Magento: Rewrite Shipping Method

There is a way to rewrite carrier classes of shipping methods but it is not obvious and required me to browse the shipping module source:

If you look at Mage_Shipping_Model_Config, you will discover that the code used as parameter for Mage::getModel() is taken from the store configuration. This code is NOT the standard code like 'shipping/carrier_tablerate', so it does not help overriding as usual.

Now you have to find out first what this code is. For example I wanted to override the matrixrate carrier, so I tested it like that:

$carrierConfig = Mage::getStoreConfig('carriers/matrixrate')
var_dump($carrierConfig['model']);

Yes, you can put this code anywhere on the page temporary but it is useful to have a separate file for such things that can be run from the command line (starting with Mage::app() to initialize Magento)

In my case the code was matrixrate_shipping/carrier_matrixrate so I had to change my config.xml like that:

<global>
    <models>
        <matrixrate_shipping>
            <rewrite>
                <carrier_matrixrate>my_class_name</carrier_matrixrate>
            </rewrite>
        </matrixrate_shipping>
    </models>

instead of

<global>
    <models>
        <matrixrate>
            <rewrite>
                <carrier_matrixrate>my_class_name</carrier_matrixrate>
            </rewrite>
        </matrixrate>
    </models>

Question and answer on StackOverflow

One Reply to “Magento: Rewrite Shipping Method”

Comments are closed.