Search.../

updateCart( )

Updates a specified cart's properties.

Description

The updateCart() function returns a Promise that resolves when the specified cart's properties are updated.

Note: When updating catalog items, options.lineItems.catalogReference is required.

Syntax

function updateCart(_id: string, options: UpdateCartOptions): Promise<Cart>

updateCart Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the cart to be updated.

options
Optional
UpdateCartOptions

Available options to use when updating a cart.

Returns

Fulfilled - Updated cart.

Return Type:

Promise<
Cart
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the cart was created.

_id
string

Cart ID.

_updatedDate
Date

Date and time the cart was updated.

appliedDiscounts
Array<
CartDiscount
>

Cart discounts.

buyerInfo
BuyerInfo

Buyer information.

buyerLanguage
string

Language for communication with the buyer. Defaults to the site language. For a site that supports multiple languages, this is the language the buyer selected.

buyerNote
string

Buyer note left by the customer.

checkoutId
string

ID of the checkout that originated from this cart.

contactInfo
AddressWithContact

Contact info.

conversionCurrency
string

Currency code used for all the converted prices that are returned. For a site that supports multiple currencies, this is the currency the buyer selected.

currency
string

Currency used for pricing.

lineItems
Array<
LineItem
>

Line items.

overrideCheckoutUrl
string

overrideCheckoutUrl allows the flexibility to redirect customers to a customized checkout page.

This field overrides the checkoutUrl in a cart or checkout. checkoutUrl is used to send customers back to their checkouts. By default, a checkoutUrl generates for a checkout and directs to a standard Wix checkout page. When overrideCheckoutUrl has a value, it will replace and set the value of checkoutUrl.

purchaseFlowId
string

Persistent ID that correlates between the various eCommerce elements: cart, checkout, and order.

selectedShippingOption
SelectedShippingOption

Selected shipping option.

siteLanguage
string

Site language in which original values are displayed.

taxIncludedInPrices
boolean

Whether tax is included in line item prices.

weightUnit
string

Weight measurement unit - defaults to site's weight unit. Supported values:

  • "KG"
  • "LB"

Was this helpful?

Update a cart

Apply a coupon to a cart

Copy Code
1/**************************************
2 * Backend code - my-backend-file.web.js *
3 *************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { cart } from 'wix-ecom-backend';
7
8export const myUpdateCartFunction = webMethod(Permissions.Anyone, async (_id, options) => {
9 try {
10 const updatedCart = await cart.updateCart(_id, options);
11 console.log('Success! Updated cart:', updatedCart);
12 return updatedCart;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/*************
20 * Page code *
21 ************/
22
23import { myUpdateCartFunction } from 'backend/my-backend-file.web';
24
25// Sample cartId:
26const _id = 'ba47a627-7bb8-4918-89b2-6a72af464765';
27
28// Coupon code to be applied to the cart
29const updateOptions = {
30 "couponCode": "SUMMERSALE10"
31}
32
33myUpdateCartFunction(_id, updateOptions)
34 .then((updatedCart) => {
35 // appliedCoupon boolean resolves to true if coupon object exists
36 const appliedCoupon = !!updatedCart.appliedDiscounts[0].coupon
37
38 console.log('Success! Updated cart:', updatedCart);
39 return updatedCart;
40 })
41 .catch((error) => {
42 console.error(error);
43 // Handle the error
44 });
45
46/* Promise resolves to:
47 *
48 * {
49 * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765",
50 * "appliedDiscounts": [
51 * {
52 * "coupon": {
53 * "_id": "fbb94b06-7447-4161-9c48-59bfcdc39e77",
54 * "code": "SUMMERSALE10"
55 * }
56 * }
57 * ],
58 * "lineItems": [
59 * {
60 * "_id": "00000000-0000-0000-0000-000000000001",
61 * "quantity": 1,
62 * "catalogReference": {
63 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",
64 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"
65 * },
66 * "productName": {
67 * "original": "Shirt",
68 * "translated": "Shirt"
69 * },
70 * "url": "https://example.wixsite.com",
71 * "price": {
72 * "amount": "10",
73 * "convertedAmount": "10",
74 * "formattedAmount": "€10.00",
75 * "formattedConvertedAmount": "€10.00"
76 * },
77 * "fullPrice": {
78 * "amount": "10",
79 * "convertedAmount": "10",
80 * "formattedAmount": "€10.00",
81 * "formattedConvertedAmount": "€10.00"
82 * },
83 * "priceBeforeDiscounts": {
84 * "amount": "10",
85 * "convertedAmount": "10",
86 * "formattedAmount": "€10.00",
87 * "formattedConvertedAmount": "€10.00"
88 * },
89 * "descriptionLines": [],
90 * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",
91 * "availability": {
92 * "status": "AVAILABLE"
93 * },
94 * "physicalProperties": {
95 * "sku": "364115376135191",
96 * "shippable": true
97 * },
98 * "couponScopes": [
99 * {
100 * "namespace": "stores",
101 * "group": {
102 * "name": "collection",
103 * "entityId": "00000000-000000-000000-000000000001"
104 * }
105 * },
106 * {
107 * "namespace": "stores",
108 * "group": {
109 * "name": "product",
110 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"
111 * }
112 * }
113 * ],
114 * "itemType": {
115 * "preset": "PHYSICAL"
116 * },
117 * "paymentOption": "FULL_PAYMENT_ONLINE"
118 * }
119 * ],
120 * "buyerInfo": {
121 * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7"
122 * },
123 * "currency": "EUR",
124 * "conversionCurrency": "EUR",
125 * "buyerLanguage": "en",
126 * "siteLanguage": "en",
127 * "taxIncludedInPrices": false,
128 * "weightUnit": "KG",
129 * "subtotal": {
130 * "amount": "10",
131 * "convertedAmount": "10",
132 * "formattedAmount": "€10.00",
133 * "formattedConvertedAmount": "€10.00"
134 * },
135 * "inSync": true,
136 * "_createdDate": "2022-05-15T11:31:30.484Z",
137 * "_updatedDate": "2022-06-16T09:20:23.388Z"
138 * }
139 *
140 */