Displaying the cart summary
How to show an order summary to your customers
Last updated
How to show an order summary to your customers
Last updated
You want to display an order summary to your customer, including the order line items and totals.
To retrieve the list of line items that compose an order summary, send a GET
request to the /api/orders/:id
endpoint and include its line items.
To get a faster response and fewer data to parse, we recommend requesting only the fields you need to show in the cart summary.
The following request fetches the list of line items associated with the order identified by the "yzkWXfgHQS" ID, with a specific selection of the fields you need to show in the cart summary:
The image below shows how each of the elements of the shopping cart is mapped to a specific field of the order or line item objects.
Select the last updated order belonging to the customer by sorting the API call results by the updated_at
attribute (desc) with page[size]=1
.
Double-check that the order has not been created as guest by filtering the API call by the guest
attribute.
Check that the order is still editable by filtering the API call by status
.
The following request fetched the last updated, editable order belonging to the customer identified by the "nDNahABVZR" ID:
You may have noticed the pseudo-code { "other": "... line items (different item types)" }
in the response. That's because the above request fetches all the line items associated with the order (SKUs, shipments, payment methods, and promotions). If you plan to use only some of them, remember to properly filter them through some client-side logic based on their item_type
attribute.
Commerce Layer supports the option for payment methods to have a cost. If that's your case and you want to display it in the cart summary, remember to add also the formatted_payment_method_amount
order's field in the API call above.
When working with carts belonging to logged customers, you might want to retrieve the current order associated with the logged customer (e.g. to give them the possibility to edit the cart content before placing the order). To do that, you don't need to know the order ID in advance, but you can directly fetch the order relationship of the customer using a . Just make sure to:
See our documentation if you need more information on how to or to . For further details on how to use include
, sort
, and fields
queries in your request, see , , and .