magento - 如何在 magento 的交易电子邮件模板中使用自定义客户变量?

标签 magento

我已向客户添加了一些自定义变量,我想在电子邮件模板中使用它们。

以下是我如何在安装程序中向客户添加变量的示例:

$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/

相关文章:

css - 样式表在呈现后被 Google 阻止

Magento:如何覆盖 Review/Model/Resource/Collection.php

mysql - Magento全文搜索错误

php - Magento translate.csv 文件未加载

magento - 如何在magento中将产品名称属性设置为唯一

Magento 2 : Replace labels in invoice pdf

css - 我在Magento面板中合并时的CSS和JS路径不正确

php - Magento 阻止 Paypal 重写

magento - 以编程方式从布局中删除 block

php - Magento 客户登录页面在登录后立即再次加载,并且未创建 Frontedn cookie