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:
Add the new import statement:
javascript | Copy Codeimport { currentCart } from 'wix-ecom-backend';Look for any code that uses
cart.getCurrentCart()
, and replace it withcurrentCart.getCurrentCart()
. Update your code to work with the newgetCurrentCart()
response properties. For more info about the differences between the Stores Cart and eCommerce Cart, refer to the cart conversion table.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:
NAME
TYPE
DESCRIPTION
Unique identifier of the shopping cart.
Coupon applied in the shopping cart.
Cart billing address.
The buyer's information.
Cart status. Either "INCOMPLETE"
or "COMPLETE"
.
Currency of the shopping cart.
The shopping cart's shipping information.
Items in the shopping cart.
The shopping cart's totals.
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.
1import { cart } from 'wix-stores-frontend';23cart.getCurrentCart()4 .then((currentCart) => {5 const cartId = currentCart._id;6 const cartLineItems = currentCart.lineItems;7 })8 .catch((error) => {9 console.error(error);10 });111213/* 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":null53* },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": 174* },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": 299* }100* ],101* "totals": {102* "discount": 0,103* "quantity": 2,104* "shipping": 0,105* "subtotal": 145,106* "tax": 0,107* "total": 145,108* "weight": 5109* },110* "weightUnit": "LB"111* }112*/