magento - 如何添加自定义折扣

时间:2014-08-04 19:48:24

标签: php magento discount

我需要为订单添加自定义折扣。我创建了一个观察者,如下所示:

$shippingDiscountValue = 20;
$currentAddress = $quote->getShippingAddress();
$currentDiscount = (-1) * $currentAddress->getDiscountAmount();
$newDiscount = $currentDiscount + $shippingDiscountValue;
$quote->setGrandTotal($quote->getBaseSubtotal() - $shippingDiscountValue)
    ->setBaseGrandTotal($quote->getBaseSubtotal() - $shippingDiscountValue)
    ->setSubtotalWithDiscount($quote->getBaseSubtotal() - $shippingDiscountValue)
    ->setBaseSubtotalWithDiscount($quote->getBaseSubtotal() - $shippingDiscountValue)
    ->save();  

$currentAddress->setSubtotalWithDiscount((float) $currentAddress->getSubtotalWithDiscount() - $shippingDiscountValue);
$currentAddress->setGrandTotal((float) $currentAddress->getGrandTotal() - $shippingDiscountValue);
$currentAddress->setBaseSubtotalWithDiscount((float) $currentAddress->getBaseSubtotalWithDiscount() - $shippingDiscountValue);
$currentAddress->setBaseGrandTotal((float) $currentAddress->getBaseGrandTotal() - $shippingDiscountValue);        

$currentAddress->setBaseDiscountAmount($newDiscount * (-1));
$currentAddress->setDiscountAmount($newDiscount * (-1));

$currentAddress->save();
$quote->save();

我的购物车中的任何更改(添加,删除,更新数量)后我都会调用此观察者。在购物车详细信息中一切正常 - 折扣是正确计算的,但在结帐时(按顺序)有折扣基数,没有$shippingDiscountValue

0 个答案:

没有答案