Bug in getProductOptionsAvailability API

Hi everyone, I think I have found a bug in the getProductOptionsAvailability( ) api.

If a product has a normal price of 500€, and I set 10% discount in the product settings, the API shows a wrong value under
selectedVariant.discountedPrice
and
selectedVariant.formattedDiscountedPrice

Sales price 500€
Sale price 500€ - 10% = 450€
The selected product variant has a surcharge of 55€

Therefore selectedVariant.formattedDiscountedPrice (500€+55€) -10% = 499,5€.

but selectedVariant.formattedDiscountedPrice calculates (500€-10%) + 55€ = 505€

However, if you change the discount from % to €, (500€+55€) - 50€ = 505€ is calculated, which is correct.

If you then add the product to the shopping cart, the percentage discount is correctly displayed as 499.5€ and 505€ for the € discount in the shopping cart.

This is absolutely confusing and is due to incorrect programming of the percentage discount in the getProductOptionsAvailability() API.

Also in the product setting of the corresponding variant the correct price is displayed at the percentage discount of 499,5€.

What is also unfortunate is that the API does not display the number of available variants.

Does anyone have any other idea how I can determine the price, the discounted price and the number of available product variants using velo code?

Unfortunately, Wix currently calculates discounts on the original product price, not the variant price. This means any discounts you set in Wix Stores will be applied to the base price before variant selections.

Here’s a tip: To account for variant pricing, consider setting the original price slightly higher to accommodate the variant surcharge.

Now, let’s dive into managing inventory for your festival product variants:

Checking Inventory with getProductOptionsAvailability

The getProductOptionsAvailability function in Velo is a handy tool for checking a product variant’s availability and quantity. Here’s how it works:

  1. Use getProductOptionsAvailability to retrieve product information for your festival product. This function takes the product ID and any selected options (e.g., size) as arguments.
  2. The response includes a property called availableForPurchase. This indicates if the chosen variant is currently in stock (available for purchase).
  3. If availableForPurchase is true , the response also provides the quantity property within the selectedVariant object. This tells you the exact number of units of that specific variant remaining in stock.

Remember: To ensure accurate inventory control, you need to manage stock levels directly in your Wix product settings. This function helps you display that information on your website.strong text

Thank you for your reply.

It is not quite correct that the discounts entered are calculated on the base price. The error only occurs with the discount in % selection.

Take a look at the following screenshots, it is always the same product in the following variant:

Color = Blue
Size = L
Material = Cotton

On the following screenshot you can see the following:

Price = 500€
Discount = -50€
Sale price = 450€
Variant surcharge +55€

To get the price of the variant, Wix calculates as follows in the product menu:
Price (500€) + variant surcharge (+55€) - discount (-50€) = 505€

However, the API calculates:
Price (500€) - Discount(-50€) + Variant surcharge(+55€) = 505€

This is not a problem with discounts in € because both calculations always produce the same result.

In screenshot 2 you can also see the correct display in the store.

In the following screenshot number 3 you can see the setting for the same product but now with a percentage discount:

Price = 500€
Discount = -10%
Sale price = 450€
Variant surcharge +55€

To get the price of the variant, Wix calculates as follows in the product menu:
Price (500€) + variant surcharge(+55€) - discount(-10%) = 499,50€

However, the API calculates:
Price (500€) - Discount(-10%) + Variant surcharge(+55€) = 505€

This Screenshot clearly shows that the API only adds the variant surcharge after deducting the discount. However, this is fundamentally wrong, because if the product had no discount, the variant surcharge would also be added.

Unfortunately, I cannot confirm point 3 of your answer.

The number of available products of the respective variant is not displayed if the condition is met.

You can see this in this screenshot:

bedingung erfüllt

About the first problem.
I think you need to contact with support for this

about the second one after checking api-reference.
I see that you’re supposed to get the quantity.
Make sure that your truck inventory in the setting.