【问题标题】:Magento discount is not being showing on line item but totals are correctMagento 折扣未显示在订单项上,但总数正确
【发布时间】:2023-04-15 00:08:01
【问题描述】:

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

例如,假设我对所有商品都进行了 50% 的促销活动,而有人购买了 2 件商品,Apple 售价 10 美元,Orange 售价 5 美元,购物车总额将是 15 - 50% = 7.50 美元,这已经发生了,但是当你看在行项目中,两个折扣都设置为 0 美元,应该是:apple 数量: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;

【问题讨论】:

    标签: magento discount coupon


    【解决方案1】:

    购物车促销规则是设置为单件折扣还是整个订单折扣?

    代码本身看起来没问题。

    您可能还希望为结帐会话添加。

    Mage::getSingleton("checkout/session")->setData("coupon_code",strlen($couponCode));
    

    【讨论】:

    • 嗨谢谢你的建议,它不是它自己的促销规则,因为它只针对这种特定的付款方式(自定义创建)我认为它可能与观察者有关