Add custom calculation to cart total and grand total in magento

家住魔仙堡 提交于 2019-12-01 12:57:39

Rehman,

i am afraid this is not a straight forward task to complete, although you can take following as Ref to start

http://www.excellencemagentoblog.com/magento-add-fee-discount-order-total

Hope above link helps.

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;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!