Hi all, I posted this yesterday, but realized my long-windedness may have scared people away.
So, I’m planning to sell limited edition prints on a Wix store and I want to display the number of prints remaining. I came up with a workaround in which I created a text element on my product page (see image). The wrote some code to access the product’s .quantityInStock property and assign the results to display in my text element. (see code below)
let productQuantityNum = 200; //initialize product quantity variable
let soldOutText = "Edition Sold Out" //initialize variable to display "sold out" text when inventory is 0
$w.onReady(function () {
//TODO: write your page related code here...
$w('#productPage1').getProduct() //get current product
.then( (product) => {
productQuantityNum = product.quantityInStock; //get quantity in stock for current product
if (productQuantityNum > 0) { //if it's greater than 0, Display number remaining
let productQuantityString = productQuantityNum.toString();
$w("#quantityRemainingText").text = productQuantityString + " remaining";
} else {
$w("#quantityRemainingText").text = soldOutText; //display sold out text
}
} )
.catch( (error) => {
console.log(error);
} );
});
This works, but the problem is that the product.quantityInStock property seems to hold the combined inventory for all the varients. What I want is for my text to display the number available for the currently selected varient. Becaus the two varients are separate products. I realize I can separate them into two separate products, but this is not ideal for me.
So, I looked and found there are a number of objects in the Wix api that relate to the product options (StoreProductOption, StoreProductOptionsChoice, and the ProductOptionsAvailability), however, I don’t see any mention of there being a .quantityInStock property for the specific product option as there is for the general product object.
So, can anyone tell me if there is such a property? If so, how can I retrieve it and implement it into my code?
My knowledge of Javascript is close to none and general coding only slightly more, so any code snippets you could provide would be highly appreciated. Or if there are different or better ways of accomplishing my goal, please let me know.
Cheers!
Jonathan