Hi Everyone, I m looking for your help after 4 days working 13 hours trying to MAKE MY ADD TO CARD WORKING. Your help will be appraciated.
I have a website with two collections
- the first for the client personal information need to add their product
- the second for products info.
I need to allow my visitors to add to card succesfully from any Client.
Here are all the codes I tried.
import wixData from 'wix-data';
import { cart } from 'wix-stores';
export function dynamicDataset_ready() {
let product = $w('#dynamicDataset').getCurrentItem();
let idproduct = product.foodPrice;
$w('#AddToCart').onClick( () => {
cart.addProducts(idproduct)
.then((shoppingCartIcon1) => {
//Products added to cart
const cartId = shoppingCartIcon1._id;
const cartLineItems = shoppingCartIcon1.lineItems;
console.log("Product Added")
cart.showMiniCart();
})
.catch((error) => {
console.log(error);
});
})
}
import wixData from 'wix-data';
import { cart } from 'wix-stores';
export function AddToCart_click_1(event) {
let productData = $w('#dynamicDataset').getCurrentItem()
let productId = productData.foodPrice;
// const productRef = productId._id
let quantity = 1
let product = [{
"productId": productId,
"quantity": quantity
}]
$w('#shoppingCartIcon1').addToCart(productId,1)
cart.addProducts(product)
.then((shoppingCartIcon1) => {
//Products added to cart
const cartId = shoppingCartIcon1._id;
const cartLineItems = shoppingCartIcon1.lineItems;
console.log("Product Added")
cart.showMiniCart();
})
.catch((error) => {
console.log(error);
});
}
import wixData from 'wix-data';
import { cart } from 'wix-stores';
import { formFactor } from 'wix-window';
$w.onReady(function () {
let productData = $w('#dynamicDataset').getCurrentItem()
let productId = productData._id
let quantity = 1
let product = [{
"productId": productId,
"quantity": quantity
}]
$w("#AddToCart").onClick( (event) => {
cart.addProducts(product)
.then(()=>{
// const cartId = shoppingCartIcon1._id;
// const cartLineItems = shoppingCartIcon1.lineItems;
// Only show the Mini Cart if the site is not being viewed on mobile
if (formFactor !== "Mobile") {
cart.showMiniCart();
}
})
.catch((error) => {
console.error(error);
});
});
})
import wixData from 'wix-data';
import { cart } from 'wix-stores';
export function AddToCart_click_1(event) {
let product = $w('#dynamicDataset').getCurrentItem();
let idproduct = product.CaribbeAfro_ProductsRegistration;
$w('#shoppingCartIcon1').addToCart(idproduct)
cart.addProducts(idproduct)
.then(()=>{
console.log("Product Added")
cart.showMiniCart();
})
.catch((error)=>{
console.log(console.error);
})
}
All of them failed,