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