I have developed A custom module using event observer method, In that I am updating Handling fee(15%) for the customers that reside outside USA. I can see that this code is updating the carrier's shipping fee correctly but that change is not reflected in the grand total. i.e the shipping fee cost added to the grand total is set according to the one set in admin panel(8%).
I want to update this grand total using the updated shipping and handling fee. How can i achieve that?
config.xml
<?xml version="1.0" ?>
<config>
<modules>
<Dynamo_HandleFee>
<version>0.1.0</version> <!-- Version number of your module -->
</Dynamo_HandleFee>
</modules>
<frontend>
<routers>
<HandleFee>
<use>standard</use>
<args>
<module>Dynamo_HandleFee</module>
<frontName>HandleFee</frontName>
</args>
</HandleFee>
</routers>
</frontend>
<global>
<models>
<Dynamo_HandleFee>
<class>Dynamo_HandleFee_Model</class>
</Dynamo_HandleFee>
</models>
<events>
<sales_quote_save_before>
<observers>
<HandleFee>
<type>singleton</type>
<class>Dynamo_HandleFee/observer</class>
<method>customerAddressSaveAfter</method>
</HandleFee>
</observers>
</sales_quote_save_before>
</events>
</global>
Observer.php
class Dynamo_HandleFee_Model_Observer
{
public function customerAddressSaveAfter(Varien_Event_Observer $observer)
{
/**@var Mage_Sales_Model_Quote $quote */
$quote = $observer->getQuote();
$countryId = $quote->getShippingAddress()->getCountryId();
$someConditions = true; //this can be any condition based on your requirements
$newHandlingFee = 15;
$store = Mage::app()->getStore($quote->getStoreId());
$carriers = Mage::getStoreConfig('carriers', $store);
foreach ($carriers as $carrierCode => $carrierConfig) {
if($carrierCode == 'pickup'){
if($countryId != 'US' ){
$carrierConfig['handling_fee'] = 15;
$store->setConfig("carriers/{$carrierCode}/handling_fee", $newHandlingFee);
}
}
}
//echo true;exit;
//echo Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal();
//}
}
}