Search.../

getCurrentCart( )

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

We recommend you migrate to the new Wix eCommerce APIs as soon as possible.

Description

Migration Instructions

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

The wix-ecom-backend.CurrentCart.getCurrentCart() function works from both backend and frontend code.

To migrate to the new function:

  1. Add the new import statement:

    import { currentCart } from 'wix-ecom-backend';
    javascript | Copy Code
  2. Look for any code that uses cart.getCurrentCart(), and replace it with currentCart.getCurrentCart(). Update your code to work with the new getCurrentCart() response properties. For more info about the differences between the Stores Cart and eCommerce Cart, refer to the cart conversion table.

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

Gets the current site visitor's shopping cart.

The getCurrentCart() function returns a Promise that resolves to the current site visitor's shopping cart.

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

This example uses a deprecated function.

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