Search.../

getCurrentCart( )

Retrieves the current site visitor's cart.

Description

The getCurrentCart() function returns a Promise that resolves when the current cart is retrieved.

Syntax

function getCurrentCart(): Promise<Cart>

getCurrentCart Parameters

This function does not take any parameters.

Returns

Current session's active 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?

Get the current site visitor's cart

Copy Code
1/**************************************
2 * Backend code - my-backend-file.jsw *
3 *************************************/
4
5 import { currentCart } from 'wix-ecom-backend';
6
7 export async function myGetCurrentCartFunction() {
8 try {
9 const myCurrentCart = await currentCart.getCurrentCart();
10 console.log('Success! Retrieved current cart:', currentCart);
11 return myCurrentCart;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16 }
17
18 /*************
19 * Page code *
20 ************/
21
22 import { myGetCurrentCartFunction } from 'backend/my-backend-file';
23
24 myGetCurrentCartFunction()
25 .then((myCurrentCart) => {
26 const formattedCartTotal = myCurrentCart.subtotal.formattedAmount;
27 const numberOfCartLineItems = myCurrentCart.lineItems.length;
28
29 console.log('Success! Retrieved current cart:', myCurrentCart);
30 return myCurrentCart;
31 })
32 .catch((error) => {
33 console.error(error);
34 // Handle the error
35 });
36
37 /* Promise resolves to:
38 *
39 * {
40 * "_id": "96a61a4b-6b61-47d1-a039-0213a8230ccd",
41 * "lineItems": [
42 * {
43 * "_id": "00000000-0000-0000-0000-000000000001",
44 * "quantity": 3,
45 * "catalogReference": {
46 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",
47 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"
48 * },
49 * "productName": {
50 * "original": "Shirt",
51 * "translated": "Shirt"
52 * },
53 * "url": "https://example.wixsite.com",
54 * "price": {
55 * "amount": "10",
56 * "convertedAmount": "10",
57 * "formattedAmount": "€10.00",
58 * "formattedConvertedAmount": "€10.00"
59 * },
60 * "fullPrice": {
61 * "amount": "10",
62 * "convertedAmount": "10",
63 * "formattedAmount": "€10.00",
64 * "formattedConvertedAmount": "€10.00"
65 * },
66 * "priceBeforeDiscounts": {
67 * "amount": "10",
68 * "convertedAmount": "10",
69 * "formattedAmount": "€10.00",
70 * "formattedConvertedAmount": "€10.00"
71 * },
72 * "descriptionLines": [],
73 * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",
74 * "availability": {
75 * "status": "AVAILABLE"
76 * },
77 * "physicalProperties": {
78 * "sku": "364115376135191",
79 * "shippable": true
80 * },
81 * "couponScopes": [
82 * {
83 * "namespace": "stores",
84 * "group": {
85 * "name": "collection",
86 * "entityId": "00000000-000000-000000-000000000001"
87 * }
88 * },
89 * {
90 * "namespace": "stores",
91 * "group": {
92 * "name": "product",
93 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"
94 * }
95 * }
96 * ],
97 * "itemType": {
98 * "preset": "PHYSICAL"
99 * },
100 * "paymentOption": "FULL_PAYMENT_ONLINE"
101 * }
102 * ],
103 * "buyerInfo": {
104 * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db",
105 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
106 * },
107 * "currency": "EUR",
108 * "conversionCurrency": "EUR",
109 * "buyerLanguage": "en",
110 * "siteLanguage": "en",
111 * "taxIncludedInPrices": false,
112 * "weightUnit": "KG",
113 * "subtotal": {
114 * "amount": "30",
115 * "convertedAmount": "30",
116 * "formattedAmount": "€30.00",
117 * "formattedConvertedAmount": "€30.00"
118 * },
119 * "appliedDiscounts": [],
120 * "inSync": false,
121 * "_createdDate": "2022-05-16T12:04:01.244Z",
122 * "_updatedDate": "2022-05-16T12:04:01.244Z"
123 * }
124 *
125 */