Hi,
I created a custom private member page to display member’s requests and status of their requests. Also depending on the status, various buttons will be displayed for repeater items. I also placed 2 buttons on top of repeaters which display the data accordingly.
One of the buttons is add to cart, which when clicked creates the product and adds the same to the cart. The code worked fine till few days ago, but is not working now. Product is being created and the new product id is being fetched. But it is not being added to the cart i.e., cart.addProducts is not working. It works with a constant string but not with a dynamic value.
Any help regarding the same please. This is hindering my site functionality. Thanks in advance.
async function productCreation ( event ){ let $item = $w . at ( event . context ); let title = ( $item ( ‘#text106’ ). text ) + ’ ’ + ‘(Customized)’ ; let desciption = $item ( ‘#text116’ ). text ; let subTotal = Number ( $item ( ‘#input1’ ). value );
async function Cart ( event ){ let $item = $w . at ( event . context ); const id = newProductId ; const quantity = Number ( $item ( ‘#quantity’ ). value );
**const** products = [
{
"productId" : id ,
"quantity" : quantity
}]
cart . addProducts ( products )
. then (() => {
// Only show the Mini Cart if the site is not being viewed on mobile
**if** ( formFactor !== "Mobile" ) {
cart . showMiniCart ();
}
})
Thanks for writing. I tried the code but it still shows the same error(i.e., $item(‘#errorcart’).show() is getting triggered). I don’t understand where exactly it is going wrong.
Please I have a problem because when I click on the add to cart button (#addGranos), the mini cart is shown on the mobile, and that is what I want to avoid, please can you tell me what is wrong in the code why it continues to show the cart in the mobil.
$w.onReady(function () {
$w("#addGranos").onClick((event) => {
let $item = $w.at(event.context);
let selectedProduct = $item('#Granos').getCurrentItem();
let productId = selectedProduct._id;
let formFactor = wixWindow.formFactor; // "Mobile"
$w('#shoppingCartIcon1').addToCart(productId)
.then(() => {
if (formFactor !== "Mobile") {
cart.hideMiniCart();
}
console.log("add product ${productId} success");
})
.catch((error) => {
console.log(error)
});
});
});