1

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

4

4 回答 4

6

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

于 2012-02-16T11:54:34.510 回答
3

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

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

在没有任何代码的情况下发布答案感觉不对,所以这是我进行调试的地方: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;
        }
    }
}
于 2015-07-23T17:04:33.230 回答
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;
}

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

于 2017-11-14T17:31:31.627 回答
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 < NOW()更改 为date_start <= NOW()

并且date_end < NOW()date_end <= 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'");
于 2012-02-18T01:33:38.543 回答