I have just started working on current cart. Below is the basic backend code I’ve written for adding a product to currentCart.
export async function addToCurrentCart(options) {
try {
const updatedcart = await currentCart.addToCurrentCart(options);
console.log("updated cart - ", updatedcart);
return updatedcart;
} catch (error) {
console.log(error);
}
}
And this is the front-end code i’ve written for when the user clicks on add to cart.
export function productAddToBag_click(event) {
const options = {
lineItems: [{
catalogReference: {
appId: appId,
catalogItemId: currentItem._id,
options: {
variantId: currentItem.sku
}
},
quantity: 1
}]
}
addToCurrentCart(options)
.then((updatedCart) => {
console.log(updatedCart);
const cartId = updatedCart._id;
const numberOfCartLineItems = updatedCart.lineItems.length;
console.log("updated cart - ", cartId, numberOfCartLineItems);
})
.catch((error) => {
console.log(error);
})
}
when i run this code, I get error in Logs console in dashboard.
"root":{
"insertId":"..........5YVP7CHZ_6QObm638OgKDI"
"timestamp":"2023-02-08T20:27:04.423Z"
"labels":{"siteUrl":"n/a"
"revision":"1102"
"namespace":"Velo"
"tenantId":"31c27d41-00ca-4a3d-8f8f-2184e503131c"
"viewMode":"Site"
}
"sourceLocation":{"file":"backend/cart.jsw"
"line":21
"column":16
}
"operation":{"id":"1675888021.73335377735126223"
"producer":"backend"
}
"jsonPayload":{"message":"["message: 'INVALID_ARGUMENT: \"options.lineItems[0].catalogReference.appId\" has size 0, expected 1 or more'\ndetails:\n validationError:\n fieldViolations:\n - field: options.lineItems[0].catalogReference.appId\n description: has size 0, expected 1 or more\n violatedRule: MIN_LENGTH\n data:\n threshold: 1"]"
}
"receiveTimestamp":"2023-02-08T20:27:04.926Z"
}
It says invalid argument and pretty obvious that there’s a problem with appId. Can someone guide me? What to provide in appId?