限制优惠券代码在 OpenCart 中购买所选货币

Restrict coupon code buy chosen currency in OpenCart

是否可以在 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');
    }