Product listing page

How to display prices for a list of products

Problem

You've created a product listing page (i.e. category or collection page) with your favorite CMS and now you want to display the price for each of the products. You have the SKU codes of the products you want to list.

Solution

To retrieve the price for each of the SKUs on the page, send a GET request to the /api/skusendpoint, filter it by code, and include the associated prices.

Example

The following request retrieves the prices of the SKUs identified by a list of specific codes:

curl -g -X GET \
  'https://yourdomain.commercelayer.io/api/skus?filter[q][code_in]=TSHIRTG5B5B5BST,TSHIRTWF5F5F5MN,TSHIRTB0A0A0ACL,TSHIRTB212F3FSM&include=prices' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token'

To be sellable in a market an SKU must have a price in the market's price list and at least one stock item in one of the market's stock locations, regardless of its quantity. About that, please note that the above API call returns sellable products, but doesn't show any details about the availability of the SKUs because, for performance reasons, the inventory information is only returned when fetching a single SKU. Read this for more info on how to display just the available products.

Mapping

The image below shows the two main dynamic elements of the page (selling price and full price) and how each of these is mapped to a specific field of the price object.

Additional notes

Available products and "Add to cart" button

Out-of-stock items are still considered sellable (i.e. they have a price and are associated with an existing stock item, only that the stock item quantity is equal to 0) but they are not available and would return an error when trying to add them to the cart.

If you want to display the available products only and show an "Add to cart" button instead of a "View details" one, we recommend you to refine the above request with an additional filter to make sure that the returned SKUs have an available quantity (i.e. they are associated with a stock item that has a quantity greater than 0).

The following request retrieves the prices of all the available SKUs:

curl -g -X GET \
  'https://yourdomain.commercelayer.io/api/skus?filter[q][code_in]=TSHIRTG5B5B5BST,TSHIRTWF5F5F5MN,TSHIRTB0A0A0ACL,TSHIRTB212F3FSM&filter[q][stock_items_quantity_gt]=0&include=prices' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token'

More to read

See our documentation if you need more information on how to filter data and include associations.

Last updated