Magento 1.9 - How to add if-else condition on Sales order email template HTML file?
-
12-04-2021 - |
Вопрос
Following is my sales order email template sample,
Docroot = app\locale\en_US\template\email\sales\order_new.html
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="email-heading">
<h1>Thank you for your order from {{var store.getFrontendName()}}.</h1>
<p>Once your package ships we will send an email with a link to track your order. Your order summary is below. Thank you again for your business.</p>
</td>
<td class="store-info">
<h4>Order Questions?</h4>
<p>
{{depend store_phone}}
<b>Call Us:</b>
<a href="tel:{{var phone}}">{{var store_phone}}</a><br>
{{/depend}}
{{depend store_hours}}
<span class="no-link">{{var store_hours}}</span><br>
{{/depend}}
{{depend store_email}}
<b>Email:</b> <a href="mailto:{{var store_email}}">{{var store_email}}</a>
{{/depend}}
</p>
</td>
</tr>
</table>
I just want to alter my thank you message based on the website in my multistore website.
If website id == 1 my message should be
<h1>Thank you for your order from {{var store.getFrontendName()}}.</h1>
else
<h1>Welcome our land your order from {{var store.getFrontendName()}}.</h1>
Решение
You can not use direct if
condition like this
{{if order.websiteid == 1}}
<p>Your text goes here</p>
{{/if}}
But you can define the function or flag in your order model like this.
with function
public function shouldShowBlock() {
/* your code to check website condition and return true or false */
}
and in email template
{{if order.shouldShowBlock()}}
<p>Your text goes here</p>
{{/if}}
Just copy app/code/Mage/Sales/Model/Order.php to app/code/local/Mage/Sales/Model/Order.php then write you function to end of that file
Не связан с magento.stackexchange