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.

Displaying Individual Order Details

The Order Details page displays details of a specific order. You can create links to the Order Details page from the Customer Orders page described in the previous article. On the Order Details page you can output the order number, order date, totals, order status and a list of order items. Also, if an order is not yet paid, you can output a link to the Pay page.

Start with creating a new page and assign it a name and URL. As the page should be accessible only for logged in customers, you need to go to the Security tab and select the Customers only in the Access section. Click the Action tab and select the shop:order action in the drop-down menu.

The shop:order action loads an order with the ID specified in the URL and creates the $order and $items variables which you can access in the page code. A value of the $order variable can be null in case if the requested order was not found in the database. Always check a value of the variable before displaying the order details.

The following code outputs the order details and a list of order items.

<h2>Order</h2>
<? if (!$order): ?>
  <h3>Order not found</h3>
<? else: ?>  
  <p>
    Order # <?= $order->id ?><br/>
    Order Date: <?= h($order->order_datetime->format('%x')) ?><br/>
    Total: <?= format_currency($order->total) ?><br/>
    Status: <?= h($order->status->name) ?>
  </p>
  
  <table>
    <thead>
      <tr>
        <th>Items</th>
        <th>Price</th>
        <th>Discount</th>
        <th>Quantity</th>
        <th>Total</th>
      </tr>
    </thead>
    <tbody>
      <?
        foreach ($items as $item):
          $image_url = $item->product->image_url(0, 60, 'auto');
      ?>
        <tr>
          <td>
            <? if ($image_url): ?><img src="<?= $image_url ?>"/><? endif ?>
            <?= $item->output_product_name() ?>
            <? if ($item->product->product_type->files && $order->is_paid() && $item->product->files->count): ?>
              Download:
              <ul>
                <? foreach ($item->product->files as $file): ?>
                  <li><a href="<?= $file->download_url($order) ?>"><?= h($file->name) ?></a> (<?= $file->size_str ?>)</li>
                <? endforeach ?>
              </ul>
            <? endif ?>
          </td>
          <td><?= format_currency($item->single_price) ?></td>
          <td><?= format_currency($item->discount) ?></td>
          <td><?= $item->quantity ?></td>
          <th><?= format_currency($item->subtotal) ?></th>
        </tr>
      <? endforeach ?>
    <tbody>
  </table>
  
  <p>
    Subtotal: <?= format_currency($order->subtotal) ?><br/>
    Discount: <?= format_currency($order->discount) ?><br/>
    Goods tax: <?= format_currency($order->goods_tax) ?><br/>
    Shipping: <?= format_currency($order->shipping_quote) ?>
    <? if ($order->shipping_tax): ?>
      <br/>Shipping tax: <?= format_currency($order->shipping_tax) ?>
    <? endif ?>
  </p>
  
  <p>Total: <?= format_currency($order->total) ?></p>
  <p>
    <a href="/orders">Return to the order list</a>
    <? if($order->payment_method->has_payment_form() && !$order->payment_processed()): ?>
      <a href="/pay/<?= $order->order_hash ?>">Pay</a>
    <? endif ?>
  </p>
<? endif ?>
<h2>Order</h2>
{% if not order %}
  <h3>Order not found</h3>
{% else %}
  <p>
    Order # {{ order.id }}<br/>
    Order Date: {{ order.order_datetime.format('%x') }}<br/>
    Total: {{ order.total|currency }}<br/>
    Status: {{ order.status.name }}
  </p>
  
  <table class="simple_table">
    <thead>
      <tr>
        <th>Items</th>
        <th>Price</th>
        <th>Discount</th>
        <th>Quantity</th>
        <th>Total</th>
      </tr>
    </thead>
    <tbody>
      {% for item in items %}
        {% set image_url = item.product.image_url(0, 60, 'auto') %}
        <tr>
          <td>
            {% if image_url %}<img class="product_image" src="{{ image_url }}" alt="Mac mini"/>{% endif %}
            <div class="product_description">
              {{ item.output_product_name()|unescape }}
              {% if item.product.product_type.files and order.is_paid() and item.product.files.count %}
                Download:
                <ul>
                {% for file in  item.product.files %}
                  <li><a href="{{ file.download_url(order) }}">{{ file.name }}</a> ({{ file.size_str }})</li>
                {% endfor %}
                </ul>
              {% endif %}
            </div>
          </td>
          <td>{{ field(item, 'single_price')|currency }}</td>
          <td>{{ item.discount|currency }}</td>
          <td>{{ item.quantity }}</td>
          <th>{{ field(item, 'subtotal')|currency }}</th>
        </tr>
      {% endfor %}
    </tbody>
  </table>
  
  <p>
    Subtotal: {{ order.subtotal|currency }}<br/>
    Discount: {{ order.discount|currency }}<br/>
    Goods tax: {{ order.goods_tax|currency }}<br/>
    Shipping: {{ order.shipping_quote|currency }}<br/>
    {% for tax in order.list_shipping_taxes() %}
      Shipping tax ({{ tax.name }}): {{ tax.total|currency }}<br/>
    {% endfor %} 
  </p>
 
  <p>Total: {{ order.total|currency }}</p>
  <p>
    <a href="/orders">Return to the order list</a>
    {% if order.payment_method.has_payment_form() and not order.payment_processed() %}
      <a href="/pay/{{ order.order_hash }}">Pay</a>
    {% endif %}
  </p>
{% endif %}

Please note that the code outputs links to downloadable files assigned to a product. This is needed when you sell downloadable products. The list of files is displayed only if the order is paid. To determine whether the order is paid, the is_paid method of the $order object is used. The order is considered as paid if there is a Paid status in the order status history. Please read Integrating downloadable products article for details.

The Pay button outputs only if the order payment is not processed. To check whether the payment is processed, the payment_processed method of the $order object is used. The is_paid and payment_processed methods could return opposite results in case a customer has paid an order (the payment_processed method will return TRUE), but you (a merchant) have not checked the payment and have not sent the order into the Paid status (the is_paid method will return false). 

Displaying bundle items

Displaying bundle items on the order details page is similar to displaying bundle items in the cart. In the code snippet below we updated the code from the previous section in order to display bundle items in the same way as we explained on the Cart page

<table>
  <thead>
    <tr>
      <th>Items</th>
      <th>Price</th>
      <th>Discount</th>
      <th>Quantity</th>
      <th>Total</th>
    </tr>
  </thead>
  <tbody>
    <?
      $last_index = $items->count-1;  
      foreach ($items as $index=>$item):
        $image_url = $item->product->image_url(0, 60, 'auto');
    ?>
      <tr>
        <td>
          <? if ($image_url): ?><img src="<?= $image_url ?>"/><? endif ?>
          <?= $item->output_product_name() ?>
          <? if ($item->product->product_type->files && $order->is_paid() && $item->product->files->count): ?>
            Download:
            <ul>
              <? foreach ($item->product->files as $file): ?>
                <li>
                  <a href="<?= $file->download_url($order) ?>"><?= h($file->name) ?></a> (<?= $file->size_str ?>)
                </li>
              <? endforeach ?>
            </ul>
          <? endif ?>
        </td>
        <td><?= format_currency($item->single_price) ?></td>
        <td><?= format_currency($item->discount) ?></td>
        <!-- Use get_bundle_item_quantity() method for bundle items to display
             a correct number of items in each base product -->
        <td><?= $item->bundle_master_order_item_id ? $item->get_bundle_item_quantity() : $item->quantity ?></td>
        <th>
          <? if (!$item->bundle_master_order_item_id): ?>
            <?= format_currency($item->total_price) ?>
          <? else: 
            // For bundle items use the bundle_item_total_price() method 
            // to get the total item price per single base product
            // and display the multiplier.
            $master_item = $item->get_master_bundle_order_item();
            $multiplier = ($master_item && $master_item->quantity > 1) ? ' x '.$master_item->quantity : null;
          ?>
            <?= format_currency($item->bundle_item_total).$multiplier ?>
          <? endif?>
        </th>
      </tr>
  
      <!-- Display the bundle total row -->
  
      <? if (
              ($item->bundle_master_order_item_id && $index == $last_index) 
              || ($item->bundle_master_order_item_id && !$items[$index+1]->bundle_master_order_item_id)): 
          $master_item = $item->get_master_bundle_order_item();
          if ($master_item):
      ?>
          <tr>
            <td><?= h($master_item->product->name) ?> bundle totals</td>
            <td><?= format_currency($master_item->get_bundle_single_price()) ?></td>
            <td><?= format_currency($master_item->get_bundle_discount()) ?></td>
            <td><?= $master_item->quantity ?></td>
            <th><?= format_currency($master_item->get_bundle_total_price()) ?></th>
          </tr>
      <? 
          endif;
        endif 
      ?>
    <? endforeach ?>
  </tbody>
</table>
<table class="simple_table">
  <thead>
    <tr>
      <th>Items</th>
      <th>Price</th>
      <th>Discount</th>
      <th>Quantity</th>
      <th>Total</th>
    </tr>
  </thead>
  <tbody>
    {% for index, item in items %}
      {% set image_url = item.product.image_url(0, 60, 'auto') %}
      <tr>
        <td>
          {% if image_url %}<img class="product_image" src="{{ image_url }}" alt="Mac mini"/>{% endif %}
          <div class="product_description">
            {{ item.output_product_name()|unescape }}
            {% if item.product.product_type.files and order.is_paid() and item.product.files.count %}
              Download:
              <ul>
              {% for file in  item.product.files %}
                <li><a href="{{ file.download_url(order) }}">{{ file.name }}</a> ({{ file.size_str }})</li>
              {% endfor %}
              </ul>
            {% endif %}
          </div>
        </td>
        <td>{{ field(item, 'single_price')|currency }}</td>
        <td>{{ item.discount|currency }}</td>
        <!-- Use get_bundle_item_quantity() method for bundle items to display
          a correct number of items in each base product -->
        <td>{{ item.bundle_master_order_item_id ? item.get_bundle_item_quantity() : item.quantity }}</td>
        <th>
          {% if not item.bundle_master_order_item_id %}
            {{ field(item, 'subtotal')|currency }}
          {% else %}
            {# For bundle items use the bundle_item_total_price() method
                to get the total item price per single base product
                and display the multiplier. #}
                
            {% set master_item = item.get_master_bundle_order_item() %}
            {% set multiplier = (master_item and master_item.quantity > 1) ? ' x '~master_item.quantity : null %}
            {{ field(item, 'bundle_item_total')|currency~multiplier }}
          {% endif %}
        </th>
      </tr>
      
      <!-- Display the bundle total row -->
      
      {% 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>
            <td>{{ master_item.product.name }} bundle totals</td>
            <td>{{ master_item.get_bundle_single_price()|currency }}</td>
            <td>{{ master_item.get_bundle_discount()|currency }}</td>
            <td>{{ master_item.quantity }}</td>
            <th>{{ master_item.get_bundle_total_price()|currency }}</th>
          </tr>
        {% endif %}
      {% endif %}
    {% endfor %}
  </tbody>
</table>

See also:

Next: Order Details Page for Inclusive Tax Environments
Previous: Order History, Status, and Details
Return to Order History, Status, and Details