Magento – Transactional Email: How to customize shipping address variable/html {{var order.getShippingDescription()}}

emailtemplatetransactional

How to customize this function order.getShippingDescription(), where is this function is written in Magento.

Can someone please help in it

Best Answer

When calling {{var order.getShippingDescription()}} magento will actually call $order->getShippingDescription() where $order is the current order object...the one you are sending the e-mail for.

But that method does not exist. It is called through the magic of __call. it basically returns the shipping_description field from the sales_flat_order table.

If you want to customize it, you can rewrite the Mage_Sales_Model_Order and implement the method getShippingDescription where you process the data from $this->getData('shipping_description').

But I advice against it, because that method is used in many places. You might change something you don't want changed.
Instead you care rewrite the class mentioned above and create your own method getEmailShippingDescription where you put your code, and change the e-mail template to include {{var order.getEmailShippingDescription()}}.

An other approach would be to create your own short code. Something like this:

{{shippingDescription order=$order}}

Here is an explanation on how to do that.
and in your short code directive do this:

public function shippingDescriptionDirective() {
    $params = $this->_getIncludeParameters($construction[2]);
    if (!isset($params['order'])) {
        return '';
    }
    $description = $params['order']->getShippingDescription();
    $processed = your code here to process the description
    return $processed;
}

(Learned this custom short code approach from Vinai Kopp's book Grokking Magento - ha Vinai, you said I will learn nothing new from your book).