Reputation: 41
I have an OpenCart installation that is running two stores, one wholesale and one retail. The product catalog is shared, but the problem is that OpenCart doesn't natively support multiple pricing options. So I added a new field to the oc_product table, retail_price. The idea is that I would use the price field for wholesale pricing and the retail_price field for -- you guessed it -- retail pricing.
I have everything pretty much covered on the admin side, so my new field is showing in the product section and is being updated in the database.
Now the issue is getting the price to change on the front end for the retail store. Needless to say, product price is used in a ton of different scripts. So I figured the best/sneakiest method would be to change the price field when the database is queried and the price data is initially set. This is kind of where I got lost... I changed it in some places I thought were right but the price doesn't change on the front end. Sometimes OpenCart can be a mysterious fig.
Can anyone give me a clue as to where the best place(s) to change the price would be?
Upvotes: 0
Views: 2108
Reputation: 3277
I assume that you've already created a different customer type for both wholesale and retail customers in the admin area.
That being the case, it's very simple to add this functionality to the model.
Open:
catalog/model/catalog/products.php
On or around line 22 you should see a line that looks like this:
$query->row['price'] = ($query->row['discount'] ?
$query->row['discount'] : $query->row['price']);
Determine the numerical value of your retail customer, let's assume it's 1 and wholesale customers is 2.
The variable $customer_group_id
used below is previously set at the open of the getProduct()
method.
Replace the previous line with the following:
if ($customer_group_id == 2):
$query->row['price'] = ($query->row['discount'] ?
$query->row['discount'] : $query->row['price']);
else:
$query->row['price'] = ($query->row['discount'] ?
$query->row['discount'] : $query->row['retail_price']);
endif;
Now if your customer is logged in and is not a wholesale customer, or is not logged in, they will see the retail price, if they are logged in as a wholesale customer they will see the wholesale price.
Upvotes: 1