添加自定义计算到购物车总在Magento的总计 [英] Add custom calculation to cart total and grand total in magento

查看:106
本文介绍了添加自定义计算到购物车总在Magento的总计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在要向购物车总额和总计加/减费用的站点上工作.我正在触发此事件以捕获购物车详细信息.sales_order_save_after.而在观察者中,我使用此代码获得了价格

I am working on site where i want to add/subtract fee to cart total and grand total.I am firing this event to capture the cart details.sales_order_save_after. while in observer i got the price using this code

public function modifyPrice(Varien_Event_Observer $obs)
        {


       $getotal = Mage::helper('checkout')->getQuote()->getGrandTotal();
       $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); 
       $subtotal = $totals["subtotal"]->getValue();
}.

但是我不知道如何从总数中减去/减去金额,而不是相应地进行更新.谢谢

But i don't know how to add/subtract amount from total and than update accordingly.Thanks in advance

推荐答案

搜索后,我发现本教程 http://magento.ikantam.com/qa/how-add-discount-total-magento .在折扣模型类上,我可以向购物车总计添加/减去自定义价格,例如:

After searching i found this tutorial http://magento.ikantam.com/qa/how-add-discount-total-magento.And on Discount model class i can add/subtract custom price to cart total like :

 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;
    }

这篇关于添加自定义计算到购物车总在Magento的总计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆