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:
NAME
TYPE
DESCRIPTION
Date and time the cart was created.
Cart ID.
Date and time the cart was updated.
Cart discounts.
Buyer information.
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.
ID of the checkout that originated from this cart.
Contact info.
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 used for pricing.
Line items.
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
.
Persistent ID that correlates between the various eCommerce elements: cart, checkout, and order.
Selected shipping option.
Site language in which original values are displayed.
Whether tax is included in line item prices.
Weight measurement unit - defaults to site's weight unit. Supported values:
"KG"
"LB"
Was this helpful?
1/**************************************2 * Backend code - my-backend-file.web.js *3 *************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { currentCart } from 'wix-ecom-backend';78export const myGetCurrentCartFunction = webMethod(Permissions.Anyone, async () => {9 try {10 const myCurrentCart = await currentCart.getCurrentCart();11 console.log('Success! Retrieved current cart:', currentCart);12 return myCurrentCart;13 } catch (error) {14 console.error(error);15 // Handle the error16 }17});1819/*************20 * Page code *21 ************/2223import { myGetCurrentCartFunction } from 'backend/my-backend-file.web';2425myGetCurrentCartFunction()26 .then((myCurrentCart) => {27 const formattedCartTotal = myCurrentCart.subtotal.formattedAmount;28 const numberOfCartLineItems = myCurrentCart.lineItems.length;2930 console.log('Success! Retrieved current cart:', myCurrentCart);31 return myCurrentCart;32 })33 .catch((error) => {34 console.error(error);35 // Handle the error36 });3738/* Promise resolves to:39 *40 * {41 * "_id": "96a61a4b-6b61-47d1-a039-0213a8230ccd",42 * "lineItems": [43 * {44 * "_id": "00000000-0000-0000-0000-000000000001",45 * "quantity": 3,46 * "catalogReference": {47 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",48 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"49 * },50 * "productName": {51 * "original": "Shirt",52 * "translated": "Shirt"53 * },54 * "url": "https://example.wixsite.com",55 * "price": {56 * "amount": "10",57 * "convertedAmount": "10",58 * "formattedAmount": "€10.00",59 * "formattedConvertedAmount": "€10.00"60 * },61 * "fullPrice": {62 * "amount": "10",63 * "convertedAmount": "10",64 * "formattedAmount": "€10.00",65 * "formattedConvertedAmount": "€10.00"66 * },67 * "priceBeforeDiscounts": {68 * "amount": "10",69 * "convertedAmount": "10",70 * "formattedAmount": "€10.00",71 * "formattedConvertedAmount": "€10.00"72 * },73 * "descriptionLines": [],74 * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",75 * "availability": {76 * "status": "AVAILABLE"77 * },78 * "physicalProperties": {79 * "sku": "364115376135191",80 * "shippable": true81 * },82 * "couponScopes": [83 * {84 * "namespace": "stores",85 * "group": {86 * "name": "collection",87 * "entityId": "00000000-000000-000000-000000000001"88 * }89 * },90 * {91 * "namespace": "stores",92 * "group": {93 * "name": "product",94 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"95 * }96 * }97 * ],98 * "itemType": {99 * "preset": "PHYSICAL"100 * },101 * "paymentOption": "FULL_PAYMENT_ONLINE"102 * }103 * ],104 * "buyerInfo": {105 * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db",106 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"107 * },108 * "currency": "EUR",109 * "conversionCurrency": "EUR",110 * "buyerLanguage": "en",111 * "siteLanguage": "en",112 * "taxIncludedInPrices": false,113 * "weightUnit": "KG",114 * "subtotal": {115 * "amount": "30",116 * "convertedAmount": "30",117 * "formattedAmount": "€30.00",118 * "formattedConvertedAmount": "€30.00"119 * },120 * "appliedDiscounts": [],121 * "inSync": false,122 * "_createdDate": "2022-05-16T12:04:01.244Z",123 * "_updatedDate": "2022-05-16T12:04:01.244Z"124 * }125 *126 */
1import { currentCart } from 'wix-ecom-backend';23currentCart.getCurrentCart()4 .then((myCurrentCart) => {5 const cartId = myCurrentCart._id;6 const cartLineItems = myCurrentCart.lineItems;78 console.log('Success! Retrieved myCurrentCart:', myCurrentCart);9 return myCurrentCart;10 })11 .catch((error) => {12 console.error(error);13 // Handle the error14 });1516/* Promise resolves to:17 * {18 * "_id": "295f60d4-6b04-4d53-a48c-24f51953cdc0",19 * "_createdDate": "2024-03-07T12:23:18.083Z",20 * "_updatedDate": "2024-03-07T12:23:18.083Z",21 * "lineItems": [22 * {23 * "quantity": 1,24 * "catalogReference": {25 * "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e",26 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",27 * "options": {28 * "options": {29 * "Size": "Medium",30 * "Color": "Pink"31 * },32 * "variantId": "00000000-0000-0000-0000-000000000000"33 * }34 * },35 * "productName": {36 * "original": "SWEATSHIRT",37 * "translated": "SWEATSHIRT"38 * },39 * "url": "https://example.wixstudio.io/product-page/sweatshirt",40 * "price": {41 * "amount": "85",42 * "convertedAmount": "85",43 * "formattedAmount": "€85.00",44 * "formattedConvertedAmount": "€85.00"45 * },46 * "fullPrice": {47 * "amount": "85",48 * "convertedAmount": "85",49 * "formattedAmount": "€85.00",50 * "formattedConvertedAmount": "€85.00"51 * },52 * "priceBeforeDiscounts": {53 * "amount": "85",54 * "convertedAmount": "85",55 * "formattedAmount": "€85.00",56 * "formattedConvertedAmount": "€85.00"57 * },58 * "descriptionLines": [59 * {60 * "name": {61 * "original": "Color",62 * "translated": "Color"63 * },64 * "colorInfo": {65 * "original": "Pink",66 * "translated": "Pink",67 * "code": "#D50075"68 * },69 * "lineType": "UNRECOGNISED"70 * },71 * {72 * "name": {73 * "original": "Size",74 * "translated": "Size"75 * },76 * "plainText": {77 * "original": "Medium",78 * "translated": "Medium"79 * },80 * "lineType": "UNRECOGNISED"81 * }82 * ],83 * "image": "wix:image://v1/c837a6_92b21b13a9534ad9a3874f5d980c0448~mv2.jpg/c837a6_92b21b13a9534ad9a3874f5d980c0448~mv2.jpg#originWidth=2763&originHeight=2772",84 * "availability": {85 * "status": "AVAILABLE"86 * },87 * "physicalProperties": {88 * "sku": "0001",89 * "shippable": true90 * },91 * "couponScopes": [92 * {93 * "namespace": "stores",94 * "group": {95 * "name": "collection",96 * "entityId": "00000000-000000-000000-000000000001"97 * }98 * },99 * {100 * "namespace": "stores",101 * "group": {102 * "name": "product",103 * "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"104 * }105 * }106 * ],107 * "itemType": {108 * "preset": "PHYSICAL"109 * },110 * "paymentOption": "FULL_PAYMENT_ONLINE",111 * "customLineItem": false,112 * "_id": "00000000-0000-0000-0000-000000000001"113 * }114 * ],115 * "buyerInfo": {116 * "visitorId": "66886a50-cdec-4774-8568-45d4a3c1f60c"117 * },118 * "currency": "EUR",119 * "conversionCurrency": "EUR",120 * "buyerLanguage": "en",121 * "siteLanguage": "en",122 * "taxIncludedInPrices": false,123 * "weightUnit": "KG",124 * "subtotal": {125 * "amount": "85",126 * "convertedAmount": "85",127 * "formattedAmount": "€85.00",128 * "formattedConvertedAmount": "€85.00"129 * },130 * "appliedDiscounts": [],131 * "contactInfo": {132 * "address": {133 * "subdivision": "IE-L",134 * "country": "IE",135 * "postalCode": "D02"136 * }137 * },138 * "purchaseFlowId": "ff848d1d-bc92-4de6-9acc-ad098d866f28"139 * }140 */141