我正在网站上工作,我想在购物车总额和总额中加上/减去费用。我正在启动此活动以捕获购物车详细信息。sales_order_save_after
。在观察者中,我使用此代码获得了价格
public function modifyPrice(Varien_Event_Observer $obs)
{
$getotal = Mage::helper('checkout')->getQuote()->getGrandTotal();
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
$subtotal = $totals["subtotal"]->getValue();
}.
但我不知道如何从总数中加/减金额而不是相应地更新。谢谢提前
答案 0 :(得分:1)
拉赫曼,
我担心这不是一个完成的直接任务,尽管你可以采取以下作为参考开始
http://www.excellencemagentoblog.com/magento-add-fee-discount-order-total
希望以上链接有帮助。
答案 1 :(得分:0)
搜索后我发现了这个教程http://magento.ikantam.com/qa/how-add-discount-total-magento。在折扣模型类中,我可以添加/减去自定义价格到购物车总数,如:
public function collect(Mage_Sales_Model_Quote_Address $address) {
if ($address->getData('address_type') == 'billing')
return $this;
$discount = Mage::helper('my_module')->getCurrentdiscount(); // Custom percentage
$grandTotal = $address->getGrandTotal();
$baseGrandTotal = $address->getBaseGrandTotal();
$totals = array_sum($address->getAllTotalAmounts());
$baseTotals = array_sum($address->getAllBaseTotalAmounts());
$address->setFeeAmount(-$totals * $discount / 100);
$address->setBaseFeeAmount(-$baseTotals * $discount / 100);
$address->setGrandTotal($grandTotal + $address->getFeeAmount());
$address->setBaseGrandTotal($baseGrandTotal + $address->getBaseFeeAmount());
return $this;
}