I am adding products to cart using code. The first product gets added seamlessly the way I desire, but the second product never adds and show me this in google chrome console log:
FetchError: [object Object]
at new a (https://static.parastorage.com/services/wixstores-client-worker/1.165.0/unified-viewer.bundle.min.js:1:456913)
at eval (https://static.parastorage.com/services/wixstores-client-worker/1.165.0/unified-viewer.bundle.min.js:1:457559)
at eval (https://static.parastorage.com/services/wixstores-client-worker/1.165.0/unified-viewer.bundle.min.js:1:4668)
at Object.eval [as next] (https://static.parastorage.com/services/wixstores-client-worker/1.165.0/unified-viewer.bundle.min.js:1:4773)
at i (https://static.parastorage.com/services/wixstores-client-worker/1.165.0/unified-viewer.bundle.min.js:1:3544)
Code I used is this:
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import wixData from ‘wix-data’;
// …
$w.onReady( function () {
//TODO: write your page related code here…
});
let cart = “”;
let fabric = “”;
export function button5_click(event) {
//Add your code for this event here:
wixData.query(“Stores/Products”)
.contains(“name”, $w(“#input1”).value)
.find()
.then( (results) => {
let newitem = results.items[0];
console.log(newitem)
let name = newitem.name;
console.log(name);
$w(“#text35”).text = name;
let url = newitem.mainMedia;
console.log(url);
$w(“#image2”).src = url;
let price = newitem.price;
console.log(price);
let newprice = price.toString()
$w(“#text37”).text = newprice;
cart = newitem._id;
console.log(cart)
fabric = newitem.productOptions.Fabric.choices[0].description;
console.log(fabric)
let options1 = newitem.productOptions.Color.choices;
console.log(options1)
let options2 = newitem.productOptions.Size.choices;
console.log(options2)
let options1l = options1.length;
let length1 = options1l;
let value1 = options1;
let options2l = options2.length;
let length2 = options2l;
let value2 = options2;
let test = ;
for ( let i = 0; i < length1; i++) {
test[i] = {
label: value1[i].value,
value: value1[i].value
}
$w(“#dropdown1”).options = test;
}
let test1 = ;
for ( let j = 0; j < length2; j++) {
test1[j] = {
label: value2[j].value,
value: value2[j].value
}
$w(“#dropdown2”).options = test1;
}
} );
}
export function button6_click(event) {
//Add your code for this event here:
$w(‘#shoppingCartIcon1’).addToCart(cart, $w(“#dropdown4”).value, {
“choices”: {
“Size”: $w(‘#dropdown2’).value,
“Color”: $w(‘#dropdown1’).value,
“Fabric”: fabric
}
}).then( () => {
console.log("Product added");
} )
. catch ( (error) => {
console.log(error);
} );
}
Please help me out. All is working great and this is something which is just keeping me apart from the end.