Search.../

updateCurrentCart( )

Updates the current site visitor's cart.

Description

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

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

Syntax

function updateCurrentCart(options: UpdateCurrentCartOptions): Promise<Cart>

updateCurrentCart Parameters

NAME
TYPE
DESCRIPTION
options
Optional
UpdateCurrentCartOptions

Current cart update options.

Returns

Fulfilled - The updated current 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 the current site visitor's cart

Apply a coupon to the current cart

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