Using an alternative price field in OpenCart

I have an OpenCart installation in which there are two stores, one wholesale and one retail. The product catalog is general, but the problem is that OpenCart does not 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 prices.

I have everything that is largely described on the admin side, so my new field is displayed in the product section and updated in the database.

Now the problem is that the price changes on the front side for the retail store. Needless to say, the price of the product is used in tons of different scenarios. Therefore, I decided that the best / easiest way would be to change the price field when querying the database and initially setting the price. This is a kind of place where I got lost ... I changed it in some places that I thought were right, but the price does not change on the front side. Sometimes OpenCart can be a mysterious fig.

Can someone give me a hint about where the best place to change the price would be?

0
source share
1 answer

I assume that you have already created a different type of client for wholesale and retail clients in the administration area.

In this case, it is very simple to add this functionality to the model.

Open

catalog/model/catalog/products.php

On or around line 22, you will 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 say that it is 1, and wholesale customers - 2.

The $customer_group_id variable used below is pre-set when the getProduct() method is getProduct() .

Replace the previous line as follows:

 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 not logged in, he will see the retail price, if they log in as a wholesale customer, they will see the wholesale price.

0
source

Source: https://habr.com/ru/post/1496980/


All Articles