Introduction

Note: This module is universal. Functions in this module can run on both the backend and frontend.

The eCommerce Cart API provides functionality for creating and managing carts, as well as for creating a checkout based on an existing cart. The cart is the first phase of an eCommerce purchase flow, followed by checkout, then order. A cart holds information about items for purchase, prices, discounts, site details, and more.

A cart can be created either by using the createCart() function, or by adding an item to the cart.

Estimate the cart's totals (including shipping costs) using the estimateTotals() function.

Before you begin

To assist in moving from the Stores Cart API to the eCommerce Cart API, refer to the Cart Conversion Table.

To use the Wix eCommerce Cart API, import { cart } from the wix-ecom-backend module:

Copy
import { cart } from "wix-ecom-backend";
Did this help?

addToCart( )


Adds catalog line items to a cart.

The addToCart() function returns a Promise that resolves to the updated cart when the specified items have been added.

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

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Manage eCommerce - Admin Permissions
Learn more about app permissions.
Method Declaration
Copy
function addToCart(
  _id: string,
  options: AddToCartOptions,
): Promise<AddToCartResponse>;
Method Parameters
_idstringRequired

Cart ID.


optionsAddToCartOptions

Items to be added to cart.

Returns
Return Type:Promise<AddToCartResponse>
Add a catalog item to a cart
JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { cart } from "wix-ecom-backend"; export const myAddToCartFunction = webMethod( Permissions.Anyone, async (_id, options) => { try { const updatedCart = await cart.addToCart(_id, options); console.log("Success! Updated cart:", updatedCart); return updatedCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myAddToCartFunction } from "backend/my-backend-file.web"; // Sample addToCart function parameters: const cartId = "96a61a4b-6b61-47d1-a039-0213a8230ccd"; const options = { lineItems: [ { catalogReference: { // Wix Stores appId appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e", // Wix Stores productId catalogItemId: "c8539b66-7a44-fe18-affc-afec4be8562a", }, quantity: 1, }, ], }; myAddToCartFunction(cartId, options) .then((updatedCart) => { const cartSubtotal = updatedCart.subtotal.amount; const cartCheckoutId = updatedCart.checkoutId; const numberOfCartItems = updatedCart.lineItems.length; console.log("Success! Updated cart:", updatedCart); return updatedCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765", * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 1, * "catalogReference": { * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e" * }, * "productName": { * "original": "Shirt", * "translated": "Shirt" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "fullPrice": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "descriptionLines": [], * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "364115376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "appliedDiscounts": [], * "inSync": true, * "_createdDate": "2022-05-15T11:31:30.484Z", * "_updatedDate": "2022-05-23T12:11:55.095Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

createCart( )


Creates a new cart.

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.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Manage eCommerce - Admin Permissions
Learn more about app permissions.
Method Declaration
Copy
function createCart(options: CreateCartOptions): Promise<Cart>;
Method Parameters
optionsCreateCartOptions

Cart creation options.

Returns
Return Type:Promise<Cart>
Create a cart with minimum required fields
JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { cart } from "wix-ecom-backend"; export const myCreateCartFunction = webMethod( Permissions.Anyone, async (options) => { try { const newCart = await cart.createCart(options); console.log("Success! Created newCart:", newCart); return newCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myCreateCartFunction } from "backend/my-backend-file.web"; // Sample options object: const options = { lineItems: [ { catalogReference: { // appId for Wix Stores Catalog appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e", // example of Wix Stores productId catalogItemId: "c8539b66-7a44-fe18-affc-afec4be8562a", }, quantity: 3, }, ], }; myCreateCartFunction(options) .then((newCart) => { const cartId = newCart._id; const cartCheckoutId = newCart.checkoutId; console.log("Success! Created newCart:", newCart); return newCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "96a61a4b-6b61-47d1-a039-0213a8230ccd", * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 3, * "catalogReference": { * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e" * }, * "productName": { * "original": "Shirt", * "translated": "Shirt" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "fullPrice": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "descriptionLines": [], * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "364115376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "appliedDiscounts": [], * "inSync": false, * "_createdDate": "2022-05-16T12:04:01.244Z", * "_updatedDate": "2022-05-16T12:04:01.244Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

createCheckout( )


Creates a checkout from a cart.

The createCheckout() function returns a Promise that resolves to the new checkout's ID when it's created.

If a checkout was already created from the specified cart, that checkout will be updated with any new information from the cart.

Note: options.channelType is a required field.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Orders
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function createCheckout(
  _id: string,
  options: CreateCheckoutOptions,
): Promise<CreateCheckoutResponse>;
Method Parameters
_idstringRequired

Cart ID.


optionsCreateCheckoutOptions

Checkout creation options.

Returns
Return Type:Promise<CreateCheckoutResponse>
Create a checkout from a cart
JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { cart } from "wix-ecom-backend"; export const myCreateCheckoutFunction = webMethod( Permissions.Anyone, async (cartId, options) => { try { const checkoutId = await cart.createCheckout(cartId, options); console.log("Success! Checkout created, checkoutId:", checkoutId); return checkoutId; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myCreateCheckoutFunction } from "backend/my-backend-file.web"; // Sample cartId: const cartId = "96a61a4b-6b61-47d1-a039-0213a8230ccd"; // Sample options object: const options = { // channelType is a required field channelType: "WEB", email: "janedoe@example.com", shippingAddress: { addressLine1: "235 West 23rd Street", addressLine2: "3rd floor", city: "New York", country: "US", postalCode: "10011", streetAddress: { name: "West 23rd Street", number: "235", }, subdivision: "US-NY", }, }; myCreateCheckoutFunction(cartId, options) .then((checkoutId) => { console.log("Success! Checkout created, checkoutId:", checkoutId); return checkoutId; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * {"checkoutId": "a43420aa-986b-456a-a2f7-7ea5c80e9007"} * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

deleteCart( )


Deletes a cart.

The deleteCart() function returns a Promise that resolves when the specified cart is deleted.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function deleteCart(_id: string): Promise<void>;
Method Parameters
_idstringRequired

ID of the cart to delete.

Delete a cart
JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { cart } from "wix-ecom-backend"; export const myDeleteCartFunction = webMethod( Permissions.Anyone, async (cartId) => { try { await cart.deleteCart(cartId); console.log("Success! Deleted cart"); return; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myDeleteCartFunction } from "backend/my-backend-file.web"; // Sample cartId: const cartId = "96a61a4b-6b61-47d1-a039-0213a8230ccd"; myDeleteCartFunction(cartId) .then(() => { console.log("Success! Deleted cart"); return; }) .catch((error) => { console.error(error); // Handle the error });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

estimateTotals( )


Estimates the subtotal and total for current site visitor’s cart. Totals include tax and are based on the selected carrier service, shipping address, and billing information.

The estimateTotals() function returns a Promise that resolves when the estimated totals are generated.

Note: Not passing any options properties will only estimate the cart items price totals.

Permissions
Manage eCommerce - all permissions
Read eCommerce - all read permissions
Manage Stores - all permissions
Read Stores - all read permissions
Manage Orders
Read Orders
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function estimateTotals(
  _id: string,
  options: EstimateTotalsOptions,
): Promise<EstimateTotalsResponse>;
Method Parameters
_idstringRequired

Cart ID.


optionsEstimateTotalsOptions

Total estimation options.

Returns
Return Type:Promise<EstimateTotalsResponse>
Estimate a cart's totals
JavaScript
/***************************************** * Backend code - my-backend-file.web.js * ****************************************/ import { Permissions, webMethod } from "wix-web-module"; import { cart } from "wix-ecom-backend"; export const myEstimateTotalsFunction = webMethod( Permissions.Anyone, async (cartId, estimateOptions) => { try { const estimatedCartTotals = await cart.estimateTotals( cartId, estimateOptions, ); console.log("Success! Cart totals estimated:", estimatedCartTotals); return estimatedCartTotals; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myEstimateTotalsFunction } from "backend/my-backend-file.web"; // Sample cartId: const cartId = "96a61a4b-6b61-47d1-a039-0213a8230ccd"; // Sample options object: const estimateOptions = { selectedShippingOption: { code: "standard_us_shipping", }, shippingAddress: { addressLine1: "235 West 23rd Street", addressLine2: "3rd floor", city: "New York", country: "US", postalCode: "10011", streetAddress: { name: "West 23rd Street", number: "235", }, subdivision: "US-NY", }, billingAddress: { addressLine1: "235 West 23rd Street", addressLine2: "3rd floor", city: "New York", country: "US", postalCode: "10011", streetAddress: { name: "West 23rd Street", number: "235", }, subdivision: "US-NY", }, }; myEstimateTotalsFunction(cartId, estimateOptions) .then((estimatedCartTotals) => { const formattedShippingPrice = estimatedCartTotals.priceSummary.shipping.formattedAmount; const estimatedCartTotal = estimatedCartTotals.priceSummary.total.formattedAmount; console.log("Success! Cart totals estimated:", estimatedCartTotals); return estimatedCartTotals; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "cart": { * "_id": "96a61a4b-6b61-47d1-a039-0213a8230ccd", * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 5, * "catalogReference": { * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e" * }, * "productName": { * "original": "Shirt", * "translated": "Shirt" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "fullPrice": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "descriptionLines": [], * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "364115376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db", * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "50", * "convertedAmount": "50", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "appliedDiscounts": [], * "inSync": false, * "_createdDate": "2022-05-16T12:04:01.244Z", * "_updatedDate": "2022-05-23T11:55:30.023Z" * }, * "calculatedLineItems": [ * { * "lineItemId": "00000000-0000-0000-0000-000000000001", * "pricesBreakdown": { * "totalPriceAfterTax": { * "amount": "50.00", * "convertedAmount": "50.00", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "totalPriceBeforeTax": { * "amount": "50.00", * "convertedAmount": "50.00", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "taxDetails": { * "taxableAmount": { * "amount": "50.00", * "convertedAmount": "50.00", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "taxRate": "0.0", * "totalTax": { * "amount": "0.0", * "convertedAmount": "0.0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "rateBreakdown": [] * }, * "totalDiscount": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "price": { * "amount": "10.00", * "convertedAmount": "10.00", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10.00", * "convertedAmount": "", * "formattedAmount": "", * "formattedConvertedAmount": "" * } * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "priceSummary": { * "subtotal": { * "amount": "50.00", * "convertedAmount": "50.00", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "shipping": { * "amount": "10.0", * "convertedAmount": "10.0", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "tax": { * "amount": "0.0", * "convertedAmount": "0.0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "discount": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "total": { * "amount": "60.00", * "convertedAmount": "60.00", * "formattedAmount": "€60.00", * "formattedConvertedAmount": "€60.00" * } * }, * "shippingInfo": { * "region": { * "_id": "009fbe5d-89d3-7825-cbbf-1aab4d908b73", * "name": "USA shipping" * }, * "selectedCarrierServiceOption": { * "code": "ed5bbce2-9533-dff4-7db0-13702fd139c5", * "title": "Standard US Shipping", * "logistics": { * "deliveryTime": "" * }, * "cost": { * "totalPriceAfterTax": { * "amount": "10.0", * "convertedAmount": "10.0", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "totalPriceBeforeTax": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "taxDetails": { * "taxRate": "0.0", * "totalTax": { * "amount": "0.0", * "convertedAmount": "0.0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "rateBreakdown": [] * }, * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * } * }, * "requestedShippingOption": false, * "otherCharges": [], * "carrierId": "c8a08776-c095-4dec-8553-8f9698d86adc" * }, * "carrierServiceOptions": [ * { * "carrierId": "c8a08776-c095-4dec-8553-8f9698d86adc", * "shippingOptions": [ * { * "code": "ed5bbce2-9533-dff4-7db0-13702fd139c5", * "title": "Standard US Shipping", * "logistics": { * "deliveryTime": "" * }, * "cost": { * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "otherCharges": [] * } * } * ] * } * ] * }, * "appliedDiscounts": [], * "calculationErrors": { * "orderValidationErrors": [] * }, * "weightUnit": "KG", * "currency": "EUR", * "payNow": { * "subtotal": { * "amount": "50.00", * "convertedAmount": "50.00", * "formattedAmount": "€50.00", * "formattedConvertedAmount": "€50.00" * }, * "shipping": { * "amount": "10.0", * "convertedAmount": "10.0", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "tax": { * "amount": "0.0", * "convertedAmount": "0.0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "discount": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "total": { * "amount": "60.00", * "convertedAmount": "60.00", * "formattedAmount": "€60.00", * "formattedConvertedAmount": "€60.00" * } * }, * "payLater": { * "subtotal": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "shipping": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "tax": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "discount": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "total": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * } * }, * "membershipOptions": { * "eligibleMemberships": [], * "invalidMemberships": [], * "selectedMemberships": [] * } * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

getCart( )


Retrieves a cart.

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

Permissions
Manage eCommerce - all permissions
Read eCommerce - all read permissions
Manage Stores - all permissions
Read Stores - all read permissions
Manage Orders
Read Orders
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function getCart(_id: string): Promise<Cart>;
Method Parameters
_idstringRequired

ID of the cart to retrieve.

Returns
Return Type:Promise<Cart>
Get a cart
JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { cart } from "wix-ecom-backend"; export const myGetCartFunction = webMethod( Permissions.Anyone, async (cartId) => { try { const retrievedCart = await cart.getCart(cartId); console.log("Success! Retrieved cart:", retrievedCart); return retrievedCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myGetCartFunction } from "backend/my-backend-file.web"; // Sample cartId: const cartId = "96a61a4b-6b61-47d1-a039-0213a8230ccd"; myGetCartFunction(cartId) .then((cart) => { const cartCheckoutId = cart.checkoutId; const formattedCartTotal = cart.subtotal.formattedAmount; const numOfCartLineItems = cart.lineItems.length; console.log("Success! Retrieved cart:", cart); return cart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "96a61a4b-6b61-47d1-a039-0213a8230ccd", * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 3, * "catalogReference": { * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e" * }, * "productName": { * "original": "Shirt", * "translated": "Shirt" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "fullPrice": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "descriptionLines": [], * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "364115376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db", * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "appliedDiscounts": [], * "inSync": false, * "_createdDate": "2022-05-16T12:04:01.244Z", * "_updatedDate": "2022-05-16T12:04:01.244Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

removeCoupon( )


Removes the coupon from a specified cart.

The removeCoupon() function returns a Promise that resolves to the updated cart when the coupon is removed from the specified cart.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function removeCoupon(_id: string): Promise<RemoveCouponResponse>;
Method Parameters
_idstringRequired

Cart ID.

Returns
Return Type:Promise<RemoveCouponResponse>
Remove coupon from a cart
JavaScript
/************************************** * Backend code - my-backend-file.web.js * **************************************/ import { Permissions, webMethod } from "wix-web-module"; import { cart } from "wix-ecom-backend"; export const myRemoveCouponFunction = webMethod( Permissions.Anyone, async (cartId) => { try { const updatedCart = await cart.removeCoupon(cartId); console.log("Success! Updated cart:", updatedCart); return updatedCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myRemoveCouponFunction } from "backend/my-backend-file.web"; // Sample cartId: const cartId = "ba47a627-7bb8-4918-89b2-6a72af464765"; myRemoveCouponFunction(cartId) .then((updatedCart) => { const cartId = updatedCart._id; const appliedDiscounts = cart.appliedDiscounts; // appliedCoupon boolean value is false if coupon was removed const appliedCoupon = appliedDiscounts.some(({ coupon }) => coupon); console.log("Success! Updated cart:", updatedCart); return updatedCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765", * "appliedDiscounts": [], * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 1, * "catalogReference": { * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e" * }, * "productName": { * "original": "Shirt", * "translated": "Shirt" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "fullPrice": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "descriptionLines": [], * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "364115376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "inSync": true, * "_createdDate": "2022-05-15T11:31:30.484Z", * "_updatedDate": "2022-06-16T09:20:23.388Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

removeLineItems( )


Removes line items from the specified cart.

The removeLineItems() function returns a Promise that resolves to the updated cart when the line items are removed from the specified cart.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function removeLineItems(
  _id: string,
  lineItemIds: Array<string>,
): Promise<RemoveLineItemsResponse>;
Method Parameters
_idstringRequired

ID of the cart to remove line items from.


lineItemIdsArray<string>Required

IDs of the line items to remove from the cart.

Returns
Return Type:Promise<RemoveLineItemsResponse>
Remove 3 line items from a cart
JavaScript
/***************************************** * Backend code - my-backend-file.web.js * ****************************************/ import { Permissions, webMethod } from "wix-web-module"; import { cart } from "wix-ecom-backend"; export const myRemoveLineItemsFunction = webMethod( Permissions.Anyone, async (cartId, lineItemIds) => { try { const updatedCart = await cart.removeLineItems(cartId, lineItemIds); console.log("Success! Line items removed from cart:", updatedCart); return updatedCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myRemoveLineItemsFunction } from "backend/my-backend-file.web"; // Sample cartId: const cartId = "ba47a627-7bb8-4918-89b2-6a72af464765"; // Sample lineItemIds array: const lineItemIds = [ "00000000-0000-0000-0000-000000000001", "00000000-0000-0000-0000-000000000002", "00000000-0000-0000-0000-000000000003", ]; myRemoveLineItemsFunction(cartId, lineItemIds) .then((updatedCart) => { const cartId = updatedCart._id; // All lineItems removed if numberOfCartItems value is 0 const numberOfCartItems = updatedCart.lineItems.length; console.log("Success! Line items removed from cart:", updatedCart); return updatedCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765", * "lineItems": [], * "buyerInfo": { * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "0", * "convertedAmount": "0", * "formattedAmount": "€0.00", * "formattedConvertedAmount": "€0.00" * }, * "appliedDiscounts": [], * "inSync": true, * "_createdDate": "2022-05-15T11:31:30.484Z", * "_updatedDate": "2022-06-16T09:18:32.388Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

updateCart( )


Updates a specified cart's properties.

The updateCart() function returns a Promise that resolves when the specified cart's properties are updated.

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

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Manage eCommerce - Admin Permissions
Learn more about app permissions.
Method Declaration
Copy
function updateCart(_id: string, options: UpdateCartOptions): Promise<Cart>;
Method Parameters
_idstringRequired

ID of the cart to be updated.


optionsUpdateCartOptions

Available options to use when updating a cart.

Returns
Return Type:Promise<Cart>
Update a cart

Apply a coupon to a cart

JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { cart } from "wix-ecom-backend"; export const myUpdateCartFunction = webMethod( Permissions.Anyone, async (_id, options) => { try { const updatedCart = await cart.updateCart(_id, options); console.log("Success! Updated cart:", updatedCart); return updatedCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myUpdateCartFunction } from "backend/my-backend-file.web"; // Sample cartId: const _id = "ba47a627-7bb8-4918-89b2-6a72af464765"; // Coupon code to be applied to the cart const updateOptions = { couponCode: "SUMMERSALE10", }; myUpdateCartFunction(_id, updateOptions) .then((updatedCart) => { // appliedCoupon boolean resolves to true if coupon object exists const appliedCoupon = !!updatedCart.appliedDiscounts[0].coupon; console.log("Success! Updated cart:", updatedCart); return updatedCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765", * "appliedDiscounts": [ * { * "coupon": { * "_id": "fbb94b06-7447-4161-9c48-59bfcdc39e77", * "code": "SUMMERSALE10" * } * } * ], * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 1, * "catalogReference": { * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e" * }, * "productName": { * "original": "Shirt", * "translated": "Shirt" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "fullPrice": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "priceBeforeDiscounts": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "descriptionLines": [], * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "364115376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "10", * "convertedAmount": "10", * "formattedAmount": "€10.00", * "formattedConvertedAmount": "€10.00" * }, * "inSync": true, * "_createdDate": "2022-05-15T11:31:30.484Z", * "_updatedDate": "2022-06-16T09:20:23.388Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

updateLineItemsQuantity( )


Updates the quantity of one or more line items in a specified cart.

The updateLineItemsQuantity() function returns a Promise that resolves when the quantities of the specified cart's line items are updated.

This endpoint is only for updating the quantity of line items. To entirely remove a line item from the cart, use removeLineItems(). To add a new line item to the cart, use addToCart().

This endpoint checks the amount of stock remaining for this line item. If the specified quantity is greater than the remaining stock, then the quantity returned in the response is the total amount of remaining stock.

Permissions
Manage eCommerce - all permissions
Manage Stores - all permissions
Manage Restaurants - all permissions
Learn more about app permissions.
Method Declaration
Copy
function updateLineItemsQuantity(
  _id: string,
  lineItems: Array<LineItemQuantityUpdate>,
): Promise<UpdateLineItemsQuantityResponse>;
Method Parameters
_idstringRequired

Cart ID.


lineItemsArray<LineItemQuantityUpdate>Required

Line item IDs and their new quantity.

Returns
Return Type:Promise<UpdateLineItemsQuantityResponse>
Update the quantity of a cart's line items

The first line item is updated to a quantity of 2, while the second is updated to a quantity of 3

JavaScript
/************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { cart } from "wix-ecom-backend"; export const myUpdateLineItemsQuantityFunction = webMethod( Permissions.Anyone, async (cartId, lineItems) => { try { const updatedCart = await cart.updateLineItemsQuantity(cartId, lineItems); console.log("Success! Line item quantities updated:", updatedCart); return updatedCart; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { myUpdateLineItemsQuantityFunction } from "backend/my-backend-file.web"; // Sample cartId: const cartId = "b79fd177-ec98-4245-b9f6-f09e7afa9d04"; // Sample lineItems array: const lineItems = [ { _id: "00000000-0000-0000-0000-000000000001", quantity: 2, }, { _id: "00000000-0000-0000-0000-000000000002", quantity: 3, }, ]; myUpdateLineItemsQuantityFunction(cartId, lineItems) .then((updatedCart) => { const firstItemQuantity = updatedCart[0].quantity; const secondItemQuantity = updatedCart[1].quantity; const numberOfCartItems = updatedCart.lineItems.length; console.log("Success! Line item quantities updated:", updatedCart); return updatedCart; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "_id": "b79fd177-ec98-4245-b9f6-f09e7afa9d04", * "lineItems": [ * { * "_id": "00000000-0000-0000-0000-000000000001", * "quantity": 2, * "catalogReference": { * "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", * "options": { * "variantId": "e62fee23-7878-437a-bf0e-292f17d11cb5" * } * }, * "productName": { * "original": "Shoe", * "translated": "Shoe" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "85", * "convertedAmount": "85", * "formattedAmount": "€85.00", * "formattedConvertedAmount": "€85.00" * }, * "fullPrice": { * "amount": "85", * "convertedAmount": "85", * "formattedAmount": "€85.00", * "formattedConvertedAmount": "€85.00" * }, * "priceBeforeDiscounts": { * "amount": "85", * "convertedAmount": "85", * "formattedAmount": "€85.00", * "formattedConvertedAmount": "€85.00" * }, * "descriptionLines": [ * { * "name": { * "original": "Color", * "translated": "Color" * }, * "colorInfo": { * "original": "Black", * "translated": "Black", * "code": "#000" * }, * "lineType": "UNRECOGNISED" * } * ], * "image": "wix:image://v1/3c76e2_bf235c38610f4d2a905db71095b351cf~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE", * "quantityAvailable": 30 * }, * "physicalProperties": { * "sku": "364215376135191", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * }, * { * "_id": "00000000-0000-0000-0000-000000000002", * "quantity": 3, * "catalogReference": { * "catalogItemId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09", * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", * "options": { * "variantId": "132b84e8-aab8-47a1-a1f6-2c47557b64a4" * } * }, * "productName": { * "original": "Watch", * "translated": "Watch" * }, * "url": "https://example.wixsite.com", * "price": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "fullPrice": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "priceBeforeDiscounts": { * "amount": "30", * "convertedAmount": "30", * "formattedAmount": "€30.00", * "formattedConvertedAmount": "€30.00" * }, * "descriptionLines": [ * { * "name": { * "original": "Size", * "translated": "Size" * }, * "plainText": { * "original": "Medium", * "translated": "Medium" * }, * "lineType": "UNRECOGNISED" * }, * { * "name": { * "original": "Color", * "translated": "Color" * }, * "colorInfo": { * "original": "Grey", * "translated": "Grey", * "code": "rgb(128, 128, 128)" * }, * "lineType": "UNRECOGNISED" * } * ], * "image": "wix:image://v1/3c76e2_8891bbe3372a428aac976ac59aa0ac74~mv2.jpg#originWidth=1000&originHeight=1000", * "availability": { * "status": "AVAILABLE" * }, * "physicalProperties": { * "sku": "217537123517253", * "shippable": true * }, * "couponScopes": [ * { * "namespace": "stores", * "group": { * "name": "collection", * "entityId": "00000000-000000-000000-000000000001" * } * }, * { * "namespace": "stores", * "group": { * "name": "product", * "entityId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09" * } * } * ], * "itemType": { * "preset": "PHYSICAL" * }, * "paymentOption": "FULL_PAYMENT_ONLINE" * } * ], * "buyerInfo": { * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7" * }, * "currency": "EUR", * "conversionCurrency": "EUR", * "buyerLanguage": "en", * "siteLanguage": "en", * "taxIncludedInPrices": false, * "weightUnit": "KG", * "subtotal": { * "amount": "260", * "convertedAmount": "260", * "formattedAmount": "€260.00", * "formattedConvertedAmount": "€260.00" * }, * "appliedDiscounts": [], * "inSync": false, * "_createdDate": "2022-06-22T11:32:29.601Z", * "_updatedDate": "2022-06-22T11:36:48.831Z" * } * */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?