With the $wsOrderHistory module, you can load and display the order history of a logged-in customer in the frontend. This allows customers to view their past orders, retrieve order details, and place reorders, for example. In this section, you will learn how to load the order list and individual orders.
Module overview
Example / excerpt of $wsOrderHistory
{{= $wsOrderHistory | json }}
JSON output
{
"load": "ƒ()",
"loadList": "ƒ()"
}
Note: ƒ() denotes a function.
Methods overview
| Method | Return type | Description |
|---|
loadList() | array | Returns a list of the last 50 orders. |
load() | map | Returns a single order based on an order ID. |
Templates
The order history can be loaded in any template and is typically integrated into the account area. Logged-in customers can view it in the template orderHistory.htm.
Variables
No variables are available for $wsOrderHistory.
Methods
$wsOrderHistory.loadList()
Returns a list of the last 50 orders.
Signature
$wsOrderHistory.loadList()
Return value
Array - List of order maps.
Example that loads the order history into a variable.
{{ var $myOrderListVariable = $wsOrderHistory.loadList() }}
$wsOrderHistory.load()
Returns a single order based on an order ID.
Signature
$wsOrderHistory.load(orderId)
Return value
Map - Order map with all order data.
Parameters
| Name | Type | Required | Description |
|---|
orderId | string | yes | ID of the order to be loaded. |
Example that loads an order into a variable.
{{ var $order = $wsOrderHistory.load("12345") }}
By using the $wsOrderHistory.load function, various variables are available to retrieve and output order data. Below is an overview of which variables are available.
Order data (return value of $wsOrderHistory.load())
First, it is necessary to assign the map with the order data, as shown in the example above, to a local variable. This can then be used at various places in the template.
JSON output of the variable:
{
"general": {
"orderId": "...",
"dateTime": "...",
"shopId": "...",
"subshopId": "...",
"sessionId": "...",
"shopLanguage": "...",
"testMode": true/false
},
"order": {
"priceType": "...",
"currencyIso": "...",
"currencySymbol": "...",
"defaultTaxRate": "...",
"paymentId": "...",
"paymentOrderText": "...",
"delivererId": "...",
"delivererOrderText": "...",
"deliveryCost": "...",
"deliveryTaxRate": "...",
"subtotal": "...",
"total": "...",
"tax": "...",
"totalDiscount": "..."
},
"customer": {
"accountType": "...",
"accountId": "...",
"email": "...",
"ipAddress": "..."
},
"orderList": {
"items": [...]
},
"billAddress": { ... },
"shippingAddress": { ... },
"freeFields": { ... }
}
Variables overview
General variables:
| Variable | Type | Description |
|---|
general | map | Map with general information about the order. |
orderId | string | ID of the order. |
dateTime | string | Date and time of the order. |
shopId | string | ID of the shop in which the order was placed. |
subshopId | string | ID of the subshop in which the order was placed. |
sessionId | string | ID of the session in which the order was placed. |
shopLanguage | string | Language of the shop in which the order was placed. |
testMode | bool | Checks whether the order was executed in test mode. |
Order information:
| Variable | Type | Description |
|---|
order | map | Map with data about the order (prices, shipping, payment method, etc.) |
priceType | string | Price type: "net" or "gross". |
currencyIso | string | ISO code of the currency (e.g. "EUR"). |
currencySymbol | string | Currency symbol (e.g. "€"). |
defaultTaxRate | string | Standard tax rate. |
paymentId | string | ID of the payment method. |
paymentOrderText | string | Description of the payment method. |
delivererId | string | ID of the shipping method. |
delivererOrderText | string | Description of the shipping method. |
deliveryCost | string | Shipping costs. |
deliveryTaxRate | string | Tax rate of the shipping costs. |
subtotal | string | Goods value of the order. |
total | string | Total price of the order. |
tax | string | Total taxes of the order. |
totalDiscount | string | Total discount of the order. |
Customer information:
| Variable | Type | Description |
|---|
customer | map | Map with data about the buyer. |
accountType | string | Account type: "Guest" or "Existing customer". |
accountId | string | ID of the account. |
email | string | Email of the buyer. |
ipAddress | string | IP address of the buyer. |
Additional information:
| Variable | Type | Description |
|---|
orderList | map | Map with data about ordered items. |
items | array | List of ordered products. |
billAddress | map | Map with billing address data. |
shippingAddress | map | Map with shipping address data. |
freeFields | map | Map with free fields specified with the order. |
Example for displaying order history data
Display order data
After an order has been loaded from the order history and assigned to a variable, the order data can be accessed via the available maps.
In this example, the order is assigned to the variable $myOrder. The order data can be loaded from this variable and freely placed in the template.
{{if $wsViews.current.params.orderHistorySelect}}
{{var $myOrder = $wsOrderHistory.load($wsViews.current.params.orderHistorySelect)}}
{{ /if }}
General map - general info
The map $myOrder.general loads general information such as order ID and order date.
Order ID: {{= $myOrder.general.orderId }}
Order date: {{= $myOrder.general.dateTime }}
Shop ID: {{= $myOrder.general.shopId }}
Subshop ID: {{= $myOrder.general.subshopId }}
Session ID: {{= $myOrder.general.sessionId }}
Shop language: {{= $myOrder.general.shopLanguage }}
Order placed in test mode: {{ if $myOrder.general.testMode }}True{{ /if }}
Order map - info about the order
The map $myOrder.order loads technical info such as costs, payment method, shipping method, and discounts of the order.
Price "net" or "gross": {{= $myOrder.order.priceType }}
ISO code of the currency: {{= $myOrder.order.currencyIso }}
Currency symbol: {{= $myOrder.order.currencySymbol }}
Standard tax rate: {{= $myOrder.order.defaultTaxRate }}
ID of payment method: {{= $myOrder.order.paymentId }}
Description of payment method: {{= $myOrder.order.paymentOrderText }}
ID of shipping method: {{= $myOrder.order.delivererId }}
Description of shipping method: {{= $myOrder.order.delivererOrderText }}
Extra costs of shipping method: {{= $myOrder.order.deliveryCost }}
Tax rate of shipping costs: {{= $myOrder.order.deliveryTaxRate }}
Goods value: {{= $myOrder.order.subtotal }}
Total price: {{= $myOrder.order.total }}
Total taxes: {{= $myOrder.order.tax }}
Total discount: {{= $myOrder.order.totalDiscount }}
Customer map - customer info
The map $myOrder.customer loads customer info such as address and customer number.
Account type ("Guest" or "Existing customer"): {{= $myOrder.customer.accountType }}
Account ID: {{= $myOrder.customer.accountId }}
Buyer's email: {{= $myOrder.customer.email }}
Buyer's IP address: {{= $myOrder.customer.ipAddress }}
Actions
No actions are available for $wsOrderHistory.