1

我遇到的问题是,当尝试从结帐时对订单应用折扣时,它将在 magento 管理订单页面的底部应用正确的总折扣,但订单项显示 0 美元折扣。

例如,假设我对所有商品都进行了 50% 的促销,有人购买了 2 件商品,Apple 售价 10 美元,Orange 售价 5 美元,购物车总额将是 15 - 50% = 7.50 美元,这已经发生了,但是当你查看这条线时项目两个折扣设置为 $0 应该是:苹果数量:1 价格 10 美元折扣 5 美元总计 5 美元橙色数量:1 价格 5 美元折扣 2.50 总计 2.50 美元;这是我的代码:

 $couponCode = (string) $this->getRequest()->getParam('coupon_code');
    if ($this->getRequest()->getParam('remove') == 1) {
        $couponCode = '';
    }
    $oldCouponCode = $this->_getQuote()->getCouponCode();

    if (!strlen($couponCode) && !strlen($oldCouponCode)) {
        $this->_goBack();
        return;
    }

    try {
        $this->_getQuote()->getShippingAddress()->setCollectShippingRates(true);
        $this->_getQuote()->setCouponCode(strlen($couponCode) ? $couponCode : '')
            ->collectTotals()
            ->save();

        if ($couponCode) {
            if ($couponCode == $this->_getQuote()->getCouponCode()) {
                $this->_getSession()->addSuccess(
                    $this->__('Coupon code "%s" was applied.', Mage::helper('core')->htmlspecialchars($couponCode))
                );
            }
            else {
                $this->_getSession()->addError(
                    $this->__('Coupon code "%s" is not valid.', Mage::helper('core')->htmlspecialchars($couponCode))
                );
            }
        } else {
            $this->_getSession()->addSuccess($this->__('Coupon code was canceled.'));
        }


    echo $this->_getReviewHtml();
    exit;
4

1 回答 1

0

Is the cart promotional rule set to discount on a per item discount or for the whole order?

The code itself looks ok.

You may also wish to add for the checkout session.

Mage::getSingleton("checkout/session")->setData("coupon_code",strlen($couponCode));
于 2013-08-01T18:08:33.690 回答