Wednesday, May 29, 2013

Add extra cost to every shipping method in Magento


>>  I needed to add extra cost to every shipping method price. There would be any other better way to do it but I did the following :

         Open the Rate.php file within app/code/core/Mage/Sales/Model/Quote/Address directory. Find this method:
    public function importShippingRate(Mage_Shipping_Model_Rate_Result_Abstract $rate)
    {
        if ($rate instanceof Mage_Shipping_Model_Rate_Result_Error) {
            $this
                ->setCode($rate->getCarrier().'_error')
                ->setCarrier($rate->getCarrier())
                ->setCarrierTitle($rate->getCarrierTitle())
                ->setErrorMessage($rate->getErrorMessage())
            ;
        } elseif ($rate instanceof Mage_Shipping_Model_Rate_Result_Method) {
            $this
                ->setCode($rate->getCarrier().'_'.$rate->getMethod())
                ->setCarrier($rate->getCarrier())
                ->setCarrierTitle($rate->getCarrierTitle())
                ->setMethod($rate->getMethod())
                ->setMethodTitle($rate->getMethodTitle())
                ->setMethodDescription($rate->getMethodDescription())
                ->setPrice($rate->getPrice())
            ;
        }
        return $this;
    }

    Add extra 10 price with $rate->getPrice() like :  
                   ->setPrice($rate->getPrice()+10)


  Note: Editing the core file is not a good practice. If anyone find any other solution, please must share with me. :)