In my attempt to fetching shipping rates, I want to override/rewrite this core file Mage_Sales_Model_Quote_Address to put my custom code. So that, I can call the original method using PHP's parent:: construct.

However, I found the Mage_Shipping_Model_Rate_Request object is created and used locally in the method Mage_Sales_Model_Quote_Address::requestShippingRates, hence I confused how to override/rewrite it.

public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null)
    /** @var $request Mage_Shipping_Model_Rate_Request */
    $request = Mage::getModel('shipping/rate_request');
    $request->setAllItems($item ? array($item) : $this->getAllItems());

    /** My custom code shall added in my override class */

1 Answer 1


In order to overwrite Mage_Sales_Model_Quote_Address, you need to add this code in your config.xml file

File : app/code/local/Namespace/Module/etc/config.xml


If you use this code inside config.xml, that means instead of Mage_Sales_Model_Quote_Address, your model class will be used by magento. If your custom model definition do not holds the requested method from default model, then magento is brave enough to use that method from original class.

Your model definition should look like this.

class Namespace_Module_Model_Quote_Address extends Mage_Sales_Model_Quote_Address {

    public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null)
       //ofcourse you can use here `Mage::getModel('shipping/rate_request')` if you need

       //no problems with that. 

       //this method will use by magento if `Mage_Sales_Model_Quote_Address::requestShippingRates` get requested

So there is no doubt. You can rewrite this class and alter how requestShippingRates() method works right now. You can invoke Mage_Shipping_Model_Rate_Request class inside this function and still use it in your custom class

  • I wish to call the original method using parent:: construct in my rewrite model. So would be something like: public function requestShippingRates(...) { // add my own code parent::requestShippingRates(); }
    – Leongelis
    Aug 12, 2014 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.