Magento Email Template If Statements

后端 未结 4 1273
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 02:52

The Magento Email Template If Statements aren\'t evaluating to true when I expect them to. Can someone tell me what\'s wrong? Take a look at the following code:

         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 03:24

    Digging through the code, it looks like the template logic is implemented by Varien_Filter_Template (under lib\Varien not app\code) in the filter function which issues a callback to the ifDirective function if the pattern matches the regex. The ifDirective in turn uses the _getVariable function to evaluate your if condition. _getVariable then tokenizes the condition in Varien_Filter_Template_Tokenizer_Variable into either a property or a method.

    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 = '';
            }
    

    When the if condition is detected to be a method, it will execute that method, otherwise it simply returns the string value of the variable.

    All of which means (I think!) that if you want to evaluate an expression inside the if statement, you need to add a new customer attribute (there are extensions available for this) that the template can evaluate. So if you define a boolean "isMemberOfGroupNameX" attribute, then the template should work.

    I imagine this is not the answer that you're looking for, but I'm fairly sure that's the case.

    HTH, JD

提交回复
热议问题