I'm trying to add a conditional check to my New Order email template by using a helper to determine which Group a customer belongs to. My helper is loading fine, but it seems like the helper doesn't have access to any data (Customer or Order info).


    <block type="sales/order_email_invoice_items" name="items" template="email/order/invoice/items.phtml">
        <action method="addItemRender"><type>default</type><block>sales/order_email_items_default</block><template>email/order/items/invoice/default.phtml</template></action>


class Mbs_Emailbygroup_Helper_Data extends Mage_Core_Helper_Abstract {
    public function getEmailTemplate() {
    $customerGroupId = $this->getCustomerGroupId();
    $customerGroupName = Mage::getModel('customer/group')->load($customerGroupId)->getCustomerGroupCode();
        if($customerGroupName = 'Distributors5') {
             return 'email/order/items/order/discount.phtml'; 
        } else {
            return 'email/order/items/order/default.phtml';

The Error

Fatal error: Call to undefined method Mbs_Emailbygroup_Helper_Data::getCustomerGroupId() in /var/www/sites/mbs/app/code/local/Mbs/Emailbygroup/Helper/Data.php on line 5

I've tried calling variations replacing $this with $order or using $order = $this->getOrder() but nothing seems to be getting any data.

How can I check get the Customer Group within the transactional email template?

  • please check compiler enable or not?
    – Amit Bera
    Jul 14, 2015 at 3:20
  • Do you have <helper> node in config.xml? Jul 14, 2015 at 3:21
  • where do you make the call Mbs_Emailbygroup_Helper_Data::getEmailTemplate() Jul 14, 2015 at 3:30
  • Compiler is disabled. Helper node is present in config.xml. The only call to getEmailTemplate is the sales.xml layout file.
    – travisw
    Jul 14, 2015 at 4:55
  • @AmitBera I just noticed this but I don't know if it changes anything. Compiler Status is disabled, but Compilation State is Compiled. Could this cause problems?
    – travisw
    Jul 14, 2015 at 14:17

2 Answers 2


So your are trying to get the customerGroupId form layout file using helper in email transaction.

as per the @Rajeev K Tomy answer. You can get the customer group id from the current customer session.

   $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();

Update :

To get the customer group id on admin order creation.

$customerGroupId = Mage::getSingleton('adminhtml/sales_order_create')->getQuote()->getCustomerGroupId()
  • Wouldn't I need to load from something other than customer/session since the email can be generated from the back end too? I think it should work in front and back end with the order, no?
    – travisw
    Jul 14, 2015 at 4:58
  • @travisw Check my updated answer Jul 14, 2015 at 7:25

Here $customerGroupId = $this->getCustomerGroupId(); makes trouble because, $this stands for the class reference Mbs_Emailbygroup_Helper_Data and it does not have a method getCustomerGroupId() (nor in it's parent). So ultimately you are calling an undefined method here.

So instead of this you should call this method on a valid/loaded customer instance. ie

/** @var $customer instanceof Mage_Customer_Model_Customer **/

This can be achieved by passing a valid customer instance to your helper method getEmailTemplate() as a parameter and then use it within your function. Otherwise, you need to load a valid customer within the function itself and then use that instance to call getCustomerGroupId()


To get the order in your helper, try this.

 $order = Mage::registry('current_order');
  • Is it possible to pass in an instance of $_order (which is being worked with in a parent template file, before it calls $this->getItemHtml($_item) to output my template (discount.phtml or default.phtml) and retrieve the customer group from there? I don't know how I would go about getting the Order # or Customer # without passing the data into my helper.
    – travisw
    Jul 14, 2015 at 13:30
  • Meenakshi's answer got things working, but I feel it is slower to load everything separately (with Mage::get...) than to import the $_order information when it is already retrieved higher in the template structure. If you know how I could accomplish this, I would be greatly appreciative.
    – travisw
    Jul 14, 2015 at 16:05
  • see my edit.. it may work. Not sure. Jul 14, 2015 at 16:59

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.