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