From bd2a06f48c2f78a4dfb2274946bff1f432477d11 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Mon, 8 May 2023 13:06:14 +0300 Subject: [PATCH] docs: added more details on variant pricing (#4035) * docs: added more details on variant pricing * Update manage-products.mdx * Update products.md * Update show-products.mdx * shortened down the price details in the admin guide --- .../products/admin/manage-products.mdx | 4 ++- docs/content/modules/products/products.md | 32 ++++++++++++++++++- .../products/storefront/show-products.mdx | 8 +---- docs/styles/docs/Acronyms.yml | 3 +- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/docs/content/modules/products/admin/manage-products.mdx b/docs/content/modules/products/admin/manage-products.mdx index c399c3b740..529361f5ec 100644 --- a/docs/content/modules/products/admin/manage-products.mdx +++ b/docs/content/modules/products/admin/manage-products.mdx @@ -389,10 +389,12 @@ If you don’t pass the `handle` body parameter, the handle of the product will ### Product Variant Prices -It’s recommended to set the prices of product variants as the actual amount multiplied by a hundred. This behavior is implemented within the Medusa admin, and the Next.js storefront divides all prices by a hundred before displaying the price. +For currencies that are not zero-decimal, you must set the prices of product variants as the actual amount multiplied by a hundred. So, in the example above, if the `amount` is set to `1000`, it means the price is actually `10`. +You can learn more about pricing and zero-decimal currencies [here](../products.md#storing-the-product-variants-price). + --- ## Retrieve a Product diff --git a/docs/content/modules/products/products.md b/docs/content/modules/products/products.md index a7ebc978d4..4af36dc967 100644 --- a/docs/content/modules/products/products.md +++ b/docs/content/modules/products/products.md @@ -105,7 +105,37 @@ The `MoneyAmount` entity has the following attributes that are useful for a prod ### Storing the Product Variant’s Price -Although this is no requirement, it’s recommended to store the `amount` as the price multiplied by a hundred. The Medusa admin dashboard and the Next.js storefront expect the price to be of that format, so when prices are displayed they’re divided by a hundred. Also, when you add or update a product variant, its price is sent to the Medusa backend as the price multiplied by a hundred. +You must store the `amount` in a currency's smallest unit as an integer. + +For example, if a variant's price is 10 USD, it's stored is `1000`, as in 1,000 cents. + +For zero-decimal currencies, the amount is still stored as an integer without multiplying by a 100. For example, if a variant's price is ¥500, it's stored as `500`. + +
+ Zero-decimal Currencies + + - BIF + - CLP + - DJF + - GNF + - JPY + - KMF + - KRW + - MGA + - PYG + - RWF + - UGX + - VND + - VUV + - XAF + - XOF + - XPF + +
+ +This logic of formatting the price is not handled in the backend. So, when you add a product variant using the Admin APIs, you must format the price as explained earlier. The backend stores the price as received from API requests. + +In addition, the Medusa admin dashboard and the Next.js storefront expect the price to be of that format, so when prices are displayed for currencies that are stored multiplied by a `100`, such as USD, they’re divided by a hundred. Also, when you add or update a product variant, its price is sent to the Medusa backend as the price multiplied by a hundred. ### Displaying the Product Variant’s Price diff --git a/docs/content/modules/products/storefront/show-products.mdx b/docs/content/modules/products/storefront/show-products.mdx index ce5f429605..37988c9fef 100644 --- a/docs/content/modules/products/storefront/show-products.mdx +++ b/docs/content/modules/products/storefront/show-products.mdx @@ -362,13 +362,7 @@ You must pass one of the [pricing parameters](#product-pricing-parameters) to th ::: -By default, prices in Medusa are stored as the price entered by the admin multiplied by a 100. - -:::note - -This is the behaviour if you're using the admin dashboard to create products. If you're using a different logic to create products and store prices, you can skip the instructions in this section. - -::: +Prices in Medusa are stored as the currency's smallest unit. So, for currencies that are not zero-decimal, the amount is stored multiplied by a `100`. You can learn more about this in the [Product conceptual guide](../products.md#storing-the-product-variants-price). So, to show the correct price, you would need to convert it to its actual price with a method like this: diff --git a/docs/styles/docs/Acronyms.yml b/docs/styles/docs/Acronyms.yml index 368fe3ac45..269403ad46 100644 --- a/docs/styles/docs/Acronyms.yml +++ b/docs/styles/docs/Acronyms.yml @@ -72,4 +72,5 @@ exceptions: - VIP - UPS - RMA - - JSONB \ No newline at end of file + - JSONB + - USD \ No newline at end of file