Search.../

createCart( )

Creates a new cart.

Description

The createCart() function returns a Promise that resolves to the new cart when it's created.

Note: When adding catalog items, options.lineItems.catalogReference is required.

Syntax

function createCart(options: CreateCartOptions): Promise<Cart>

createCart Parameters

NAME
TYPE
DESCRIPTION
options
Optional
CreateCartOptions

Cart creation options.

Returns

Fulfilled - 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?

Create a cart with minimum required fields

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