【问题标题】:Coupons doesn't work in opencart优惠券在 opencart 中不起作用
【发布时间】:2012-03-07 12:57:24
【问题描述】:

我正在对一个 opencart 项目进行更新。我们创建将应用回扣的优惠券。它包含在结帐页面中。我们正在从管理员端添加此优惠券详细信息,例如优惠券代码、折扣、到期日期等。但在用户端没有任何反应。输入优惠券代码时没有任何反应。没有降价,我们也没有收到任何错误消息。

【问题讨论】:

  • 你需要调试你的代码。你确定你能看到错误信息吗?
  • 没有收到任何错误信息
  • 报错级别、display_errors ini标志和数据库错误怎么样?
  • 这是广泛的。尝试将问题缩小到特定文件。
  • 如果我们使用了错误的优惠券代码,那么通常我们会收到一条错误消息,例如“优惠券无效、已过期或已达到使用限制!”...但这里什么也没有发生

标签: php opencart coupon


【解决方案1】:

按照约翰的回答...在catalog/model/total/coupon.php我换掉了

// If discount greater than total
if ($discount_total > $total) {
    $discount_total = $total;
}

为:

// If discount greater than total
if ($coupon_info['type'] == 'F' && $discount_total > $subtotal) {
    $discount_total = $subtotal;
}

希望没有人需要调试这个!!!

【讨论】:

    【解决方案2】:

    刚刚遇到类似的问题,优惠券申请成功但没有折扣。

    发现问题是由于订单总排序的方式,“小计”需要在“优惠券”之前。

    感觉在没有任何代码的情况下发布答案是错误的,所以这里是我进行调试的地方:catalog/model/total/coupon.php

    $total 为 0,因此折扣正在重置。

    public function getTotal(&$total_data, &$total, &$taxes) {
        if (isset($this->session->data['coupon'])) {
            $this->load->language('total/coupon');
    
            $this->load->model('checkout/coupon');
    
            $coupon_info = $this->model_checkout_coupon->getCoupon($this->session->data['coupon']);
    
            if ($coupon_info) {
                $discount_total = 0;
    
                if (!$coupon_info['product']) {
                    $sub_total = $this->cart->getSubTotal();
                } else {
                    $sub_total = 0;
    
                    foreach ($this->cart->getProducts() as $product) {
                        if (in_array($product['product_id'], $coupon_info['product'])) {
                            $sub_total += $product['total'];
                        }
                    }
                }
    
                if ($coupon_info['type'] == 'F') {
                    $coupon_info['discount'] = min($coupon_info['discount'], $sub_total);
                }
    
                foreach ($this->cart->getProducts() as $product) {
                    $discount = 0;
    
                    if (!$coupon_info['product']) {
                        $status = true;
                    } else {
                        if (in_array($product['product_id'], $coupon_info['product'])) {
                            $status = true;
                        } else {
                            $status = false;
                        }
                    }
    
                    if ($status) {
                        if ($coupon_info['type'] == 'F') {
                            $discount = $coupon_info['discount'] * ($product['total'] / $sub_total);
                        } elseif ($coupon_info['type'] == 'P') {
                            $discount = $product['total'] / 100 * $coupon_info['discount'];
                        }
    
                        if ($product['tax_class_id']) {
                            $tax_rates = $this->tax->getRates($product['total'] - ($product['total'] - $discount), $product['tax_class_id']);
    
                            foreach ($tax_rates as $tax_rate) {
                                if ($tax_rate['type'] == 'P') {
                                    $taxes[$tax_rate['tax_rate_id']] -= $tax_rate['amount'];
                                }
                            }
                        }
                    }
    
                    $discount_total += $discount;
                }
    
                if ($coupon_info['shipping'] && isset($this->session->data['shipping_method'])) {
                    if (!empty($this->session->data['shipping_method']['tax_class_id'])) {
                        $tax_rates = $this->tax->getRates($this->session->data['shipping_method']['cost'], $this->session->data['shipping_method']['tax_class_id']);
    
                        foreach ($tax_rates as $tax_rate) {
                            if ($tax_rate['type'] == 'P') {
                                $taxes[$tax_rate['tax_rate_id']] -= $tax_rate['amount'];
                            }
                        }
                    }
    
                    $discount_total += $this->session->data['shipping_method']['cost'];
                }
    
                // If discount greater than total
                if ($discount_total > $total) {
                    $discount_total = $total;
                }
    
                $total_data[] = array(
                    'code'       => 'coupon',
                    'title'      => sprintf($this->language->get('text_coupon'), $this->session->data['coupon']),
                    'value'      => -$discount_total,
                    'sort_order' => $this->config->get('coupon_sort_order')
                );
    
                $total -= $discount_total;
            }
        }
    }
    

    【讨论】:

      【解决方案3】:

      优惠券的正常工作方式确实会使它们无效。原因是日期有点尴尬。您需要将开始日期设置为要使用它的前一天,结束日期设置为后一天。我知道这很奇怪,但这就是它的工作方式,所以请确保日期对优惠券有效

      【讨论】:

        【解决方案4】:

        扩展杰的答案...

        如果是日期问题,是因为OpenCart希望优惠券大于/小于(不等于)日期

        打开/catalog/model/checkout/coupon.php

        第一个函数应该是getCoupon

        找到这一行:

        $coupon_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "coupon WHERE code = '" . $this->db->escape($code) . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) AND status = '1'");
        

        date_start 更改为 date_start

        date_end date_end

        导致:

        $coupon_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "coupon WHERE code = '" . $this->db->escape($code) . "' AND ((date_start = '0000-00-00' OR date_start <= NOW()) AND (date_end = '0000-00-00' OR date_end >= NOW())) AND status = '1'");
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-08-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-05-08
          • 2018-05-17
          • 2020-07-27
          • 2014-01-20
          相关资源
          最近更新 更多