2

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

Can someone please help in it

11

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).

2

getShippingDescription() is a getter method that returns a string previously set. After a small research, it looks like the string is set in app/code/core/Mage/Sales/Model/Quote/Address/Total/Shipping.php at lines 168-169:

$shippingDescription = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle()
$address->setShippingDescription(trim($shippingDescription, ' -'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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