Show Products in the Storefront
List, paginate, filter, and sort catalog products.
On this page
In this guide, you'll learn how to list, paginate, and filter products in your storefront.
For Next.js App Router, call the Store API from src/lib/data/products.ts with "use server". Pass storeCode first, resolve region_id from the URL country, and request calculated prices only when a region exists. See Build a Next.js Storefront.
List Products
To retrieve products, send a request to the List Products API route:
Tip: Learn how to install and configure the JS SDK in the Getting started guide.
Next.js (recommended)
ts
Never request calculated_price without a region_id. Use this from a server component (app/[countryCode]/(store)/shop/page.tsx), not from a client useEffect.
React (SPA)
tsx
JS SDK
ts
The response has a products field, which is an array of products.
Paginate Products
To paginate products, pass the following query parameters:
limit: The number of products to return in the request.offset: The number of products to skip before the returned products. You can calculate this by multiplying the current page with the limit.
The response object returns a count field, which is the total count of products. Use it to determine whether there are more products that can be loaded.
For example:
tsx
In the example above, you add a useEffect hook that runs whenever the loading state changes. This hook fetches the products, passing the limit and offset parameters to retrieve the paginated products.
You then show a button to load more products if there are more pages.
Filter Products
The List Products API route accepts query parameters to filter products by title, category, handle, and more.
Refer to the API reference for the full list of accepted query parameters.
Filter by Options
This feature is available in the current Aiminaabee API.
The List Products API route supports filtering products by options and their values, such as size or color. This is useful to add filtering functionality to your storefront.
Learn more about product options and how to filter by them in the Product Options guide.
Filter by Keyword
For example, to filter products by a keyword:
ts
The q parameter is used to filter a product's searchable fields, such as its title or description, by a keyword.
The result will be products that match the keyword in their title or description.
Sort Products
To sort products by a field, use the order query parameter. Its value is a comma-separated list of fields to sort by, and each field is optionally prefixed by - to indicate descending order.
For example, to sort products by title in descending order:
ts
The result will be products sorted by title in descending order.
Retrieve Translations for Products
Prerequisites
- Translation Module Configured
By default, Aiminaabee returns the product's original content (such as title and description).
If you support localization in your storefront, you can set the locale to retrieve product information with based on the customer's preferred language.
You can set the locale using one of the following methods:
- Use the JS SDK's
setLocalemethod. The JS SDK will automatically include the locale in subsequent requests. - Pass the
localequery parameter to the List Products API route. - Set the
x-aiminaabee-localeheader in the API request to the List Products API route.
For example:
Using JS SDK
ts
Using Query Parameter
bash
Using Header
bash
The returned products will have the same structure as described in the products schema, but their fields like title and description will be in the specified locale:
json
If translations aren't available for the selected locale, or no locale is selected, the product's original content is returned.
Retrieve in Server-Side Environments
For server-side environments (such as server components or server actions in Next.js), you can set the locale using cookies to persist the selected locale across requests.
Learn more in the Storefront Localization guide.