如何在magento的交易电子邮件模板中使用自定义客户变量? [英] How to use custom customer variables in transactional email templates in magento?

查看:62
本文介绍了如何在magento的交易电子邮件模板中使用自定义客户变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经向客户添加了一些自定义变量,并且希望在电子邮件模板中使用它们.

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?

推荐答案

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

I done similar task with code like below:

$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()}}中对其进行了测试,并获得了正确的值.
试试吧,可能对您有帮助.

Next have tested it (right now) within "Order new" email {{var order.getCustomer().getAttrName()}} and have got correct value.
Try it, might it helps to you.

这篇关于如何在magento的交易电子邮件模板中使用自定义客户变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆