Using an alternate price field in OpenCart

会有一股神秘感。 提交于 2019-12-12 01:51:26

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/18057499/using-an-alternate-price-field-in-opencart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!