/   /   /  OroCommerce B2B : Email Templates - variables functions and filters

Note:

For more extensions and themes visit our store

OroCommerce B2B : Email Templates - variables functions and filters


The email template system in Orocommerce came with various  techniques to make it dynamic and more readable to last email recipient .

1 – Variables:

Often the variables is related to entities , for example if you have chosen order entity related to your template you will have the id , creation date , baseTotalValue  …. and you will have access to variables  of related entities too ,  like entity billingAddress , customer …. 
So you can use directly inside you editor and the system going to render the real value based on current entity (order id or quote id) 
example :
Please see your order #{{ entity.identifier }} details below.
{{ entity.identifier }} : I wanna render here the  identifier of current order which used on this email , the result is Order #FR1012401 . 

2 – Filters:

The filters is a function but with specific usage (object to string , formating or other) , for example filter date to string or render object price to string price with currency .
Emails have independent twig renderer with the sandbox to disable all not required twig filters or functions.
Some allowed filters is:

  1.  
  2.             'oro_format_address',
  3.             'oro_format_date',
  4.             'oro_format_time',
  5.             'oro_format_datetime',
  6.             'oro_format_datetime_organization',
  7.             'oro_format_name',
  8.             'date',
  9.             'oro_format_currency',
  10.             'oro_html_sanitize'
  11.  

like default twig filter are applied to Twig variables by using the | character followed by the filter name
Example:
Order Date: {{ entity.createdAt|oro_format_date }}
{{ entity.createdAt|oro_format_date }} :  get my object date  createdAt and convert to string with specific format , the result is Order Date: Feb 6, 2019 .

3 – Functions :

Often we’re using function to get complex data to use as simple array collection or final string render, 
like Twig functions are called directly with any parameters being passed in via parenthesis.
Example:
{% set data = order_line_items(entity) %}  : the function  order_line_items take in parameter our current order entity and we have used -{% set-  to affect to result in variables data , this variable data can give us many sub data :
{% for item in data.lineItems %} :  data.lineItems return collection of all items related to current order 
{{ data.total.totalPrice|oro_format_price }} : the variable data return too the total price of order we have used filter  oro_format_price to formatting it to to specific format , our result $47,494.53

Some allowed function:

  1.  
  2.             'oro_order_shipping_method_label',
  3.             'get_payment_methods',
  4.             'get_payment_status_label',
  5.             'get_payment_status',
  6.             'line_items_discounts',
  7.             'get_payment_status',
  8.             'get_payment_status_label',            
  9.             'get_payment_term',
  10.             'get_payment_method_label',
  11.             'oro_payment_method_config_template',
  12.             'getlabel'
  13.  


this just some lines for general usage …...

Comments

Related Posts

make your store more efficient

Solving problems. With open source technology. Professional results. That’s what makes Ibnab your best choice

IBNAB is a company made of a group of professionals whose work is providing secure open source solutions. Our company strives for reaching magnificent results with each experience and provides professional open source solutions that cover every part of the business process.