Search...
updateLineItemsQuantity( )
Updates the quantity of one or more line items in a checkout.
Description
This endpoint is only for updating the quantity of line items. To entirely remove a line item from
the checkout, use removeLineItems()
.
To add a new line item to the checkout, use addToCheckout()
.
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
_id
string
Checkout ID.
lineItems
Array<
LineItemQuantityUpdate
>Line item info to update.
Returns
Return Type:
Promise<
UpdateLineItemsQuantityResponse
>NAME
TYPE
DESCRIPTION
checkout
Checkout
Updated checkout.
Was this helpful?
Update the quantity of line items in a checkout
Copy Code
1import { checkout } from 'wix-ecom-backend';23/* Sample checkoutId value: '21fe558e-21a0-4cff-a49b-a4ccb0f7414d'4 *5 * Sample listItems value:6 * {7 * _id: '00000000-0000-0000-0000-000000000001',8 * quantity: 109 * }10 */1112export async function myUpdateQuantityFunction(checkoutId, lineItems) {13 try {14 const updatedCheckout = await checkout.updateLineItemsQuantity(checkoutId, lineItems);1516 const firstUpdatedLineItem = updatedCheckout.checkout.lineItems[0];17 const updatedQuantity = firstUpdatedLineItem.quantity;1819 console.log('Success! The updated quantity for the first line item is:', updatedQuantity);20 return updatedCheckout;21 } catch (error) {22 console.error(error);23 }24}2526/* Promise resolves to:27 * {28 * "checkout": {29 * "_id": "21fe558e-21a0-4cff-a49b-a4ccb0f7414d",30 * "lineItems": [31 * {32 * "_id": "00000000-0000-0000-0000-000000000001",33 * "quantity": 10,34 * "catalogReference": {35 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",36 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"37 * },38 * "productName": {39 * "original": "Shirt",40 * "translated": "Shirt"41 * },42 * "url": "https://example.wixsite.com/product-page/shirt",43 * "price": {44 * "amount": "10",45 * "convertedAmount": "10",46 * "formattedAmount": "$10.00",47 * "formattedConvertedAmount": "$10.00"48 * },49 * "lineItemPrice": {50 * "amount": "100",51 * "convertedAmount": "100",52 * "formattedAmount": "$100.00",53 * "formattedConvertedAmount": "$100.00"54 * },55 * "fullPrice": {56 * "amount": "10",57 * "convertedAmount": "10",58 * "formattedAmount": "$10.00",59 * "formattedConvertedAmount": "$10.00"60 * },61 * "priceBeforeDiscounts": {62 * "amount": "10",63 * "convertedAmount": "10",64 * "formattedAmount": "$10.00",65 * "formattedConvertedAmount": "$10.00"66 * },67 * "totalPriceAfterTax": {68 * "amount": "100",69 * "convertedAmount": "100",70 * "formattedAmount": "$100.00",71 * "formattedConvertedAmount": "$100.00"72 * },73 * "totalPriceBeforeTax": {74 * "amount": "100",75 * "convertedAmount": "100",76 * "formattedAmount": "$100.00",77 * "formattedConvertedAmount": "$100.00"78 * },79 * "taxDetails": {80 * "taxableAmount": {81 * "amount": "100",82 * "convertedAmount": "100",83 * "formattedAmount": "$100.00",84 * "formattedConvertedAmount": "$100.00"85 * },86 * "taxRate": "0",87 * "totalTax": {88 * "amount": "0",89 * "convertedAmount": "0",90 * "formattedAmount": "$0.00",91 * "formattedConvertedAmount": "$0.00"92 * },93 * "rateBreakdown": []94 * },95 * "discount": {96 * "amount": "0",97 * "convertedAmount": "0",98 * "formattedAmount": "$0.00",99 * "formattedConvertedAmount": "$0.00"100 * },101 * "descriptionLines": [],102 * "media": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",103 * "availability": {104 * "status": "AVAILABLE"105 * },106 * "physicalProperties": {107 * "sku": "364115376135191",108 * "shippable": true109 * },110 * "couponScopes": [111 * {112 * "namespace": "stores",113 * "group": {114 * "name": "collection",115 * "entityId": "00000000-000000-000000-000000000001"116 * }117 * },118 * {119 * "namespace": "stores",120 * "group": {121 * "name": "product",122 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"123 * }124 * }125 * ],126 * "itemType": {127 * "preset": "PHYSICAL"128 * },129 * "paymentOption": "FULL_PAYMENT_ONLINE",130 * "rootCatalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a"131 * }132 * ],133 * "shippingInfo": {134 * "carrierServiceOptions": []135 * },136 * "buyerNote": "Updated note.",137 * "buyerInfo": {138 * "contactId": "a4bc8d90-a91b-467f-a775-77d65dd0442e",139 * "email": "testing3@example.com",140 * "memberId": "ea3d74df-b7dc-4ca1-a7c9-c416b9017a86"141 * },142 * "conversionCurrency": "USD",143 * "priceSummary": {144 * "subtotal": {145 * "amount": "100",146 * "convertedAmount": "100",147 * "formattedAmount": "$100.00",148 * "formattedConvertedAmount": "$100.00"149 * },150 * "shipping": {151 * "amount": "0",152 * "convertedAmount": "0",153 * "formattedAmount": "$0.00",154 * "formattedConvertedAmount": "$0.00"155 * },156 * "tax": {157 * "amount": "0",158 * "convertedAmount": "0",159 * "formattedAmount": "$0.00",160 * "formattedConvertedAmount": "$0.00"161 * },162 * "discount": {163 * "amount": "0",164 * "convertedAmount": "0",165 * "formattedAmount": "$0.00",166 * "formattedConvertedAmount": "$0.00"167 * },168 * "total": {169 * "amount": "100",170 * "convertedAmount": "100",171 * "formattedAmount": "$100.00",172 * "formattedConvertedAmount": "$100.00"173 * },174 * "additionalFees": {175 * "amount": "0",176 * "convertedAmount": "0",177 * "formattedAmount": "$0.00",178 * "formattedConvertedAmount": "$0.00"179 * }180 * },181 * "calculationErrors": {182 * "orderValidationErrors": []183 * },184 * "appliedDiscounts": [],185 * "customFields": [],186 * "weightUnit": "LB",187 * "currency": "USD",188 * "channelType": "WEB",189 * "siteLanguage": "en",190 * "buyerLanguage": "en",191 * "completed": false,192 * "taxIncludedInPrice": false,193 * "createdBy": {194 * "memberId": "ea3d74df-b7dc-4ca1-a7c9-c416b9017a86"195 * },196 * "_createdDate": "2023-02-22T15:49:04.627Z",197 * "_updatedDate": "2023-04-30T05:51:13.309Z",198 * "payNow": {199 * "subtotal": {200 * "amount": "100",201 * "convertedAmount": "100",202 * "formattedAmount": "$100.00",203 * "formattedConvertedAmount": "$100.00"204 * },205 * "shipping": {206 * "amount": "0",207 * "convertedAmount": "0",208 * "formattedAmount": "$0.00",209 * "formattedConvertedAmount": "$0.00"210 * },211 * "tax": {212 * "amount": "0",213 * "convertedAmount": "0",214 * "formattedAmount": "$0.00",215 * "formattedConvertedAmount": "$0.00"216 * },217 * "discount": {218 * "amount": "0",219 * "convertedAmount": "0",220 * "formattedAmount": "$0.00",221 * "formattedConvertedAmount": "$0.00"222 * },223 * "total": {224 * "amount": "100",225 * "convertedAmount": "100",226 * "formattedAmount": "$100.00",227 * "formattedConvertedAmount": "$100.00"228 * },229 * "additionalFees": {230 * "amount": "0",231 * "convertedAmount": "0",232 * "formattedAmount": "$0.00",233 * "formattedConvertedAmount": "$0.00"234 * }235 * },236 * "payLater": {237 * "subtotal": {238 * "amount": "0",239 * "convertedAmount": "0",240 * "formattedAmount": "$0.00",241 * "formattedConvertedAmount": "$0.00"242 * },243 * "shipping": {244 * "amount": "0",245 * "convertedAmount": "0",246 * "formattedAmount": "$0.00",247 * "formattedConvertedAmount": "$0.00"248 * },249 * "tax": {250 * "amount": "0",251 * "convertedAmount": "0",252 * "formattedAmount": "$0.00",253 * "formattedConvertedAmount": "$0.00"254 * },255 * "discount": {256 * "amount": "0",257 * "convertedAmount": "0",258 * "formattedAmount": "$0.00",259 * "formattedConvertedAmount": "$0.00"260 * },261 * "total": {262 * "amount": "0",263 * "convertedAmount": "0",264 * "formattedAmount": "$0.00",265 * "formattedConvertedAmount": "$0.00"266 * },267 * "additionalFees": {268 * "amount": "0",269 * "convertedAmount": "0",270 * "formattedAmount": "$0.00",271 * "formattedConvertedAmount": "$0.00"272 * }273 * },274 * "membershipOptions": {275 * "eligibleMemberships": [],276 * "invalidMemberships": [],277 * "selectedMemberships": {278 * "memberships": []279 * }280 * },281 * "additionalFees": [],282 * "payNowTotalAfterGiftCard": {283 * "amount": "100",284 * "convertedAmount": "100",285 * "formattedAmount": "$100.00",286 * "formattedConvertedAmount": "$100.00"287 * }288 * }289 * }290 */291
Update the quantity of line items in a checkout (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { checkout } from 'wix-ecom-backend';34/* Sample checkoutId value: '21fe558e-21a0-4cff-a49b-a4ccb0f7414d'5 *6 * Sample listItems value:7 * {8 * _id: '00000000-0000-0000-0000-000000000001',9 * quantity: 1010 * }11 */1213export const myUpdateQuantityFunction = webMethod(Permissions.Anyone, async (checkoutId, lineItems) => {14 try {15 const updatedCheckout = await checkout.updateLineItemsQuantity(checkoutId, lineItems);1617 const firstUpdatedLineItem = updatedCheckout.checkout.lineItems[0];18 const updatedQuantity = firstUpdatedLineItem.quantity;1920 console.log('Success! The updated quantity for the first line item is:', updatedQuantity);21 return updatedCheckout;22 } catch (error) {23 console.error(error);24 }25});2627/* Promise resolves to:28 * {29 * "checkout": {30 * "_id": "21fe558e-21a0-4cff-a49b-a4ccb0f7414d",31 * "lineItems": [32 * {33 * "_id": "00000000-0000-0000-0000-000000000001",34 * "quantity": 10,35 * "catalogReference": {36 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",37 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"38 * },39 * "productName": {40 * "original": "Shirt",41 * "translated": "Shirt"42 * },43 * "url": "https://example.wixsite.com/product-page/shirt",44 * "price": {45 * "amount": "10",46 * "convertedAmount": "10",47 * "formattedAmount": "$10.00",48 * "formattedConvertedAmount": "$10.00"49 * },50 * "lineItemPrice": {51 * "amount": "100",52 * "convertedAmount": "100",53 * "formattedAmount": "$100.00",54 * "formattedConvertedAmount": "$100.00"55 * },56 * "fullPrice": {57 * "amount": "10",58 * "convertedAmount": "10",59 * "formattedAmount": "$10.00",60 * "formattedConvertedAmount": "$10.00"61 * },62 * "priceBeforeDiscounts": {63 * "amount": "10",64 * "convertedAmount": "10",65 * "formattedAmount": "$10.00",66 * "formattedConvertedAmount": "$10.00"67 * },68 * "totalPriceAfterTax": {69 * "amount": "100",70 * "convertedAmount": "100",71 * "formattedAmount": "$100.00",72 * "formattedConvertedAmount": "$100.00"73 * },74 * "totalPriceBeforeTax": {75 * "amount": "100",76 * "convertedAmount": "100",77 * "formattedAmount": "$100.00",78 * "formattedConvertedAmount": "$100.00"79 * },80 * "taxDetails": {81 * "taxableAmount": {82 * "amount": "100",83 * "convertedAmount": "100",84 * "formattedAmount": "$100.00",85 * "formattedConvertedAmount": "$100.00"86 * },87 * "taxRate": "0",88 * "totalTax": {89 * "amount": "0",90 * "convertedAmount": "0",91 * "formattedAmount": "$0.00",92 * "formattedConvertedAmount": "$0.00"93 * },94 * "rateBreakdown": []95 * },96 * "discount": {97 * "amount": "0",98 * "convertedAmount": "0",99 * "formattedAmount": "$0.00",100 * "formattedConvertedAmount": "$0.00"101 * },102 * "descriptionLines": [],103 * "media": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",104 * "availability": {105 * "status": "AVAILABLE"106 * },107 * "physicalProperties": {108 * "sku": "364115376135191",109 * "shippable": true110 * },111 * "couponScopes": [112 * {113 * "namespace": "stores",114 * "group": {115 * "name": "collection",116 * "entityId": "00000000-000000-000000-000000000001"117 * }118 * },119 * {120 * "namespace": "stores",121 * "group": {122 * "name": "product",123 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"124 * }125 * }126 * ],127 * "itemType": {128 * "preset": "PHYSICAL"129 * },130 * "paymentOption": "FULL_PAYMENT_ONLINE",131 * "rootCatalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a"132 * }133 * ],134 * "shippingInfo": {135 * "carrierServiceOptions": []136 * },137 * "buyerNote": "Updated note.",138 * "buyerInfo": {139 * "contactId": "a4bc8d90-a91b-467f-a775-77d65dd0442e",140 * "email": "testing3@example.com",141 * "memberId": "ea3d74df-b7dc-4ca1-a7c9-c416b9017a86"142 * },143 * "conversionCurrency": "USD",144 * "priceSummary": {145 * "subtotal": {146 * "amount": "100",147 * "convertedAmount": "100",148 * "formattedAmount": "$100.00",149 * "formattedConvertedAmount": "$100.00"150 * },151 * "shipping": {152 * "amount": "0",153 * "convertedAmount": "0",154 * "formattedAmount": "$0.00",155 * "formattedConvertedAmount": "$0.00"156 * },157 * "tax": {158 * "amount": "0",159 * "convertedAmount": "0",160 * "formattedAmount": "$0.00",161 * "formattedConvertedAmount": "$0.00"162 * },163 * "discount": {164 * "amount": "0",165 * "convertedAmount": "0",166 * "formattedAmount": "$0.00",167 * "formattedConvertedAmount": "$0.00"168 * },169 * "total": {170 * "amount": "100",171 * "convertedAmount": "100",172 * "formattedAmount": "$100.00",173 * "formattedConvertedAmount": "$100.00"174 * },175 * "additionalFees": {176 * "amount": "0",177 * "convertedAmount": "0",178 * "formattedAmount": "$0.00",179 * "formattedConvertedAmount": "$0.00"180 * }181 * },182 * "calculationErrors": {183 * "orderValidationErrors": []184 * },185 * "appliedDiscounts": [],186 * "customFields": [],187 * "weightUnit": "LB",188 * "currency": "USD",189 * "channelType": "WEB",190 * "siteLanguage": "en",191 * "buyerLanguage": "en",192 * "completed": false,193 * "taxIncludedInPrice": false,194 * "createdBy": {195 * "memberId": "ea3d74df-b7dc-4ca1-a7c9-c416b9017a86"196 * },197 * "_createdDate": "2023-02-22T15:49:04.627Z",198 * "_updatedDate": "2023-04-30T05:51:13.309Z",199 * "payNow": {200 * "subtotal": {201 * "amount": "100",202 * "convertedAmount": "100",203 * "formattedAmount": "$100.00",204 * "formattedConvertedAmount": "$100.00"205 * },206 * "shipping": {207 * "amount": "0",208 * "convertedAmount": "0",209 * "formattedAmount": "$0.00",210 * "formattedConvertedAmount": "$0.00"211 * },212 * "tax": {213 * "amount": "0",214 * "convertedAmount": "0",215 * "formattedAmount": "$0.00",216 * "formattedConvertedAmount": "$0.00"217 * },218 * "discount": {219 * "amount": "0",220 * "convertedAmount": "0",221 * "formattedAmount": "$0.00",222 * "formattedConvertedAmount": "$0.00"223 * },224 * "total": {225 * "amount": "100",226 * "convertedAmount": "100",227 * "formattedAmount": "$100.00",228 * "formattedConvertedAmount": "$100.00"229 * },230 * "additionalFees": {231 * "amount": "0",232 * "convertedAmount": "0",233 * "formattedAmount": "$0.00",234 * "formattedConvertedAmount": "$0.00"235 * }236 * },237 * "payLater": {238 * "subtotal": {239 * "amount": "0",240 * "convertedAmount": "0",241 * "formattedAmount": "$0.00",242 * "formattedConvertedAmount": "$0.00"243 * },244 * "shipping": {245 * "amount": "0",246 * "convertedAmount": "0",247 * "formattedAmount": "$0.00",248 * "formattedConvertedAmount": "$0.00"249 * },250 * "tax": {251 * "amount": "0",252 * "convertedAmount": "0",253 * "formattedAmount": "$0.00",254 * "formattedConvertedAmount": "$0.00"255 * },256 * "discount": {257 * "amount": "0",258 * "convertedAmount": "0",259 * "formattedAmount": "$0.00",260 * "formattedConvertedAmount": "$0.00"261 * },262 * "total": {263 * "amount": "0",264 * "convertedAmount": "0",265 * "formattedAmount": "$0.00",266 * "formattedConvertedAmount": "$0.00"267 * },268 * "additionalFees": {269 * "amount": "0",270 * "convertedAmount": "0",271 * "formattedAmount": "$0.00",272 * "formattedConvertedAmount": "$0.00"273 * }274 * },275 * "membershipOptions": {276 * "eligibleMemberships": [],277 * "invalidMemberships": [],278 * "selectedMemberships": {279 * "memberships": []280 * }281 * },282 * "additionalFees": [],283 * "payNowTotalAfterGiftCard": {284 * "amount": "100",285 * "convertedAmount": "100",286 * "formattedAmount": "$100.00",287 * "formattedConvertedAmount": "$100.00"288 * }289 * }290 * }291 */292