Hello all,
I am writing a velo code in wixStudio’s Cart Page that will populate item repeaters from my custom catalog. I have created an add and subtract buttons in the Cart Page, that will increment or decrement the quantity in the line items. To achieve that, I have created a backend function called changeItemQuantity
. The backend function file getCart.web.js, that contains the function, looks like this:
import { Permissions, webMethod } from "wix-web-module";
import { currentCart } from "wix-ecom-backend";
export async function changeItemQuantity(lineItem) {
const updatedLineItems = await currentCart.updateCurrentCartLineItemQuantity([lineItem]);
return updatedLineItems;
}
I am calling this function inside an event listener, so that every time the addQuantityButton is clicked the quantity in the line items should increment by one. Below is the code where the changeItemQuantity
gets called:
import {getCart, changeItemQuantity} from 'backend/getCart.web';
$w.onReady(function () {
populateCartItems()
});
async function populateCartItems() {
const cart = await getCart()
const {lineItems} = cart
console.log("Line Items=",lineItems)
$w("#lineItemsRepeater").onItemReady(($item,itemData)=>{
console.log("ItemData=",itemData)
$item("#imageTitleText").text = itemData.productName.original
$item("#printImage").src = itemData.image
$item("#unitPriceText").text = itemData.price.formattedAmount
$item("#quantityDisplayText").value = itemData.quantity.toString()
$item("#printOptionsText").text = getProductOptions(itemData)
$item("#addQuantityButton").onClick(async()=>{
const {_id, quantity} = itemData;
console.log("_id=",_id)
const updatedQuantity = quantity + 1;
console.log("Updated quantity=",updatedQuantity)
const updatedLineItems = await changeItemQuantity({
_id,
quantity: updatedQuantity,})
console.log("updatedLineItems=", updatedLineItems)
})
});
$w('#lineItemsRepeater').data = lineItems
}
function getProductOptions(product) {
const options = product.catalogReference.options
console.log("Options are = ",product.catalogReference.options)
const keys = Object.keys(options)
console.log("Keys =",keys)
let optionsText = ""
for (let i=0; i<keys.length; i++){
optionsText = optionsText+`${keys[i]}: ${options[keys[i]]}\n`
}
console.log("OptionsText=",optionsText)
return optionsText
}
However, upon publishing the website and using the + button in my cart, I get the following error message: "TypeError: (0,t.changeItemQuantity) is not a function. (In '(0,t.changeItemQuantity)({_id:o,quantity:a})', '(0,t.changeItemQuantity)' is undefined)"
Anyone has an insight what that might mean? The code runs normally until the line
const updatedLineItems = await changeItemQuantity({
_id,
quantity: updatedQuantity,})
Your help will be very much appreciated.