Retrieve Product Variant

Retrieve calculated variant prices for a region.

On this page

In this guide, you'll learn how to retrieve product variants' prices in the storefront, including sale prices.

Tip: For code examples on how to show product variants' prices in your storefront, refer to the Full Code Examples section.

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:

ParameterDescription
region_idThe ID of the customer's region. This parameter must be included if you want to apply taxes on the product variant's price.
country_codeThe customer's country code. This parameter must be included if you want to apply taxes on the product variant's price.
provinceThe lower-case ISO 3166-2 province code, 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.
cart_idThe 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 region_id, country_code, and province parameters.

For example:

Tip: Learn how to install and configure the JS SDK in the Getting started guide.

ts

tsCopy
sdk.store.product.retrieve("us", id, {
fields: `*variants.calculated_price`,
region_id: region.id,
})
.then(({ product: dataProduct }) => {
// TODO use product
console.log(product)
})

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:

PropertyDescriptionNotes
calculated_amountThe product variant's price.Show this price if you didn't supply the region_id and country_code query parameters to retrieve prices with taxes applied.
calculated_amount_with_taxThe calculated_amount with taxes applied.This property is only available if you supply both the region_id and country_code query parameters.
calculated_amount_without_taxThe calculated_amount without taxes applied.This property is only available if you supply both the region_id and country_code query parameters.
calculated_price.price_list_typeThe type of the variant price.If its value is sale, it means the calculated_amount is a sale price. You can show the amount before the sale using the original_amount property.

Full Code Examples