我想在“结帐购物车”页面中按下自定义按钮后动态设置每个项目的折扣(比如 10 美元)。我检查了 Magento 的一些编码,发现:
- 主要是 "
Mage_Sales_Model_Quote_Address
" 类总是受到影响,当任何人(任何 Magento 代码)都在谈论折扣时。 - " " 有 2 个实例
Mage_Sales_Model_Quote_Address
- 一个用于“ billing ”地址类型,另一个用于“ shipping ”地址类型,但后一个主要用于优惠券代码相关的折扣。
在检查了这些区域之后,我继续编写了一些代码,针对“”的“运输”地址类型Mage_Sales_Model_Quote_Address
,如:-
$cart = Mage::getSingleton('checkout/cart');
$objShippingAddress = $cart->getQuote()->getShippingAddress();
$discountAmount = 10;
$objShippingAddress->setDiscountDescription('any description');
$objShippingAddress->addTotal(array(
'code' => 'discount',
'title' => "Custom Discount",
'value' => -$discountAmount,
));
$totalDiscountAmount = $discountAmount;
$subtotalWithDiscount = $discountAmount;
$baseTotalDiscountAmount = $discountAmount;
$baseSubtotalWithDiscount = $discountAmount;
$objShippingAddress->setDiscountAmount($totalDiscountAmount);
$objShippingAddress->setSubtotalWithDiscount($subtotalWithDiscount);
$objShippingAddress->setBaseDiscountAmount($baseTotalDiscountAmount);
$objShippingAddress->setBaseSubtotalWithDiscount($baseSubtotalWithDiscount);
$objShippingAddress->setGrandTotal($objShippingAddress->getGrandTotal() - $objShippingAddress->getDiscountAmount());
$objShippingAddress->setBaseGrandTotal($objShippingAddress->getBaseGrandTotal() - $objShippingAddress->getBaseDiscountAmount());
但我仍然没有在totals
我的结帐购物车页面的“”部分和单页结帐的订单审查部分中看到任何行。