How to set custom grand total before checkout process in magento?

无人久伴 提交于 2019-11-27 03:37:52

问题


I have added an observer on "sales_order_place_before" Event and want to customize grand total before processing the payment. but i have tried a lot to change the quote price but it is not working.

Does anyone have any idea??


回答1:


You need to add new collector after grand total one (Mage_Sales_Model_Quote_Address_Total_Grand). It has to modify sum that was set by grand total collector.

I spoke about such a case at MageConf conference in Ukraine week ago. Video and slides are not available yet, but you can download demo-module that was described at conference. There is an example of total collector that calculates wrapping price.

You can modify my demo total collector so it'll be inserted in collecting process AFTER Grand total collector (see config.xml in module etc directory - remove <before>subtotal</before> node then use <after>grand_total</after> instead) and modify collect() method just to set grand totals to your predefined values:

$address->setGrandTotal($someValue);
$address->setBaseGrandTotal($someBaseValue);

Or you can leave this module as it is, but set negative totals in it. So Grand total collector will subtract them and lower grand total value as you wish. Also in such a case customer will be able to see your negative values (give them in fetch() method) and understand why grand totals were lowered.

Have fun :)




回答2:


you can't you have to make a new total object or add sums as virtual products

please observe

Mage_Sales_Model_Quote_Address_Total_Abstract Mage_Sales_Model_Order_Invoice_Total_Abstract Mage_Sales_Model_Order_Creditmemo_Total_Abstract

to see what is needed to implement a total object . You also might need to extend the rate objects



来源:https://stackoverflow.com/questions/4363876/how-to-set-custom-grand-total-before-checkout-process-in-magento

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