我想在Checkout Cart页面中按下自定义按钮后动态设置每个项目的折扣(比如10美元)。我查了一下Magento的编码,发现: -
Mage_Sales_Model_Quote_Address
”类会受到影响。Mage_Sales_Model_Quote_Address
”实例 - 一个用于“结算”地址类型&另一个用于“送货”地址类型,但后者主要用于与优惠券代码相关的折扣。检查完这些区域后,我继续编写一些代码,将“送货”地址类型定位为“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
”部分获取任何内容。在结帐一页的订单审核部分。
任何人都请帮忙。我知道它可以做到。
提前感谢所有人。
答案 0 :(得分:0)
我们要求设置折扣级别。由于我们无法使用当前的折扣模型,我们对CartController中的couponPostAction进行了修改。我们设置了一个虚拟优惠券,并且能够根据有关客户的其他信息,为该优惠券提供分层折扣方案。