Skip to content

Magento : Change Shipping Price After Save Shipping Method

it took couple days to figure this ‘shit’ out

i assume you already understand how to create custom shipping method extension, for example on your carrier model file

<?php  
    class Company_Myext_Model_Carrier_Shipseller     
		extends Mage_Shipping_Model_Carrier_Abstract
		implements Mage_Shipping_Model_Carrier_Interface
	{  
        protected $_code = 'yoursihipcode';  
      
............

then we ‘play’ with “checkout_controller_onepage_save_shipping_method” even observer,

<?xml version="1.0"?>
<config>
  
..............
   <global>
     <events>	
	<checkout_controller_onepage_save_shipping_method>
	   <observers>
		<Company_Myext_Model_Observer>
		 <type>singleton</type>
		 <class>Company_Myext_Model_Observer</class>
		 <method>saveShippingMethod</method>
		</Company_Myext_Model_Observer>
	   </observers>
	</checkout_controller_onepage_save_shipping_method>
		
     </events>
.................

and then the final step is on your Observer file

<?php 
class Company_Myext_Model_Observer{
	public function saveShippingMethod($observer){
	 $quote=$observer->getQuote();
	 $data=$quote->getShippingAddress()->getAllShippingRates();
	  foreach($data as $_rate){
	   if($_rate->getCode()=='yoursihipcode_yoursihipcode'){
		 $_rate->setPrice(9999); /* this is your new price*/
		 $_rate->setCarrierTitle('new carrier name'); /* new carrier title here */
		 $_rate->setMethodTitle('new method title');/* new method title here */
		 $_rate->save();
					
		 $quote->save();
	    }
	  }
     }
}

 

Comments are closed.