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.

TipFor 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_id

The ID of the customer's region. This parameter must be included if you want to apply taxes on the product variant's price.

country_code

The customer's country code. This parameter must be included if you want to apply taxes on the product variant's price.

province

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.

cart_id

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 region_id, country_code, and province parameters.

For example:

TipLearn how to install and configure the JS SDK in the JS SDK documentation.
Code
1sdk.store.product.retrieve(id, {2  fields: `*variants.calculated_price`,3  region_id: region.id,4})5.then(({ product: dataProduct }) => {6  // TODO use product7  console.log(product)8})

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_amount

The 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_tax

The 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_tax

The 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_type

The 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#

Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break