优惠券在opencart中不起作用

时间:2012-02-16 05:24:47

标签: php opencart coupon

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

4 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:3)

在优惠券成功申请但没有折扣的情况下遇到了类似的问题。

发现问题是由于订单总订单的方式,' sub total'需要在优惠券之前出现。

感觉错误发布没有任何代码的答案,所以这里是我进行调试的地方: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;
        }
    }
}

答案 2 :(得分: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;
}

希望没有人能够调试这个!!!

答案 3 :(得分:0)

扩展周杰伦的答案......

如果是日期问题,那是因为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&lt;现在() date_start&lt; = NOW()

date_end&lt;现在() date_end&lt; = NOW()

导致:

$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'");