I am using eCommerce Catalog Custom Extension to create a new collection of products, called “Itens”.
I already coded frontend and backend scripts, but when the user clicks the button, I have a success log message that item was added to cart, but the cart continues with zero items.
Frontend:
import {addLensToCart} from 'backend/ecom-integration';
let selectedLens;
$w.onReady(function () {
const lensDetailsRepeater = $w('#lensRepeater');
lensDetailsRepeater.onItemReady(($item, itemData, index) => {
$item('#subtitleText').text = itemData.subtitle;
$item('#subtitleText').onClick(() => {
selectedLens = itemData;
console.log(selectedLens);
});
});
$w('#btnAddToCart').onClick(() => {
const item = $w("#dynamicDataset").getCurrentItem();
const lineItem = {
id: item._id,
};
addLensToCart(lineItem.id,);
});
});
Backend:
import { currentCart, cart } from 'wix-ecom-backend';
export async function addLensToCart(lensId) {
const options = {
lineItems: [{
catalogReference: {
appId: "96c81ef5-dbfe-471b-b449-7fb7a1552cd6",
catalogItemId: lensId,
},
quantity: 1,
title: item.title,
price: item.price,
mainMedia: item.image,
description: item.description,
quantityAvailable: 1,
}]
};
const myCart = await currentCart.getCurrentCart();
if (myCart) {
const addToCartIdResponse = await cart.addToCart(myCart._id, options);
console.log("addToCartIdResponse: ", {addToCartIdResponse});
} else {
const createCartResponse = await cart.createCart(options);
console.log("createCartResponse: ", {createCartResponse});
}
}
Any ideas on what could be going wrong?
Tks!