updateLineItemsQuantity( )
Updates the quantity of one or more line items in a specified cart.
Description
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.
Syntax
function updateLineItemsQuantity(_id: string, lineItems: Array<LineItemQuantityUpdate>): Promise<UpdateLineItemsQuantityResponse>
updateLineItemsQuantity Parameters
NAME
TYPE
DESCRIPTION
Cart ID.
Line item IDs and their new quantity.
Returns
Fulfilled - Updated cart.
Return Type:
NAME
TYPE
DESCRIPTION
Updated cart.
Was this helpful?
Update the quantity of a cart's line items
The first line item is updated to a quantity of 2, while the second is updated to a quantity of 3
1/**************************************2 * Backend code - my-backend-file.web.js *3 *************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { cart } from 'wix-ecom-backend';78export const myUpdateLineItemsQuantityFunction = webMethod(Permissions.Anyone, async (cartId, lineItems) => {9 try {10 const updatedCart = await cart.updateLineItemsQuantity(cartId, lineItems);11 console.log('Success! Line item quantities updated:', updatedCart);12 return updatedCart;13 } catch (error) {14 console.error(error);15 // Handle the error16 }17});1819/*************20 * Page code *21 ************/2223import { myUpdateLineItemsQuantityFunction } from 'backend/my-backend-file.web';2425// Sample cartId:26const cartId = 'b79fd177-ec98-4245-b9f6-f09e7afa9d04';2728// Sample lineItems array:29const lineItems = [30 {31 "_id": '00000000-0000-0000-0000-000000000001',32 "quantity": 233 },34 {35 "_id": '00000000-0000-0000-0000-000000000002',36 "quantity": 337 }38]3940myUpdateLineItemsQuantityFunction(cartId, lineItems)41 .then((updatedCart) => {42 const firstItemQuantity = updatedCart[0].quantity;43 const secondItemQuantity = updatedCart[1].quantity;44 const numberOfCartItems = updatedCart.lineItems.length;4546 console.log('Success! Line item quantities updated:', updatedCart);47 return updatedCart;48 })49 .catch((error) => {50 console.error(error);51 // Handle the error52 });5354/* Promise resolves to:55 *56 * {57 * "_id": "b79fd177-ec98-4245-b9f6-f09e7afa9d04",58 * "lineItems": [59 * {60 * "_id": "00000000-0000-0000-0000-000000000001",61 * "quantity": 2,62 * "catalogReference": {63 * "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e",64 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",65 * "options": {66 * "variantId": "e62fee23-7878-437a-bf0e-292f17d11cb5"67 * }68 * },69 * "productName": {70 * "original": "Shoe",71 * "translated": "Shoe"72 * },73 * "url": "https://example.wixsite.com",74 * "price": {75 * "amount": "85",76 * "convertedAmount": "85",77 * "formattedAmount": "€85.00",78 * "formattedConvertedAmount": "€85.00"79 * },80 * "fullPrice": {81 * "amount": "85",82 * "convertedAmount": "85",83 * "formattedAmount": "€85.00",84 * "formattedConvertedAmount": "€85.00"85 * },86 * "priceBeforeDiscounts": {87 * "amount": "85",88 * "convertedAmount": "85",89 * "formattedAmount": "€85.00",90 * "formattedConvertedAmount": "€85.00"91 * },92 * "descriptionLines": [93 * {94 * "name": {95 * "original": "Color",96 * "translated": "Color"97 * },98 * "colorInfo": {99 * "original": "Black",100 * "translated": "Black",101 * "code": "#000"102 * },103 * "lineType": "UNRECOGNISED"104 * }105 * ],106 * "image": "wix:image://v1/3c76e2_bf235c38610f4d2a905db71095b351cf~mv2.jpg#originWidth=1000&originHeight=1000",107 * "availability": {108 * "status": "AVAILABLE",109 * "quantityAvailable": 30110 * },111 * "physicalProperties": {112 * "sku": "364215376135191",113 * "shippable": true114 * },115 * "couponScopes": [116 * {117 * "namespace": "stores",118 * "group": {119 * "name": "collection",120 * "entityId": "00000000-000000-000000-000000000001"121 * }122 * },123 * {124 * "namespace": "stores",125 * "group": {126 * "name": "product",127 * "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"128 * }129 * }130 * ],131 * "itemType": {132 * "preset": "PHYSICAL"133 * },134 * "paymentOption": "FULL_PAYMENT_ONLINE"135 * },136 * {137 * "_id": "00000000-0000-0000-0000-000000000002",138 * "quantity": 3,139 * "catalogReference": {140 * "catalogItemId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",141 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",142 * "options": {143 * "variantId": "132b84e8-aab8-47a1-a1f6-2c47557b64a4"144 * }145 * },146 * "productName": {147 * "original": "Watch",148 * "translated": "Watch"149 * },150 * "url": "https://example.wixsite.com",151 * "price": {152 * "amount": "30",153 * "convertedAmount": "30",154 * "formattedAmount": "€30.00",155 * "formattedConvertedAmount": "€30.00"156 * },157 * "fullPrice": {158 * "amount": "30",159 * "convertedAmount": "30",160 * "formattedAmount": "€30.00",161 * "formattedConvertedAmount": "€30.00"162 * },163 * "priceBeforeDiscounts": {164 * "amount": "30",165 * "convertedAmount": "30",166 * "formattedAmount": "€30.00",167 * "formattedConvertedAmount": "€30.00"168 * },169 * "descriptionLines": [170 * {171 * "name": {172 * "original": "Size",173 * "translated": "Size"174 * },175 * "plainText": {176 * "original": "Medium",177 * "translated": "Medium"178 * },179 * "lineType": "UNRECOGNISED"180 * },181 * {182 * "name": {183 * "original": "Color",184 * "translated": "Color"185 * },186 * "colorInfo": {187 * "original": "Grey",188 * "translated": "Grey",189 * "code": "rgb(128, 128, 128)"190 * },191 * "lineType": "UNRECOGNISED"192 * }193 * ],194 * "image": "wix:image://v1/3c76e2_8891bbe3372a428aac976ac59aa0ac74~mv2.jpg#originWidth=1000&originHeight=1000",195 * "availability": {196 * "status": "AVAILABLE"197 * },198 * "physicalProperties": {199 * "sku": "217537123517253",200 * "shippable": true201 * },202 * "couponScopes": [203 * {204 * "namespace": "stores",205 * "group": {206 * "name": "collection",207 * "entityId": "00000000-000000-000000-000000000001"208 * }209 * },210 * {211 * "namespace": "stores",212 * "group": {213 * "name": "product",214 * "entityId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09"215 * }216 * }217 * ],218 * "itemType": {219 * "preset": "PHYSICAL"220 * },221 * "paymentOption": "FULL_PAYMENT_ONLINE"222 * }223 * ],224 * "buyerInfo": {225 * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7"226 * },227 * "currency": "EUR",228 * "conversionCurrency": "EUR",229 * "buyerLanguage": "en",230 * "siteLanguage": "en",231 * "taxIncludedInPrices": false,232 * "weightUnit": "KG",233 * "subtotal": {234 * "amount": "260",235 * "convertedAmount": "260",236 * "formattedAmount": "€260.00",237 * "formattedConvertedAmount": "€260.00"238 * },239 * "appliedDiscounts": [],240 * "inSync": false,241 * "_createdDate": "2022-06-22T11:32:29.601Z",242 * "_updatedDate": "2022-06-22T11:36:48.831Z"243 * }244 *245 */