3

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.

3 Answers 3

6

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.

1
  • :) nice trick. We can change anything related to carrier by the way. +1
    – mageUz
    Commented Jun 6, 2013 at 10:55
0

I guess I found a sort of solution by myself.

It would be making a custom module, overriding Mage_Sales_Model_Quote_Address and adding a new method getShippingDescription() there. This will make magic getShippingDescription() not so magic and the custom logic can be placed there based on $this->getCountry() or any other conditions.

0

Also try this one: In config.xml rewrite Mage_Shipping_Model_Rate_Result_Method class:

<global>
  <models>
    <shipping>
      <rewrite>
        <rate_result_method>{{Some}}_{{Module}}_Model_Rate_Result_Method</rate_result_method>
      </rewrite>
    </shipping>
  </models>
</global>

Create Method.php file in local/{{Some}}/{{Module}}/Model/Rate/Result and its methods will be:

class {{Some}}_{{Module}}_Model_Rate_Result_Method extends Mage_Shipping_Model_Rate_Result_Method
{
    public function getMethodTitle(){
         //your logic here
    }
    public function getMethodDescription(){
         //your logic here
    }
}

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.