在Ajax中调用collectTotals()后,Magento计算了两次

时间:2012-11-15 15:58:05

标签: php magento

我正在尝试在Magento结账时使用折扣后的运费金额

我正在使用UPS免费送货,所以如果您在折扣后的总价低于免运费的最低金额,它将不会授予您免费送货。

Magento计算折扣前的免费送货,所以我在我的本地ups.php文件中计算了折扣后的正确金额并将其应用于代码:

$coupon_code=Mage::getSingleton('checkout/cart')->getQuote()->getCouponCode();
         Mage::getSingleton("checkout/session")->setData("coupon_code",$coupon_code);
         Mage::getSingleton('checkout/session')->getQuote()->setCouponCode($coupon_code)->setTotalsCollectedFlag(false)->collectTotals();
         //Mage::getSingleton('checkout/cart')->getQuote()->setCouponCode($coupon_code)->collectTotals()->save();
         $totals =Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object
         $subtotal = $totals["subtotal"]->getValue(); //Subtotal value

        if(isset($totals['discount']) && $totals['discount']->getValue()) {
            $discount = $totals['discount']->getValue(); //Discount value if applied
        } else {
            $discount = '';
        }       
    $r->setValue($request->getPackageValueWithDiscount( ) - $giftCardPrice);
    if($discount!='')  $r->setValueWithDiscount($subtotal-abs($discount));  
    else $r->setValueWithDiscount($request->getPackageValueWithDiscount( )- $giftCardPrice);

这就解决了我的问题,因为在每次运输Ajax时,Magento会计算两次购物车的大笔费用

我该怎么办?

0 个答案:

没有答案