Joh*_*ohn 21 email templates magento magento-1.4
Magento电子邮件模板如果语句在我期望的时候没有评估为真.有人能告诉我什么是错的吗?看看下面的代码:
{{var customer.group_id}}
{{if customer.group_id}}Print true{{else}}Print false{{/if}}
{{if customer.group_id==4}}Print true{{else}}Print false{{/if}}
{{if customer.group_id=4}}Print true{{else}}Print false{{/if}}
{{if customer.group_id eq 4}}Print true{{else}}Print false{{/if}}
Run Code Online (Sandbox Code Playgroud)
输出是
4
Print True
Print False
Print False
Print False
Run Code Online (Sandbox Code Playgroud)
我尝试在4周围加上引号,但结果相同.如何使用magento电子邮件模板if语句评估平等性?
ʍǝɥ*_*ʇɐɯ 32
我通过使用'block'技术解决了这个问题.
你所做的是将订单传递给一个区块,然后在该区块内完成你的逻辑.
虽然我的解决方案针对不同的问题,但这种方法应该适用于此.
我想要的是通过支票付款选项和确认电子邮件中的一些额外文字提醒他们付款.我将其添加到新订单模板中:
{{block type='core/template' area='frontend' template='paymentstatus/orderemail.phtml' order=$order}}<br />
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个文件 app/design/frontend/default/default/template/paymentstatus/orderemail.phtml
这有'if'逻辑,在我的情况下,我想查看订单状态是否为支票,然后才提醒客户他们的订单需要清算资金.
<?php if($this->getData('order')->getStatus()=='cheque') {
echo "<p>Please note that we will require your cheque to clear before we can despatch your order.</p>"; }?>
Run Code Online (Sandbox Code Playgroud)
Jon*_*Day 16
通过代码挖掘,看起来模板逻辑是由函数Varien_Filter_Template中的(在lib\Varien而不是app\code下)实现的filter,ifDirective如果模式与正则表达式匹配,则该函数发出对函数的回调.该ifDirective反过来使用的_getVariable评估您的功能if状态._getVariable然后将条件标记Varien_Filter_Template_Tokenizer_Variable为属性或方法.
if($this->isWhiteSpace()) {
// Ignore white spaces
continue;
} else if($this->char()!='.' && $this->char()!='(') {
// Property or method name
$parameterName .= $this->char();
} else if($this->char()=='(') {
// Method declaration
$methodArgs = $this->getMethodArgs();
$actions[] = array('type'=>'method',
'name'=>$parameterName,
'args'=>$methodArgs);
$parameterName = '';
} else if($parameterName!='') {
// Property or variable declaration
if($variableSet) {
$actions[] = array('type'=>'property',
'name'=>$parameterName);
} else {
$variableSet = true;
$actions[] = array('type'=>'variable',
'name'=>$parameterName);
}
$parameterName = '';
}
Run Code Online (Sandbox Code Playgroud)
当检测到if条件是一个方法时,它将执行该方法,否则它只返回变量的字符串值.
所有这些意味着(我认为!)如果你想评估if语句中的表达式,你需要添加一个新的客户属性(有可用于此的扩展),模板可以评估.因此,如果您定义一个布尔"isMemberOfGroupNameX"属性,那么该模板应该可以工作.
我想这不是你要找的答案,但我很确定是这样的.
HTH,JD
我可以使用{{depend}}模板标记在模板中或多或少地完成此任务.
{{depend somevar}}
Print this if somevar evaluates to true
{{/depend}}
Run Code Online (Sandbox Code Playgroud)
你必须在app/code/local/Mage/Sales/Model/Order.php中使用sendNewOrderEmail()等方法来构建这个变量.
| 归档时间: |
|
| 查看次数: |
28985 次 |
| 最近记录: |