updateLineItemQuantity( )
Updates the quantity of a specified line item in the cart.
Description
The updateLineItemQuantity()
function returns a Promise that resolves to the current
site visitor's cart when the specified line item's quantity has been updated.
Note: When editing a site as a contributor,
updateLineItemQuantity()
will only work when viewing the live site.
Syntax
function updateLineItemQuantity(cartLineItemId: number, quantity: number): Promise<CartObj>
updateLineItemQuantity Parameters
NAME
TYPE
DESCRIPTION
ID of the cart line item to update.
Line item's new quantity.
Returns
Fulfilled - The updated cart.
Return Type:
NAME
TYPE
DESCRIPTION
Unique identifier of the shopping cart.
Coupon applied in the shopping cart.
Cart billing address.
The buyer's information.
Cart status. Either "INCOMPLETE"
or "COMPLETE"
.
Currency of the shopping cart.
The shopping cart's shipping information.
Items in the shopping cart.
The shopping cart's totals.
The order's units of weight. One of: "KG"
, "LB"
, or "UNSPECIFIED_WEIGHT_UNIT"
.
Was this helpful?
Update the quantity of a cart's line item
1import { cart } from 'wix-stores-frontend';23const cartLineItemId = 2;4const quantity = 10;56cart.updateLineItemQuantity(cartLineItemId, quantity)7 .then((updatedCart) => {8 // Cart line item's quantity updated9 const cartId = updatedCart._id;10 const updatedLineItems = updatedCart.lineItems;11 })12 .catch((error) => {13 // Cart line item's quantity not updated14 console.log(error);15 })161718/* Example of returned updatedCart object:19*20* {21* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",22* "appliedCoupon": {23* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",24* "name": "Summer Sale",25* "code": "SummerSale",26* "discountValue": "$10.00",27* "couponType": "MoneyOff"28* },29* "billingAddress": {30* "firstName": "John",31* "lastName": "Doe",32* "email":"john.doe@somedomain.com",33* "phone":"5555555",34* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"35* },36* "buyerNote": "This is a note from the buyer.",37* "buyerInfo":{38* "firstName": "John",39* "lastName": "Doe",40* "email": "john.doe@somedomain.com",41* "phone": "5555555555",42* "identityType": "CONTACT"43* },44* "status": "INCOMPLETE",45* "currency": {46* "code": "USD",47* "symbol": "$"48* },49* "shippingInfo": {50* "deliveryOption": "Free Shipping",51* "shippingAddress": {52* "firstName": "John",53* "lastName": "Doe",54* "email":"john.doe@somedomain.com",55* "phone":"5555555",56* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"57* },58* "pickupDetails":null59* },60* "lineItems":[61* {62* "quantity": 1,63* "price": 120,64* "name": "A product",65* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",66* "totalPrice": 120,67* "lineItemType": "PHYSICAL",68* "customTextFields": [69* "title": "Custom Field",70* "value": "Custom value"71* ],72* "mediaItem": {73* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",74* "type": "IMAGE"75* },76* "sku": "21554345656",77* "options": [ ],78* "weight": 3,79* "id": 180* },81* {82* "quantity": 10,83* "price": 25,84* "name": "Another product",85* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",86* "totalPrice": 25,87* "lineItemType": "PHYSICAL",88* "mediaItem": {89* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",90* "type": "IMAGE"91* },92* "sku": "217537123517253",93* "options": [94* {95* "option": "Size",96* "selection": "Medium"97* },98* {99* "option": "Color",100* "selection": "Black"101* }102* ],103* "weight": 2,104* "id": 2105* }106* ],107* "totals": {108* "discount": 0,109* "quantity": 2,110* "shipping": 0,111* "subtotal": 145,112* "tax": 0,113* "total": 145,114* "weight": 5115* },116* "weightUnit": "LB"117* }118*/