Hi - I’m using Wix Stores and trying to user a repeater to allow users to browse and add products to their cart. I want them to be able to select the quantity of items to add from the repeater, so have added an input field of ‘Whole Number’ type to capture the quantity and a button to add to cart.
I’ve got the basics in place and can add different products to cart from the repeater but am struggling to get the quantity to work. The code I have (having tried various ideas from other posts) is as follows:
export function button6_click(event) {
let $item = $w.at(event.context);
let selectedProduct = $item( ‘#dataset1’ ).getCurrentItem();
let selectedQty = $item( “#input4” ).value;
let productId = selectedProduct._id;
$w( ‘#shoppingCartIcon1’ ).addToCart(productId,selectedQty)
.then(() => {
console.log( “add products${productID} success” );
})
}
If I plug a number directly into the variable eg: selectedQTY = 2; then it’ll work as expected. I just can’t get the #input4 field to populate the variable.
Any ideas?
Many Thanks - Mike
Assuming your dropdown variables are correct and the rest of your code is correct, you may only need to update this variable:
let selectedQty = Number($item( " #input4 " ).value);
This changes it to a number instead of text.
Hi and thanks so much for your reply Code Queen Nayeli!
I’m pretty sure that’s one of the things I tried - in any case I’ve just tried it again with no success
.
The #input4 comes from an input box with type set to Number and supported number format set to Whole Numbers .
As for the variable ‘selectedQty’, If I just set it to let selectedQty = 1; (or 2,3 or any other number) it works just fine.
I just can’t figure out what’s preventing the formula you suggested from working!
Any other ideas much appreciated!
Thanks again - Mike
SOLVED!!
Your code DOES work Code Queen !! 
AND you were right, the problem lay elsewhere.
The problem was that I had the input box set to show placeholder text rather than a default value. As such, even though the box shows up ‘1’ as you use the site the actual value of the box is NULL, so there’s nothing to add to the cart. Setting the default value to 1 works just fine!
Thanks again!!
Mike
$w( ’ #shoppingCartIcon1 ’ ).addToCart(productId,selectedQty)
please Explain on this spacialy “addToCart”