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
Cart creation options.
Returns
Fulfilled - 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.
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?
Create a cart with minimum required fields
1/**************************************2 * Backend code - my-backend-file.jsw *3 *************************************/45import { cart } from 'wix-ecom-backend';67export 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 error15 }16}1718/*************19 * Page code *20 ************/2122import { myCreateCartFunction } from 'backend/my-backend-file';2324// Sample options object:25const options = {26 lineItems: [{27 catalogReference: {28 // appId for Wix Stores Catalog29 appId: "1380b703-ce81-ff05-f115-39571d94dfcd",30 // example of Wix Stores productId31 catalogItemId: "c8539b66-7a44-fe18-affc-afec4be8562a"32 },33 quantity: 334 }]35}3637myCreateCartFunction(options)38 .then((newCart) => {39 const cartId = newCart._id;40 const cartCheckoutId = newCart.checkoutId;4142 console.log('Success! Created newCart:', newCart);43 return newCart;44 })45 .catch((error) => {46 console.error(error);47 // Handle the error48 });4950/* 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": "1380b703-ce81-ff05-f115-39571d94dfcd"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": true93 * },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 */