【发布时间】:2016-11-02 20:59:45
【问题描述】:
是否可以通过 OpenCart 中选择的货币来限制优惠券代码?
例如 店里有两种货币XX和YY。如果买家选择 XX 货币,优惠券代码字段在购物车中可见。在其他情况下(选择货币 YY)不是。
OpenCart 2.0.3.1
【问题讨论】:
-
到目前为止,您做了哪些无效的操作?
是否可以通过 OpenCart 中选择的货币来限制优惠券代码?
例如 店里有两种货币XX和YY。如果买家选择 XX 货币,优惠券代码字段在购物车中可见。在其他情况下(选择货币 YY)不是。
OpenCart 2.0.3.1
【问题讨论】:
是的,打开这个文件:
catalog/controller/checkout/coupon.php 在 2.0.3.1 版本中
找到:
if (empty($this->request->post['coupon'])) {
$json['error'] = $this->language->get('error_empty');
unset($this->session->data['coupon']);
} elseif ($coupon_info) {
$this->session->data['coupon'] = $this->request->post['coupon'];
$this->session->data['success'] = $this->language->get('text_success');
$json['redirect'] = $this->url->link('checkout/cart');
} else {
$json['error'] = $this->language->get('error_coupon');
}
改成:
if (empty($this->request->post['coupon'])) {
$json['error'] = $this->language->get('error_empty');
unset($this->session->data['coupon']);
} elseif ($coupon_info) {
// here I use USD for example
if($this->session->data['currency'] == 'USD'){
$this->session->data['coupon'] = $this->request->post['coupon'];
$this->session->data['success'] = $this->language->get('text_success');
$json['redirect'] = $this->url->link('checkout/cart');
} else {
// Write your custom error message here
$json['error'] = 'This coupon is only available in USD';
unset($this->session->data['coupon']);
}
} else {
$json['error'] = $this->language->get('error_coupon');
}
【讨论】: