Tuesday, January 5, 2010

Show customer group in order e-mail (for redbeetstudio)

Problem: Show customer group in order e-mail.
http://www.magentocommerce.com/boards/viewthread/71736/

Possible solution
In order for this to work in the e-mail template:
{{var order.getCustomerGroupName()}}
you have to create a method in the Order model (overwrite it or edit the core at your own risk).
function getCustomerGroupName(){
$group = Mage::getModel('customer/customer_group')->load($this->getCustomerGroupId());
if ($group->getId()){
return $group->getName();
}
return '';//or any default value if the customer is not in a group or is a guest
}

2 comments:

  1. Does this work in 1.5.1.0 Community? Also, where in the order module (which line) does the code above need inserted into? Thx!

    ReplyDelete
  2. Hello Mark
    The code above should be in the order model (Mage_Sales_Model_Order.php), but you shouldn't add it directly in this file. You should properly override the model and add your function. To override the model check this:

    http://magedev.com/2009/06/03/magento-overriding-model-block-or-helper/

    I actually don't know for sure if it works on 1.5.1.0 CE but I don't see any reason why it shouldn't.

    ReplyDelete