0

Standard shipment emails are:

app/locale/en_US/email/sales/shipment_new.phtml app/locale/en_US/email/sales/shipment_new_guest.phtml

In case an order has been made using a specific shipping method, I would like to set a custom shipment email template.

Can you help me to solve this?

0

You have to override Mage_Sales_Model_Order and rewrite queueNewOrderEmail method. So in your module's config.xml:

...
<global>
    ...
    <models>
        <sales>
            <rewrite>
                <order>Your_Module_Model_Order</order>
            </rewrite>
        </sales>
    </models>
    ...
</global>

Then in app/code/[pool]/Your/Module/Model/Order.php

class Your_Module_Model_Order extends Mage_Sales_Model_Order
{
    /**
     * Queue email with new order data
     *
     * @param bool $forceMode if true then email will be sent regardless of the fact that it was already sent previously
     *
     * @return Mage_Sales_Model_Order
     * @throws Exception
     */
    public function queueNewOrderEmail($forceMode = false)
    {
        ...
        // Retrieve corresponding email template id and customer name
        if ($this->getCustomerIsGuest()) {
            $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
            $customerName = $this->getBillingAddress()->getName();
        } else {
            $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
            $customerName = $this->getCustomerName();
        }

        // Add your logic here. You should update $templateId
        $shippingMethod = $this->getShippingMethod(true);
        if ($shippingMethod->getCarrierCode() == 'something')
        {
            $templateId = 'id';
        }
        ...
    }
}

Personally, I don't like this approach. Overriding the whole order model just to change an email template is not something you usually want to do. But it should get you on the right track.

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.