I am trying to modify my email template to generate different product information based on customer group. As in, if a customer belongs to Group A, load modified.phtml, else load default.phtml.

Specifically, I am working with the New Order email template where the base transactional email template calls {{layout handle="sales_email_order_items" order=$order}}, which loads the template file in /app/design/frontend/rwd/default/template/email/order/items.phtml.

This template eventually calls echo $this->getItemHtml($_item).

From what I can tell, this loads the template file /app/design/frontend/rwd/default/template/email/order/items/order/default.phtml, which outputs the template information to print each item's content (SKU, Name, Price, etc) in the table.

This is what I'm trying to accomplish:

$customerGroupId    = $this->getCustomerGroupId();
$customerGroupName  = Mage::getModel('customer/group')->load($customerGroupId)->getCustomerGroupCode();
if($customerGroupName = 'A') {
    // How to getItemHtml from different template?
} else {
    echo $this->getItemHtml($_item)

I assume that I will need to add reference to my modified.phtml in the /app/design/frontend/rwd/default/layout/sales.xml file like so:

    <block type="sales/order_email_items" name="items" template="email/order/items.phtml">
        <action method="addItemRender"><type>default</type><block>sales/order_email_items_order_default</block><template>email/order/items/order/default.phtml</template></action>
        // modified.phtml reference here?

Can I make getItemHtml specify a different template?

Or is there a different way I need to be approaching this?

I could replace the {{layout handle...}} with a {{block...}} call and put all of the template information within my if... else... blocks, but this seems very hacky. Any thoughts or suggestions?

  • I think you should have two different blocks with two templates in your page which you will add with xml reference file and then you will just call the appropriate block
    – Nickool
    Commented Jul 10, 2015 at 21:50

1 Answer 1


To change the itemHtml depends upon the customer group. You can achieve that in layout file using a helper method.

     <block type="sales/order_email_items" name="items" template="email/order/items.phtml">
         <action method="addItemRender"><type>default</type><block>sales/order_email_items_order_default</block><template helper="mymodule/data/myFunction"/></action>

Then create myFunction in your helper file


Use the below code

Update :

public function myFunction()
    $customerGroupName = '';
    if($customerGroupId = Mage::getSingleton('adminhtml/sales_order_create')->getQuote()->getCustomerGroupId()):
        $customerGroupName = Mage::getModel('customer/group')->load($customerGroupId)->getCustomerGroupCode();
        $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
        $customerGroupName = Mage::getModel('customer/group')->load($customerGroupId)->getCustomerGroupCode();
    if($customerGroupName == 'General') { 
       return 'email/order/items/order/default.phtml'; 
    } else { 
      return 'email/order/items/order/another.phtml';

That's it.

  • I got a Fatal error: Call to undefined method MyNamespace_MyModule_Helper_Data::getCustomerGroupId() in .../Helper/Data.php on line 5. Is it trying to find the method in my helper?
    – travisw
    Commented Jul 13, 2015 at 17:18
  • Create an custom module and load that function through that Commented Jul 13, 2015 at 17:34
  • I've created a custom Module named Emailbygroup. It appears to call the Helper correctly when an email is sent, but my helper acts like it is looking for a method getCustomerGroupId within my Emailbygroup/Helper/Data.php file.
    – travisw
    Commented Jul 13, 2015 at 17:37
  • Get customer group id from order Commented Jul 13, 2015 at 17:42
  • @travisw check by updated code. Commented Jul 14, 2015 at 4:38

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.