Search.../

updateCurrentCartLineItemQuantity( )

Updates the quantity of one or more line items in the current site visitor's cart.

Description

The updateCurrentCartLineItemQuantity() function returns a Promise that resolves when the quantities of the current 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 current cart, use removeLineItemsFromCurrentCart(). To add a new line item to the current cart, use addToCurrentCart().

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 updateCurrentCartLineItemQuantity(lineItems: Array<LineItemQuantityUpdate>): Promise<UpdateLineItemsQuantityResponse>

updateCurrentCartLineItemQuantity Parameters

NAME
TYPE
DESCRIPTION
lineItems
Array<
LineItemQuantityUpdate
>

Line item IDs and their new quantity.

Returns

Fulfilled - The updated current cart.

Return Type:

Promise<
UpdateLineItemsQuantityResponse
>
NAME
TYPE
DESCRIPTION
cart
Cart

Updated cart.

Was this helpful?

Update the quantity of the current 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

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