I am trying to pass CMS items into the Wix Cart and am using Velo backend addToCurrentCart to accomplish this. The code I’ve set up is based on the Velo API wix-ecom-backend => currentCart=> addToCurrentCart example. The code for myAddToCurrentCart is below and it allows me to pass the productID (the ID from the CMS which is the catalogItemID), the appId: was received during setup and the options and other parameters are from videoOptions (which documents video segments to purchase), and videoData (which is already available in the lightbox from selecting the video from a dynamic page).
Here’s the code:
export const myAddToCurrentCart = webMethod(
Permissions.Anyone,
async (productId, videoData, videoOptions) => {
console.log("inside myAddToCurrentCart Cart.web videoData is", videoData);
console.log("inside myAddToCurrentCart productId ", productId);
console.log("inside myAddToCurrentCart Cart.web videoOptions is", videoOptions);
const cartOptions = {
options : {
lineItems: [{
catalogReference: {
appId: APP_ID,
catalogItemId: productId,
options: videoOptions,
},
quantity: 1,
price: videoData.videoPrice.toString(),
productName: {
original: videoData.videoTitle,
},
itemType: {
preset: "DIGITAL",
},
media: videoData.videoUrl,
}],
}
};
console.log("myAddToCurrentCart cartOptions :", cartOptions);
try {
const updatedCurrentCart = await currentCart.addToCurrentCart(cartOptions);
console.log("CurrentCart Success! Updated current cart:", updatedCurrentCart);
return updatedCurrentCart;
} catch (error) { // Handle the error
console.log("error adding to cart", error);
}
}
);
This code set up the cartOptions and the console.log for them shows:
myAddToCurrentCart cartOptions : {"options":{"lineItems":[{"catalogReference":{"appId":"d387d173-fb95-48d4-83e6-2b3a871aece6","catalogItemId":"13ef4251-1948-408b-95e8-61b023138952","options":{"startTime1":"10","startTime2":"20","startTime3":"","startTime4":"","endTime1":"15","endTime2":"30","endTime3":"","endTime4":"","segCheckBox":["1","2"],"specInstructions":""}},"quantity":1,"price":"70","productName":{"original":"МЭДЭЭЛЛИЙН ХӨТӨЛБӨР-30 ТУЛГА НААДАМ-1"},"itemType":{"preset":"DIGITAL"},"media":"https://vimeo.com/34987643"}]}}
This said, the line below fails
const updatedCurrentCart = await currentCart.addToCurrentCart(cartOptions);
and I get the error
error adding to cart message: Cant add to cart without items
details:
applicationError:
description: Cant add to cart without items
code: CANT_ADD_TO_CART_WITHOUT_ITEMS
data: {}
Given the console.log and the await…addToCurrentCart(cartOptions); follow each other, I don’t understand why I’m getting the information error (it’s not an “official” error) and is says further that “updated myCurrentCart undefined”.
Any help would be greatly appreciated!
Happy New Years!