This is the documentation for LemonStand V1, which has been discontinued. You can learn more and upgrade your store here.

LemonStand Version 1 Has Been Discontinued

This documentation is for LemonStand Version 1. LemonStand is now offered as a cloud-based eCommerce platform.
You can try the new LemonStand and learn about upgrading here.

Managing Compound Email Variables

The Compound Email Variables feature allows you to output product or order specific information in email messages. Compound email variables are basically blocks of PHP code, which can access any API objects and functions. You can modify existing email variables, or create new variables.

To manage email variables, please go to the System/Settings page, click the Email Templates link and then click the Manage Compound Variables button in the toolbar.

There are two pre-defined PHP variables available in email variable code. These variables are:

  • $order variable, which represents a related order object. This variable is an object of the Shop_Order class.
  • $items variable, which represents a collection of the order items. Each element in the collection is an object of the Shop_OrderItem class.

Using Twig in compound email variables

You can choose to use Twig as a templating engine for your compound email variables and email layouts. You can enable Twig on the System/Settings/Email Settings page.

Below is a code of the order_content email variable written with Twig:

{% set include_tax = method('Shop_CheckoutData', 'display_prices_incl_tax', order) %}
<table class="simpleList" style="font: normal 11px/150% Arial, Verdana, sans-serif; width: 100%">
  <thead style="text-align: left; background: #e5e5e5">
    <tr>
      <th>Item</th>
      <th>SKU</th>
      <th class="number">Price</th>
      <th class="number">Discount</th>
      <th class="number">Quantity</th>
      <th class="number last">Total</th>
    </tr>
  </thead>
  <tbody style="text-align: left; background: white">
    {% set last_index = items|length-1 %}
    {% for index, item in items %}
      <tr>
        <td>
          <div {% if item.bundle_master_order_item_id %}style="padding-left: 30px"{% endif %}>
            {{ item.output_product_name()|unescape }}
          </div>
        </td>
        <td>{{ item>product_sku ? item.product_sku : '<product not found>' }}</td>
        <td class="number">{{ include_tax ? itemprice_tax_included|currency : field(item, 'single_price')|currency }}</td>
        <td class="number">{{ include_tax ? item.discount_tax_included|currency : item.discount|currency }}</td>
        <td class="number">{{ item.get_bundle_item_quantity() }}</td>
        <td class="number last">
          {% set master_item = item.get_master_bundle_order_item() %}
          {% set multiplier = (master_item and master_item.quantity > 1) ? ' x '~master_item.quantity : null  %}
          {{ include_tax ? field(item, 'bundle_item_total_tax_incl')|currency~multiplier : field(item, 'bundle_item_total')|currency~multiplier }}
        </td>
      </tr>
    
      {% if (item.bundle_master_order_item_id and index == last_index) or
        (item.bundle_master_order_item_id and
        not attribute(items, index+1).bundle_master_order_item_id) %}
        {% set master_item = item.get_master_bundle_order_item() %}
        {% if master_item %}
        <tr style="background: #eee">
          <td colspan="2">{{ master_item.product.name }} bundle totals</td>
          <td class="number">{{ master_item.get_bundle_single_price()|currency }}</td>
          <td class="number">{{ master_item.get_bundle_discount()|currency }}</td>
          <td class="number">{{ master_item.quantity }}</td>
          <td class="number">{{ master_item.get_bundle_total_price()|currency }}</td>
        </tr>
        {% endif %}
      {% endif %}
    {% endfor %}
  </tbody>
</table>

Modifying existing email variables

There are several pre-defined compound email variables, which you can modify. For example - the order item list - order_content. Click this variable in the list to open the editor form. As you can see, the variable code outputs a list of order items, by iterating through the $items collection. You can modify the code and alter the way how item information is displayed.

Creating new email variables

Click the Add Variable button on the Compound Email Variables page. In the variable form, enter the variable name and description. Place the code for displaying the variable content to the Code field and click the Create button. After adding a compound email variable, you can start using it in email templates. Compound email variables are listed in the sidebar of the Create/Edit Email Template page.

Next: How to Manually Send Email Messages
Previous: Creating Custom Email Templates
Return to Notifications and Emails