Retrieve Product Variant's Prices in Storefront
In this guide, you'll learn how to retrieve product variants' prices in the storefront, including sale prices.
Pricing Query Parameters#
When you retrieve products either with the List Products or Retrieve Products API routes, you must include in the beginning of the fields
query parameter the value *variants.calculated_price
to retrieve the product variants' prices.
You also must pass at least one of the following query parameters to retrieve an accurate product variant price:
Parameter | Description |
---|---|
| The ID of the customer's region. This parameter must be included if you want to apply taxes on the product variant's price. |
| The customer's country code. This parameter must be included if you want to apply taxes on the product variant's price. |
| The province, which can be taken from a customer's address. This parameter helps further narrowing down the taxes applied on a the product variant's prices. |
| The ID of the customer's cart, if available. If set, the cart's region and shipping address's country code and province are used instead of the |
For example:
In this example, you pass the selected region's ID as a query parameter with the fields
query parameter set to *variants.calculated_price
.
Prices for Authenticated Customer#
If you pass the customer's authentication token / session in the request, the customer and their group, if available, are automatically used to retrieve prices specific to the customer.
For example, if there's a promotion that applies to the authenticated customer's group, the promotion's prices are used instead of the default prices.
Product Variant's Price Properties#
If you pass the parameters mentioned above, each variant has a calculated_price
object with the following properties:
Property | Description | Notes |
---|---|---|
| The product variant's price. | Show this price if you didn't supply the |
| The | This property is only available if you supply both the |
| The | This property is only available if you supply both the |
| The type of the variant price. | If its value is |
Full Code Examples#
- Example: Show Product Variant's Price.
- Example: Show Product Variant's Sale Price.
- Example: Show Product Variant's Price with Taxes.