Updates the quantity of one or more line items in a specified cart.
The updateLineItemsQuantity()
function returns a Promise that resolves when the quantities of the specified cart's line items are updated.
This endpoint is only for updating the quantity of line items. To entirely remove a line item from the cart, use removeLineItems()
. To add a new line item to the cart, use addToCart()
.
This endpoint checks the amount of stock remaining for this line item. If the specified quantity
is greater than the remaining stock, then the quantity
returned in the response is the total amount of remaining stock.
function updateLineItemsQuantity(
_id: string,
lineItems: Array<LineItemQuantityUpdate>,
): Promise<UpdateLineItemsQuantityResponse>;
Cart ID.
Line item IDs and their new quantity.
The first line item is updated to a quantity of 2, while the second is updated to a quantity of 3
/**************************************
* Backend code - my-backend-file.web.js *
*************************************/
import { Permissions, webMethod } from "wix-web-module";
import { cart } from "wix-ecom-backend";
export const myUpdateLineItemsQuantityFunction = webMethod(
Permissions.Anyone,
async (cartId, lineItems) => {
try {
const updatedCart = await cart.updateLineItemsQuantity(cartId, lineItems);
console.log("Success! Line item quantities updated:", updatedCart);
return updatedCart;
} catch (error) {
console.error(error);
// Handle the error
}
},
);
/*************
* Page code *
************/
import { myUpdateLineItemsQuantityFunction } from "backend/my-backend-file.web";
// Sample cartId:
const cartId = "b79fd177-ec98-4245-b9f6-f09e7afa9d04";
// Sample lineItems array:
const lineItems = [
{
_id: "00000000-0000-0000-0000-000000000001",
quantity: 2,
},
{
_id: "00000000-0000-0000-0000-000000000002",
quantity: 3,
},
];
myUpdateLineItemsQuantityFunction(cartId, lineItems)
.then((updatedCart) => {
const firstItemQuantity = updatedCart[0].quantity;
const secondItemQuantity = updatedCart[1].quantity;
const numberOfCartItems = updatedCart.lineItems.length;
console.log("Success! Line item quantities updated:", updatedCart);
return updatedCart;
})
.catch((error) => {
console.error(error);
// Handle the error
});
/* Promise resolves to:
*
* {
* "_id": "b79fd177-ec98-4245-b9f6-f09e7afa9d04",
* "lineItems": [
* {
* "_id": "00000000-0000-0000-0000-000000000001",
* "quantity": 2,
* "catalogReference": {
* "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e",
* "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",
* "options": {
* "variantId": "e62fee23-7878-437a-bf0e-292f17d11cb5"
* }
* },
* "productName": {
* "original": "Shoe",
* "translated": "Shoe"
* },
* "url": "https://example.wixsite.com",
* "price": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "€85.00",
* "formattedConvertedAmount": "€85.00"
* },
* "fullPrice": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "€85.00",
* "formattedConvertedAmount": "€85.00"
* },
* "priceBeforeDiscounts": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "€85.00",
* "formattedConvertedAmount": "€85.00"
* },
* "descriptionLines": [
* {
* "name": {
* "original": "Color",
* "translated": "Color"
* },
* "colorInfo": {
* "original": "Black",
* "translated": "Black",
* "code": "#000"
* },
* "lineType": "UNRECOGNISED"
* }
* ],
* "image": "wix:image://v1/3c76e2_bf235c38610f4d2a905db71095b351cf~mv2.jpg#originWidth=1000&originHeight=1000",
* "availability": {
* "status": "AVAILABLE",
* "quantityAvailable": 30
* },
* "physicalProperties": {
* "sku": "364215376135191",
* "shippable": true
* },
* "couponScopes": [
* {
* "namespace": "stores",
* "group": {
* "name": "collection",
* "entityId": "00000000-000000-000000-000000000001"
* }
* },
* {
* "namespace": "stores",
* "group": {
* "name": "product",
* "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"
* }
* }
* ],
* "itemType": {
* "preset": "PHYSICAL"
* },
* "paymentOption": "FULL_PAYMENT_ONLINE"
* },
* {
* "_id": "00000000-0000-0000-0000-000000000002",
* "quantity": 3,
* "catalogReference": {
* "catalogItemId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
* "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",
* "options": {
* "variantId": "132b84e8-aab8-47a1-a1f6-2c47557b64a4"
* }
* },
* "productName": {
* "original": "Watch",
* "translated": "Watch"
* },
* "url": "https://example.wixsite.com",
* "price": {
* "amount": "30",
* "convertedAmount": "30",
* "formattedAmount": "€30.00",
* "formattedConvertedAmount": "€30.00"
* },
* "fullPrice": {
* "amount": "30",
* "convertedAmount": "30",
* "formattedAmount": "€30.00",
* "formattedConvertedAmount": "€30.00"
* },
* "priceBeforeDiscounts": {
* "amount": "30",
* "convertedAmount": "30",
* "formattedAmount": "€30.00",
* "formattedConvertedAmount": "€30.00"
* },
* "descriptionLines": [
* {
* "name": {
* "original": "Size",
* "translated": "Size"
* },
* "plainText": {
* "original": "Medium",
* "translated": "Medium"
* },
* "lineType": "UNRECOGNISED"
* },
* {
* "name": {
* "original": "Color",
* "translated": "Color"
* },
* "colorInfo": {
* "original": "Grey",
* "translated": "Grey",
* "code": "rgb(128, 128, 128)"
* },
* "lineType": "UNRECOGNISED"
* }
* ],
* "image": "wix:image://v1/3c76e2_8891bbe3372a428aac976ac59aa0ac74~mv2.jpg#originWidth=1000&originHeight=1000",
* "availability": {
* "status": "AVAILABLE"
* },
* "physicalProperties": {
* "sku": "217537123517253",
* "shippable": true
* },
* "couponScopes": [
* {
* "namespace": "stores",
* "group": {
* "name": "collection",
* "entityId": "00000000-000000-000000-000000000001"
* }
* },
* {
* "namespace": "stores",
* "group": {
* "name": "product",
* "entityId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09"
* }
* }
* ],
* "itemType": {
* "preset": "PHYSICAL"
* },
* "paymentOption": "FULL_PAYMENT_ONLINE"
* }
* ],
* "buyerInfo": {
* "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7"
* },
* "currency": "EUR",
* "conversionCurrency": "EUR",
* "buyerLanguage": "en",
* "siteLanguage": "en",
* "taxIncludedInPrices": false,
* "weightUnit": "KG",
* "subtotal": {
* "amount": "260",
* "convertedAmount": "260",
* "formattedAmount": "€260.00",
* "formattedConvertedAmount": "€260.00"
* },
* "appliedDiscounts": [],
* "inSync": false,
* "_createdDate": "2022-06-22T11:32:29.601Z",
* "_updatedDate": "2022-06-22T11:36:48.831Z"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.