2

I have added some custom variables to customer and I want to use them in email template.

Here's example how I have added a variable to customer in my installer:

$setup->addAttribute('customer', 'companyname', array(
    'input'         => 'text',
    'type'          => 'varchar',
    'label'         => 'Company name',
    'visible'       => 1,
    'required'      => 1,
    'user_defined' => 1,
));

$setup->addAttributeToGroup(
 $entityTypeId,
 $attributeSetId,
 $attributeGroupId,
 'companyname',
 '999'  //sort_order
);

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'companyname');
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create'));
$oAttribute->save();

I try to use this variable in email template:

{{var order.getCustomer().getCompanyname()}}

But it's not showing. How to make it work?

4

1 回答 1

3

我用如下代码完成了类似的任务:

$setup->addAttribute('customer', 'attr_name', array(
    'type'      => 'int',
    'input'     => 'select',
    'label'     => 'Attr label',
    'global'    => 1,
    'visible'   => 1,
    'required'  => 1,
    'default'   => '0',
    'user_defined'      => 1,
    'visible_on_front'  => 1,
));
if (version_compare(Mage::getVersion(), '1.6.0', '<='))
{
      $customer = Mage::getModel('customer/customer');
      $attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
      $setup->addAttributeToSet('customer', $attrSetId, 'General', 'attr_name');
}
if (version_compare(Mage::getVersion(), '1.4.2', '>='))
{
    Mage::getSingleton('eav/config')
        ->getAttribute('customer', 'attr_name')
        ->setData('used_in_forms', array('customer_account_create'))
        ->save();
}

接下来在“订购新”电子邮件中(现在)对其进行了测试,{{var order.getCustomer().getAttrName()}}并获得了正确的值。
试试看,可能对你有帮助。

于 2012-07-25T09:22:34.597 回答