我已向客户添加了一些自定义变量,我想在电子邮件模板中使用它们。
以下是我如何在安装程序中向客户添加变量的示例:
$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();
我尝试在电子邮件模板中使用此变量:
{{var order.getCustomer().getCompanyname()}}
但它没有显示。如何让它发挥作用?
最佳答案
我使用如下代码完成了类似的任务:
$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()}}
中对其进行了测试(立即),并获得了正确的值。
尝试一下,也许对你有帮助。
关于magento - 如何在 magento 的交易电子邮件模板中使用自定义客户变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11645127/