Customer orders page
On the Customer Orders page you can display a list of orders a current customer.

Start with creating a new page and assign it a name and URL, for example Orders and /orders correspondingly. The page name and URL can be anything. The orders page is only for logged in customers,so you need to protect the page from guest access. Click the Security tab and select Customers only option in the Access section. Then click the Action tab and select the shop:orders action in the drop-down menu.
The shop:orders action loads a list of orders from current customers and creates the $orders variable which can be used in the page code. The following code snippet outputs a list of orders. A value of the $orders variable can be NULL if case if there is no currently logged in customer. Always check a value of this variable before displaying the order list.
<h2>My Orders</h2>
<? if (!$orders): ?>
<p>Orders not found</p>
<? else: ?>
<p>Click an order for details.</p>
<table>
<thead>
<tr>
<th></th>
<th>#</th>
<th>Date</th>
<th>Status</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<? if (!$orders->count): ?>
<tr>
<td colspan="5">No orders found</td>
</tr>
<? endif ?>
<? foreach ($orders as $order):
$url = '/order/'.$order->id;
?>
<tr>
<td>
<span title="<?= h($order->status->name) ?>" style="background-color: <?= $order->color ?>"> </span>
</td>
<td><a href="<?= $url ?>"><?= $order->id ?></a></td>
<td><a href="<?= $url ?>"><?= $order->order_datetime->format('%x') ?></a></td>
<td><a href="<?= $url ?>"><strong><?= h($order->status->name) ?></strong> since <?= $order->status_update_datetime->format('%x') ?></a></td>
<th><a href="<?= $url ?>"><?= format_currency($order->total) ?></a></th>
</tr>
<? endforeach ?>
</tbody>
</table>
<? endif ?><h2>My Orders</h2>
{% if not orders %}
<p>Orders not found</p>
{% else %}
<p>Click an order for details.</p>
<table>
<thead>
<tr>
<th></th>
<th>#</th>
<th>Date</th>
<th>Status</th>
<th>Total</th>
</tr>
</thead>
<tbody>
{% if not orders.count %}
<tr>
<td colspan="5">No orders found</td>
</tr>
{% endif %}
{% for order in orders %}
{% set url = root_url('/order/'~order.id) %}
<tr>
<td>
<span title="{{ order.status.name }}" style="background-color: {{ field(order, 'color') }}"> </span>
</td>
<td><a href="{{ url }}">{{ order.id }}</a></td>
<td><a href="{{ url }}">{{ order.order_datetime.format('%x') }}</a></td>
<td><a href="{{ url }}"><strong>{{ order.status.name }}</strong> since {{ order.status_update_datetime.format('%x') }}</a></td>
<th class="right last"><a href="{{ url }}">{{ order.total|currency }}</a></th>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}For each order in the $orders collection the code creates a table row with the order number, date, status and total sum. Also, a link to the Order Details page is created. The Order details page is discussed in the next article.
See also:
Next: Order details page
Previous: Payment Receipt page
Return to Building your online store

