getCurrentCart( )
Deprecated.
This function will continue to work, but a newer version is available at
wix-ecom-backend.CurrentCart.getCurrentCart()
.
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()
.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
wixStoresBackend.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.
Note: When editing a site as a collaborator,
getCurrentCart()
will only work when viewing the live site.
Syntax
function getCurrentCart(): Promise<Cart>
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 wixStoresBackend from 'wix-stores-backend'23export function getCurrentCart() {4 return wixStoresBackend.getCurrentCart();5}67/* Returned promise resolves to:8*9* {10* "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",11* "appliedCoupon": {12* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",13* "name": "Summer Sale",14* "code": "SummerSale",15* "discountValue": "$10.00",16* "couponType": "MoneyOff"17* },18* "billingAddress": {19* "firstName": "John",20* "lastName": "Doe",21* "email":"john.doe@somedomain.com",22* "phone":"5555555",23* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"24* },25* "buyerNote": "This is a note from the buyer.",26* "buyerInfo":{27* "firstName": "John",28* "lastName": "Doe",29* "email": "john.doe@somedomain.com",30* "phone": "5555555555",31* "identityType": "CONTACT"32* },33* "status": "INCOMPLETE",34* "currency": {35* "code": "USD",36* "symbol": "$"37* },38* "shippingInfo": {39* "deliveryOption": "Free Shipping",40* "shippingAddress": {41* "firstName": "John",42* "lastName": "Doe",43* "email":"john.doe@somedomain.com",44* "phone":"5555555",45* "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"46* },47* "pickupDetails":null48* },49* "lineItems":[50* {51* "quantity": 1,52* "price": 120,53* "name": "A product",54* "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",55* "totalPrice": 120,56* "lineItemType": "PHYSICAL",57* "customTextFields": [58* "title": "Custom Field",59* "value": "Custom value"60* ],61* "mediaItem": {62* "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",63* "type": "IMAGE"64* },65* "sku": "21554345656",66* "options": [ ],67* "weight": 3,68* "id": 169* },70* {71* "quantity": 1,72* "price": 25,73* "name": "Another product",74* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",75* "totalPrice": 25,76* "lineItemType": "PHYSICAL",77* "mediaItem": {78* "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",79* "type": "IMAGE"80* },81* "sku": "217537123517253",82* "options": [83* {84* "option": "Size",85* "selection": "Medium"86* },87* {88* "option": "Color",89* "selection": "Black"90* }91* ],92* "weight": 2,93* "id": 294* }95* ],96* "totals": {97* "discount": 0,98* "quantity": 2,99* "shipping": 0,100* "subtotal": 145,101* "tax": 0,102* "total": 145,103* "weight": 5104* },105* "weightUnit": "LB"106* }107*/108