Magento – Different titles for a table rate shipping module

shippingtable-rates

Is there a pretty way to override table rates shipping method title for order confirmation email and order details page (customer account) based on shipping address country?

So far I see cloning an entire shipping method wich allowed countries restriction and using WebShopApps MatrixRate extension as alternatives but I'm not happy with those options.

Best Answer

You can do the same without a rewrite using an observer:

<sales_quote_collect_totals_before>
    <observers>
        <your_module>
            <type>singleton</type>
            <class>your_module/observer</class>
            <method>salesQuoteCollectTotalsBefore</method>
        </your_module>
    </observers>
</sales_quote_collect_totals_before>

Then, in the observer:

public function salesQuoteCollectTotalsBefore(Varien_Event_Observer $observer)
{
    /** @var Mage_Sales_Model_Quote $quote */
    $quote = $observer->getQuote();

    $store = Mage::app()->getStore($quote->getStoreId());
    $store->setConfig('carriers/tablerate/name', 'Name By Country');
    $store->setConfig('carriers/tablerate/title', 'Method Title By Country');
}

Setting the config values dynamically without saving them is a cheap trick but it works pretty well.
The benefit of using an observer over a class rewrite is that it's less conflict prone.

Related Topic