How to modify/change shpping price in Magento


If you want modify or change Shipping price in Magento then we can do it using Observer So let's see how to do it:- We are going to create a Custom Module for it.
Step 1:- So let's create a config file Arunendra_Extrashipcost.xml in app/etc/modules put following code in this file:-

<?xml version="1.0"?>



    
        true
        local
    


Step 2:- create following folder and file under app/code/local
1:-Arunendra/Extrashipcost/etc/config.xml
2:-Arunendra/Extrashipcost/etc/Model/Observer.php
Step 3:-Put following code in config.xml file:-

<?xml version="1.0"?>


  

    
      0.1.0
    
  
	
		
            
            Arunendra_Extrashipcost_Model
            
		
	
 
	
		
			
				
					singleton
					extrashipcost/observer
					salesQuoteCollectTotalsBefore
				
			
		
	

 
Step 4:-Put following code in Observer.php file:-
<?php
class Arunendra_Extrashipcost_Model_Observer
{
 public function salesQuoteCollectTotalsBefore(Varien_Event_Observer $observer)
    {
         $quote = $observer->getQuote();        
	    $store    = Mage::app()->getStore($quote->getStoreId());
        $carriers = Mage::getStoreConfig('carriers', $store);     
		$newFee = 	floatval($carriers['flatrate']['price'] * 0.15);
        foreach ($carriers as $carrierCode => $carrierConfig) {
            if($carrierCode == 'flatrate'){          
			
                    Mage::log('Handling Fee(Before):' . $store->getConfig("carriers/{$carrierCode}/handling_fee"), null, 'shipping-price.log');
                    $store->setConfig("carriers/{$carrierCode}/handling_type", 'F'); #F - Fixed, P - Percentage                 
                    $store->setConfig("carriers/{$carrierCode}/handling_fee", $newFee);     
                    ###If you want to set the price instead of handling fee you can simply use as:
                    #$store->setConfig("carriers/{$carrierCode}/price", $newPrice);     
                    Mage::log('Handling Fee(After):' . $store->getConfig("carriers/{$carrierCode}/handling_fee"), null, 'shipping-price.log');
            
            }
        }
    }
}
?>

No comments:

Post a Comment