Search.../

getCurrentCart( )

Deprecated. This function will continue to work, but a newer version is available at wix-stores.cart.getCurrentCart().

Description

Gets the current site visitor's cart.

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-stores.cart.getCurrentCart().

To migrate to the new function:

  1. Add the new import statement:

    import { cart } from 'wix-stores'
    javascript | Copy Code
  2. If you plan to migrate all functions that use wix-stores, remove the original import wixStores statement.

  3. Look for any code that uses wixStores.getCurrentCart(), and replace it with cart.getCurrentCart(). Update your code to work with the new cart.getCurrentCart() call and response properties.

  4. Test your changes to make sure your code behaves as expected.

Syntax

function getCurrentCart(): Promise<CartObj>

getCurrentCart Parameters

This function does not take any parameters.

Returns

Fulfilled - The retrieved cart.

Return Type:

Promise<CartObj>
NAME
TYPE
DESCRIPTION
_id
string

Unique identifier of the shopping cart.

appliedCoupon
CartAppliedCoupon

Coupon applied in the shopping cart.

billingAddress
CartAddress

Cart billing address.

buyerInfo
CartBuyerInfo

The buyer's information.

status
string

Cart status. Either "INCOMPLETE" or "COMPLETE".

currency
Currency

Currency of the shopping cart.

shippingInfo
CartShippingInfo

The shopping cart's shipping information.

lineItems
Array<CartLineItem>

Items in the shopping cart.

totals
OrderTotals

The shopping cart's totals.

weightUnit
string

The order's units of weight. One of: "KG", "LB", or "UNSPECIFIED_WEIGHT_UNIT".

Was this helpful?

Get the current site visitor's cart

Copy Code
1// Updated example using cart.getCurrentCart()
2
3import { cart } from 'wix-stores';
4
5cart.getCurrentCart()
6 .then((currentCart) => {
7 const cartId = currentCart._id;
8 const cartLineItems = currentCart.lineItems;
9 })
10 .catch((error) => {
11 console.error(error);
12 });
13
14
15/* Example of returned currentCart object:
16*
17* {
18* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
19* "appliedCoupon": {
20* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
21* "name": "Summer Sale",
22* "code": "SummerSale",
23* "discountValue": "$10.00",
24* "couponType": "MoneyOff"
25* },
26* "billingAddress": {
27* "firstName": "John",
28* "lastName": "Doe",
29* "email":"john.doe@somedomain.com",
30* "phone":"5555555",
31* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
32* },
33* "buyerNote": "This is a note from the buyer.",
34* "buyerInfo":{
35* "firstName": "John",
36* "lastName": "Doe",
37* "email": "john.doe@somedomain.com",
38* "phone": "5555555555",
39* "identityType": "CONTACT"
40* },
41* "status": "INCOMPLETE",
42* "currency": {
43* "code": "USD",
44* "symbol": "$"
45* },
46* "shippingInfo": {
47* "deliveryOption": "Free Shipping",
48* "shippingAddress": {
49* "firstName": "John",
50* "lastName": "Doe",
51* "email":"john.doe@somedomain.com",
52* "phone":"5555555",
53* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
54* },
55* "pickupDetails":null
56* },
57* "lineItems":[
58* {
59* "quantity": 1,
60* "price": 120,
61* "name": "A product",
62* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
63* "totalPrice": 120,
64* "lineItemType": "PHYSICAL",
65* "customTextFields": [
66* "title": "Custom Field",
67* "value": "Custom value"
68* ],
69* "mediaItem": {
70* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
71* "type": "IMAGE"
72* },
73* "sku": "21554345656",
74* "options": [ ],
75* "weight": 3,
76* "id": 1
77* },
78* {
79* "quantity": 1,
80* "price": 25,
81* "name": "Another product",
82* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
83* "totalPrice": 25,
84* "lineItemType": "PHYSICAL",
85* "mediaItem": {
86* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
87* "type": "IMAGE"
88* },
89* "sku": "217537123517253",
90* "options": [
91* {
92* "option": "Size",
93* "selection": "Medium"
94* },
95* {
96* "option": "Color",
97* "selection": "Black"
98* }
99* ],
100* "weight": 2,
101* "id": 2
102* }
103* ],
104* "totals": {
105* "discount": 0,
106* "quantity": 2,
107* "shipping": 0,
108* "subtotal": 145,
109* "tax": 0,
110* "total": 145,
111* "weight": 5
112* },
113* "weightUnit": "LB"
114* }
115*/
116
117
118// Deprecated example
119
120import wixStores from 'wix-stores';
121
122wixStores.getCurrentCart()
123 .then((cartData) => {
124 const cartId = cartData._id;
125 const cartLineItems = cartData.lineItems;
126 })
127 .catch((error) => {
128 console.log(error);
129 });