2

I am using simple if condition in email template.

{{depend order.delivery_time=="1"}}

Delivery Time: 10am To 2pm

{{/depend}} {{depend order.delivery_time=="2"}}

Delivery Time: 2pm To 7pm

{{/depend}} {{depend order.delivery_time=="3"}}

Delivery Time: 7pm To 10pm

{{/depend}}

But every time it is printing 1st value i.e. Delivery Time: 10am To 2pm
Can anyone tell me, how to check == in email template?

8

You cannot use logical expressions in depend (unfortunately neither in if as one comment suggested)

  • {{depend X}}...{{/depend}} output content in between only if variable X is true-ish (note that you cannot use logical expressions here, just variables or methods on variables.

From this answer, which covers more details of template directives: https://magento.stackexchange.com/a/121510/243

So the only way I see to achieve what you are trying is to add three variables. For example:

in PHP code (probably best in an load_after observer):

$order->setData('delivery_time_1', $order->getDeliveryTime() == '1');
$order->setData('delivery_time_2', $order->getDeliveryTime() == '2');
$order->setData('delivery_time_3', $order->getDeliveryTime() == '3');

then in the email template:

{{depend order.delivery_time_1}}

Delivery Time: 10am To 2pm

{{/depend}}
{{depend order.delivery_time_2}}

Delivery Time: 2pm To 7pm

{{/depend}}
{{depend order.delivery_time_3}}

Delivery Time: 7pm To 10pm

{{/depend}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.