LemonStand Wiki

Order details page

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>
    <tr>
      <th>Items</th>
      <th>Price</th>
      <th>Discount</th>
      <th>Quantity</th>
      <th>Total</th>
    </tr>
    <?
      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 ?>
  </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 ?>

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.

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).

See also:

Next: Order details page for inclusive tax environments
Previous: Customer orders page
Return to Building your online store

Comments

No comments posted so far.

Add your comment

Loading form...