Search.../

getCart( )

Retrieves a cart.

Description

The getCart() function returns a Promise that resolves when the specified cart is retrieved.

Syntax

function getCart(_id: string): Promise<Cart>

getCart Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the cart to retrieve.

Returns

Fulfilled - The specified cart.

Return Type:

Promise<
Cart
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the cart was created.

_id
string

Cart ID.

_updatedDate
Date

Date and time the cart was updated.

appliedDiscounts
Array<
CartDiscount
>

Cart discounts.

buyerInfo
BuyerInfo

Buyer information.

buyerLanguage
string

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.

buyerNote
string

Buyer note left by the customer.

checkoutId
string

ID of the checkout that originated from this cart.

contactInfo
AddressWithContact

Contact info.

conversionCurrency
string

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
string

Currency used for pricing.

lineItems
Array<
LineItem
>

Line items.

overrideCheckoutUrl
string

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.

purchaseFlowId
string

Persistent ID that correlates between the various eCommerce elements: cart, checkout, and order.

selectedShippingOption
SelectedShippingOption

Selected shipping option.

siteLanguage
string

Site language in which original values are displayed.

taxIncludedInPrices
boolean

Whether tax is included in line item prices.

weightUnit
string

Weight measurement unit - defaults to site's weight unit. Supported values:

  • "KG"
  • "LB"

Was this helpful?

Get a cart

Copy Code
1/**************************************
2 * Backend code - my-backend-file.web.js *
3 *************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { cart } from 'wix-ecom-backend';
7
8export const myGetCartFunction = webMethod(Permissions.Anyone, async (cartId) => {
9 try {
10 const retrievedCart = await cart.getCart(cartId);
11 console.log('Success! Retrieved cart:', retrievedCart);
12 return retrievedCart;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/*************
20 * Page code *
21 ************/
22
23import { myGetCartFunction } from 'backend/my-backend-file.web';
24
25// Sample cartId:
26const cartId = '96a61a4b-6b61-47d1-a039-0213a8230ccd';
27
28myGetCartFunction(cartId)
29 .then((cart) => {
30 const cartCheckoutId = cart.checkoutId;
31 const formattedCartTotal = cart.subtotal.formattedAmount;
32 const numOfCartLineItems = cart.lineItems.length;
33
34 console.log('Success! Retrieved cart:', cart);
35 return cart;
36 })
37 .catch((error) => {
38 console.error(error);
39 // Handle the error
40 });
41
42/* Promise resolves to:
43 *
44 * {
45 * "_id": "96a61a4b-6b61-47d1-a039-0213a8230ccd",
46 * "lineItems": [
47 * {
48 * "_id": "00000000-0000-0000-0000-000000000001",
49 * "quantity": 3,
50 * "catalogReference": {
51 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",
52 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"
53 * },
54 * "productName": {
55 * "original": "Shirt",
56 * "translated": "Shirt"
57 * },
58 * "url": "https://example.wixsite.com",
59 * "price": {
60 * "amount": "10",
61 * "convertedAmount": "10",
62 * "formattedAmount": "€10.00",
63 * "formattedConvertedAmount": "€10.00"
64 * },
65 * "fullPrice": {
66 * "amount": "10",
67 * "convertedAmount": "10",
68 * "formattedAmount": "€10.00",
69 * "formattedConvertedAmount": "€10.00"
70 * },
71 * "priceBeforeDiscounts": {
72 * "amount": "10",
73 * "convertedAmount": "10",
74 * "formattedAmount": "€10.00",
75 * "formattedConvertedAmount": "€10.00"
76 * },
77 * "descriptionLines": [],
78 * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",
79 * "availability": {
80 * "status": "AVAILABLE"
81 * },
82 * "physicalProperties": {
83 * "sku": "364115376135191",
84 * "shippable": true
85 * },
86 * "couponScopes": [
87 * {
88 * "namespace": "stores",
89 * "group": {
90 * "name": "collection",
91 * "entityId": "00000000-000000-000000-000000000001"
92 * }
93 * },
94 * {
95 * "namespace": "stores",
96 * "group": {
97 * "name": "product",
98 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"
99 * }
100 * }
101 * ],
102 * "itemType": {
103 * "preset": "PHYSICAL"
104 * },
105 * "paymentOption": "FULL_PAYMENT_ONLINE"
106 * }
107 * ],
108 * "buyerInfo": {
109 * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db",
110 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
111 * },
112 * "currency": "EUR",
113 * "conversionCurrency": "EUR",
114 * "buyerLanguage": "en",
115 * "siteLanguage": "en",
116 * "taxIncludedInPrices": false,
117 * "weightUnit": "KG",
118 * "subtotal": {
119 * "amount": "30",
120 * "convertedAmount": "30",
121 * "formattedAmount": "€30.00",
122 * "formattedConvertedAmount": "€30.00"
123 * },
124 * "appliedDiscounts": [],
125 * "inSync": false,
126 * "_createdDate": "2022-05-16T12:04:01.244Z",
127 * "_updatedDate": "2022-05-16T12:04:01.244Z"
128 * }
129 *
130 */