在OpenCart中使用备用价格字段 [英] Using an alternate price field in OpenCart

查看:109
本文介绍了在OpenCart中使用备用价格字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个安装了OpenCart的商店,它在两个商店,一个批发商店和一个零售商店运行.产品目录是共享的,但是问题在于OpenCart本身不支持多种定价选项.因此,我在oc_product表中添加了一个新字段retail_price.我的想法是,我将价格字段用于批发定价,将Retail_price字段用于-您猜到了-零售定价.

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.

现在,问题在于零售商店的前端价格会发生变化.不用说,产品价格用在许多不同的脚本中.因此,我认为最好/最明智的方法是在查询数据库并初始设置价格数据时更改价格字段.这是我迷路的地方...我在一些我认为正确的地方进行了更改,但前端的价格却没有变化.有时OpenCart可能是一个神秘的无花果.

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?

推荐答案

我假设您已经在管理区域中为批发和零售客户创建了不同的客户类型.

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.

打开:

catalog/model/catalog/products.php

在第22行或其周围,您应该会看到类似以下的行:

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']);

确定您的零售客户的数值,假设它是1,批发客户是2.

Determine the numerical value of your retail customer, let's assume it's 1 and wholesale customers is 2.

下面使用的变量$customer_group_id先前是在getProduct()方法的开头设置的.

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.

这篇关于在OpenCart中使用备用价格字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆