0

I would like to send different transactional email based on ordered product category. What is the best solution to achieve this?

The goal is to send emails: - based on category if ordered products are from single category - send default one for products from multiple categories

Since content will be very similar, maybe its better to add layout handle?

  • FYI: categories are not associated with order items. They can be inferred from the order item - product link, but if the product belongs to multiple categories, you will need to handle this process more robustly. – benmarks Jul 4 '13 at 11:54
  • thanks, luckily in my case products belong to one category only – arekstasiewicz Jul 4 '13 at 12:32
2

You can make use of the control-flow if keyword in email templates to handle outputting blocks for you:

{{if order.getCategoryIsShoes()}}
    <p><!-- your content here --></p>
{{else}}
    <p><!-- your default content here --></p>
{{/if}}

Of course you'll have to rewrite Mage_Sales_Model_Order with your own module to create that method:

<?php

class YourCompany_YourModule_Model_Order extends Mage_Sales_Model_Order
{
    public function getCategoryIsShoes()
    {
        //set your shoes category id
        $shoesCategoryId = 9;

        //get order from registry
        $order = Mage::registry('current_order');

        foreach($order->getAllItems() as $_item){
            if(in_array($shoesCategoryId, $_item->getCategoryIds()){
                return true;
            }
        }

        return false;
    }
}

The above is an example only - there is probably a much more elegant way to handle this, for instance, extending the category itself to include a tab with transactional email text; or better-yet, a module that allows you to assign that text on a per-category basis. This is just to get the juices flowing.

Some more reading about the email template syntax for control flow statements like depend and if/else:

http://www.magentocommerce.com/wiki/modules_reference/english/mage_adminhtml/system_email_template/index

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.