CorvidReference

wix-stores-backend

The wix-stores-backend module contains functionality for working with your site's store from backend code.

To use the Stores API, import wixStores from the wix-stores-backend module:

   import wixStores from 'wix-stores-backend';

Table of Contents

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
AddressAn object representing an address.
AppliedCouponAn object representing a coupon applied in a shopping cart.
BuyerInfoAn object representing a visitor who abandoned a shopping cart.
CartAn object representing a shopping cart.
CurrencyAn object representing a currency.
CustomTextFieldAn object representing a custom text field.
LineItemAn object representing a line item in a shopping cart.
MediaItemAn object representing a media item.
OptionAn object representing a line item option.
OrderTotalsAn object representing an order's totals.
ProductOptionsAvailabilityAn object returned by the getProductOptionsAvailability() function representing the availability of a product.
ProductOptionsAvailabilitySelectedVariantAn object representing the product variant selected using the getProductOptionsAvailability() funtion.
ShippingInfoAn object representing shipping information.
StoreProductChoicesAn object representing the selection of specific choices from the product's options.

FAQ

    When should I write code in the backend instead of the client side?
    How do I get my store's order data?
    How do I react to events that happen in my store?

getCurrentCart( )

Gets the current site visitor's shopping cart.

Description

The getCurrentCart() function returns a Promise that resolves to the current site visitor's shopping cart.

Syntax

function getCurrentCart(): Promise<Cart>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Cart>
Fulfilled - The retrieved cart.

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

getProductOptionsAvailability( )

Gets the availability of a product based on the specified option choices.

Description

The getProductOptionsAvailability() function returns a Promise that is resolved to a ProductOptionsAvailability object when the product's availability information about the product is retrieved.

The information returned in the selectedVariant and availableForPurchase properties reflects the option choices passed in using the StoreProductChoices parameter.

If the specified choices result in the selection of a single product variant, that variant is returned in the selectedVariant property and the availableForPurchase property indicates whether that product variant is available for purchase.

If the specified choices do not result in the selection of a single product variant, no variant is returned in the selectedVariant property and the availableForPurchase property will be false.

Syntax

function getProductOptionsAvailability(productId: string, choices: StoreProductChoices): Promise<ProductOptionsAvailability>
PARAMETERS
?
Values that you pass to a function.
productId
string
The ID of the product whose availability is being checked.
choices
Option choices to use when checking the product's availability.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Fulfilled - The availability information of the product.

Examples

Get a product's availability information

This example gets a product's availability information using an option choice. The product contains more than one option, so no variant is selected and the product with the specified choices is not available for purchase.

/*****************************
 * backend code - stores.jsw *
 *****************************/

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, choices) {
  return wixStores.getProductOptionsAvailability(productId, choices);
}

/********************
 * client-side code *
 ********************/
import {myFunction} from 'backend/myModule';

// ...

let productId = // get product ID
let choices = {
  "Size": "Large"
};

myBackendFunction(productId, choices)
  .then( (availability) => {
      let available = availability.availableForPurchase;  // false
      let options = availability.productOptions;          // see below
      let mainMedia = availability.mainMedia;
      let mediaItems = availability.mediaItems;
      let selectedVariant = availability.selectedVariant; // null
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * options:
 *
 * "Size": {
 *   "optionType": "drop_down",
 *   "name": "Size",
 *   "choices": [
 *     {
 *       "value": "Small",
 *       "description": "Small",
 *       "inStock": true,
 *       "visible": true
 *     },
 *     {
 *       "value": "Large",
 *       "description": "Large",
 *       "inStock": true,
 *       "visible": true
 *     }
 *   ]
 * },
 * "Color": {
 *   "optionType": "color",
 *   "name": "Color",
 *   "choices": [
 *     {
 *       "value": "rgb(0, 128, 0)",
 *       "description": "green",
 *       "inStock": true,
 *       "visible": true
 *     },
 *     {
 *       "value": "rgb(255, 0, 0)",
 *       "description": "red",
 *       "inStock": true,
 *       "visible": true
 *     }
 *   ]
 * }
 */

Get a product's availability information

This example gets a product's availability information using multiple option choices. Since all the product's options have a corresponding choice, a variant is selected.

/*****************************
 * backend code - stores.jsw *
 *****************************/

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, choices) {
  return wixStores.getProductOptionsAvailability(productId, choices);
}

/********************
 * client-side code *
 ********************/
import {myFunction} from 'backend/myModule';

// ...

let productId = // get product ID
let choices = {
  "Size": "Large",
  "Color": "Red"
};

myBackendFunction(productId, choices)
  .then( (availability) => {
      let available = availability.availableForPurchase;  // true
      let options = availability.productOptions;          // see below
      let mainMedia = availability.mainMedia;
      let mediaItems = availability.mediaItems;
      let selectedVariant = availability.selectedVariant; // see below
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * options:
 *
 * "Size": {
 *   "optionType": "drop_down",
 *   "name": "Size",
 *   "choices": [
 *     {
 *       "value": "Small",
 *       "description": "Small",
 *       "inStock": true,
 *       "visible": true
 *     },
 *     {
 *       "value": "Large",
 *       "description": "Large",
 *       "inStock": true,
 *       "visible": true
 *     }
 *   ]
 * },
 * "Color":{
 *   "optionType": "color",
 *   "name": "Color",
 *   "choices": [
 *     {
 *       "value": "rgb(0, 128, 0)",
 *       "description": "green",
 *       "inStock": true,
 *       "visible": true
 *     },
 *     {
 *       "value": "rgb(255, 0, 0)",
 *       "description": "red",
 *       "inStock": true,
 *       "visible": true
 *     }
 *   ]
 * }
 *
 *
 * selectedVariant:
 *
 * "selectedVariant":{
 *   "sku": "366615376135191",
 *   "currency": "USD",
 *   "price": 7.5,
 *   "discountedPrice": 7.5,
 *   "formattedPrice": "$7.50",
 *   "formattedDiscountedPrice": "$7.50",
 *   "visible": true,
 *   "inStock": true,
 *   "weight": 0
 * }
 */

Address

An object representing an address.

Syntax

type Address = {
  firstName: string
  lastName: string
  email: string
  phone: string
  address: string
}
MEMBERS
?
The properties of an object.
firstName
string
First name.
lastName
string
Last name.
email
string
Email address.
phone
string
Phone number.
address
string
Address.

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

An event when a shopping cart is completed

// Place this code in the events.js file
// of your site's Backend section.

export function wixStores_onCartCompleted(event) {
  let total = event.totals.total;
}

/* Full event object:
 * {
 *    "cartId": "6d158831-1510-44ae-a420-1483a4200852",
 *    "completedTime": "2019-02-27T12:08:16.160Z",
 *    "buyerInfo": {
 *       "id": "091a8443-ab85-480c-918b-777156358dfc",
 *       "firstName": "John",
 *       "lastName": "Doe"
 *       "email": "john.doe@somedomain.com",
 *       "phone": "5555555555",
 *       "identityType": "CONTACT"
 *    },
 *    "weightUnit": "LB",
 *    "buyerNote": "This is a note from the buyer.",
 *    "billingAddress": {
 *       "firstName": "John",
 *       "lastName": "Doe"
 *       "email": "john.doe@somedomain.com",
 *       "phone": "5555555555",
 *       "address": "235 W 23rd St, New York, NY 10011, USA"
 *    },
 *    "currency": {
 *       "currency": "USD",
 *       "symbol": "$"
 *    },
 *    "appliedCoupon": {
 *       "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
 *       "name": "Summer Sale",
 *       "code": "SummerSale",
 *       "discountValue": "$10.00",
 *       "couponType": "MoneyOff"
 *    },
 *    "totals": {
 *       "subtotal": 250,
 *       "discount": 10,
 *       "total": 240,
 *       "quantity": 2
 *    },
 *    "shippingInfo": {
 *      "billingAddress": {
 *         "firstName": "John",
 *         "lastName": "Doe"
 *         "email": "john.doe@somedomain.com",
 *         "phone": "5555555555",
 *         "address": "235 W 23rd St, New York, NY 10011, USA"
 *      },
 *    }
 * }
 */

AppliedCoupon

An object representing a coupon applied in a shopping cart.

Syntax

type AppliedCoupon = {
  code: string
  couponId: string
  name: string
  couponType: string
  discountValue: string
}
MEMBERS
?
The properties of an object.
code
string
Coupon code.
couponId
string
Coupon unique identifier.
name
string
Coupon name.
couponType
string

Type of coupon. One of:

  • "BuyXGetY"
  • "FixedPriceAmount"
  • "FreeShipping"
  • "MoneyOffAmount"
  • "PercentOffRate"
discountValue
string
Value of the coupon discount.

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

An event when a shopping cart is completed

// Place this code in the events.js file
// of your site's Backend section.

export function wixStores_onCartCompleted(event) {
  let total = event.totals.total;
}

/* Full event object:
 * {
 *    "cartId": "6d158831-1510-44ae-a420-1483a4200852",
 *    "completedTime": "2019-02-27T12:08:16.160Z",
 *    "buyerInfo": {
 *       "id": "091a8443-ab85-480c-918b-777156358dfc",
 *       "firstName": "John",
 *       "lastName": "Doe"
 *       "email": "john.doe@somedomain.com",
 *       "phone": "5555555555",
 *       "identityType": "CONTACT"
 *    },
 *    "weightUnit": "LB",
 *    "buyerNote": "This is a note from the buyer.",
 *    "billingAddress": {
 *       "firstName": "John",
 *       "lastName": "Doe"
 *       "email": "john.doe@somedomain.com",
 *       "phone": "5555555555",
 *       "address": "235 W 23rd St, New York, NY 10011, USA"
 *    },
 *    "currency": {
 *       "currency": "USD",
 *       "symbol": "$"
 *    },
 *    "appliedCoupon": {
 *       "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
 *       "name": "Summer Sale",
 *       "code": "SummerSale",
 *       "discountValue": "$10.00",
 *       "couponType": "MoneyOff"
 *    },
 *    "totals": {
 *       "subtotal": 250,
 *       "discount": 10,
 *       "total": 240,
 *       "quantity": 2
 *    },
 *    "shippingInfo": {
 *      "billingAddress": {
 *         "firstName": "John",
 *         "lastName": "Doe"
 *         "email": "john.doe@somedomain.com",
 *         "phone": "5555555555",
 *         "address": "235 W 23rd St, New York, NY 10011, USA"
 *      },
 *    }
 * }
 */

BuyerInfo

An object representing a visitor who abandoned a shopping cart.

Syntax

type BuyerInfo = {
  id: string
  email: string
  firstName: string
  lastName: string
  identityType: string
  phone: string
}
MEMBERS
?
The properties of an object.
id
string
Buyer's unique ID.
email
string
Buyer's email address.
firstName
string
Buyer's first name.
lastName
string
Buyer's last name.
identityType
string

Buyer's identity. One of:

  • "ADMIN": Buyer is the site owner.
  • "MEMBER": Buyer is a logged-in site member.
  • "VISITOR": Buyer is not logged in.
  • "CONTACT": A contact has been created for the buyer.
phone
string
Buyer's phone number.

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

An event when a shopping cart is abandoned

// Place this code in the events.js file
// of your site's Backend section.

export function wixStores_onCartAbandoned(event) {
  let cartId = event.cartId;
  let abandonTime = event.abandonTime;
  let buyerEmail = event.buyerInfo.email;
  let formattedTotal = event.totals.formattedTotal;
}

/*  Full event object:
 *  {
 *    "cartId": "60349781-b3hf-4349-8c9e-09492063da9",
 *    "creationTime": "2019-01-23T11:28:22.328Z",
 *    "abandonTime": "2019-01-23T12:28:02.373Z",
 *    "buyerInfo": {
 *      "id": "6g004532-732d-829f-5kf9-f9rk42afpla04m",
 *      "identityType": "MEMBER",
 *      "email": "john.doe@somedomain.com",
 *      "firstName": "John",
 *      "lastName": "Doe",
 *      "phone": "5555555555"
 *    },
 *    "itemsCount": 1,
 *    "couponId": "329a10d8-73a4-4a78-a68f-93a590c83672",
 *    "totals": {
 *      "subtotal": 20,
 *      "total": 20,
 *      "formattedTotal": "$20.00"
 *    },
 *    "checkoutUrl": "https://mysite.com/checkout?appSectionParams=%7B%22a11y%22%3Afalse%2C%22cartId%22%3A%2260819781-b3cf-4179-9c9e-4958kd89a9%22%2C%22storeUrl%22%3A%22https%3A%2F%2Fmysite.com%22%2C%22isFastFlow%22%3Afalse%2C%22isPickupFlow%22%3Afalse%7D&linkSource=acMail"
 *  }
 */

Cart

An object representing a shopping cart.

See Also

getCurrentCart( )

Syntax

type Cart = {
  id: string
  appliedCoupon: AppliedCoupon
  billingAddress: Address
  buyerInfo: BuyerInfo
  status: string
  currency: Currency
  shippingInfo: ShippingInfo
  lineItems: Array<LineItem>
  totals: OrderTotals
  weightUnit: string
}
MEMBERS
?
The properties of an object.
id
string
Unique identifier of the shopping cart.
appliedCoupon
Coupon applied in the shopping cart.
billingAddress
Cart billing address.
buyerInfo
The buyer's information.
status
string
Cart status. Either "INCOMPLETE" or "COMPLETE".
currency
Currency of the shopping cart.
shippingInfo
The shopping cart's shipping information.
lineItems
Array<LineItem>
Items in the shopping cart.
totals
The shopping cart's totals.
weightUnit
string
The order's units of weight. One of: "KG", "LB", or "UNSPECIFIED_WEIGHT_UNIT".

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

Currency

An object representing a currency.

Syntax

type Currency = {
  currency: string
  symbol: string
}
MEMBERS
?
The properties of an object.
currency
string
The currency code.
symbol
string
The currency symbol.

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

An event when a shopping cart is created

// Place this code in the events.js file
// of your site's Backend section.

export function wixStores_onCartCreated(event) {
  let total = event.totals.total;
}

/*  Full event object:
 * {
 *    "cartId": "6d158831-1510-44ae-a420-1483a4200852",
 *    "creationTime": "2019-02-27T12:03:22.079Z",
 *    "buyerInfo": {
 *      "id": "4kf9ka09-4e9f-a02d-972f-9a5844d9d9a2",
 *      "email": "john.doe@somedomain.com",
 *      "phone": "5555555555",
 *      "firstName": "John",
 *      "lastName": "Doe"
 *    },
 *    "weightUnit": "LB",
 *    "currency": {
 *       "currency": "USD",
 *       "symbol": "$"
 *    },
 *    "totals": {
 *       "subtotal": 130,
 *       "discount": 0,
 *       "total": 130,
 *       "quantity": 1
 *    }
 * }
 */

CustomTextField

An object representing a custom text field.

See Also

getCurrentCart( )

Syntax

type CustomTextField = {
  title: string
  value: string
}
MEMBERS
?
The properties of an object.
title
string
Field title.
value
string
Field value.

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

LineItem

An object representing a line item in a shopping cart.

See Also

getCurrentCart( )

Syntax

type LineItem = {
  name: string
  notes: string
  price: string
  productId: string
  quantity: number
  sku: string
  totalPrice: string
  weight: string
  lineItemType: string
  options: Array<Option>
  mediaItem: MediaItem
  customTextFields: Array<CustomTextField>
}
MEMBERS
?
The properties of an object.
name
string
Name of the line item.
notes
string
Notes about the line item.
price
string
Line item price.
productId
string
Line item product ID.
quantity
number
Line item quantity.
sku
string
Line item stock keeping unit.
totalPrice
string
Total price charged to the customer for all line items after any applicable discounts.
weight
string
Line item weight.
lineItemType
string

Type of the line item. One of:

  • "DIGITAL": Digital item.
  • "PHYSICAL": Physical item.
  • "CUSTOM_AMOUNT_ITEM": Item with a custom price.
  • "UNSPECIFIED": Type can't be classified due to an error.
options
Array<Option>
Line item options.
mediaItem
Media item.
customTextFields
Custom text.

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

MediaItem

An object representing a media item.

See Also

getCurrentCart( )

Syntax

type MediaItem = {
  mediaType: string
  url: string
  height: number
  width: number
}
MEMBERS
?
The properties of an object.
mediaType
string

Type of the media item. One of:

  • "IMAGE": Image item.
  • "UNSPECIFIED_MEDIA_TYPE_ITEM": Media item type can't be classified due to an error.
url
string
Media item URL.
height
number
Media item height.
width
number
Media item width.

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

Option

An object representing a line item option.

See Also

getCurrentCart( )

Syntax

type Option = {
  option: string
  selection: string
}
MEMBERS
?
The properties of an object.
option
string
Name of the product option.
selection
string
Selected option.

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

OrderTotals

An object representing an order's totals.

Syntax

type OrderTotals = {
  subtotal: number
  shipping: number
  tax: string
  discount: number
  total: number
  weight: number
  quantity: number
}
MEMBERS
?
The properties of an object.
subtotal
number
The subtotal of all the order's line items, excluding tax.
shipping
number
The total shipping price, including tax.
tax
string
The total amount of tax.
discount
number
The total calculated discount amount.
total
number
The total price.
weight
number
The total weight of the order's items.
quantity
number
The total quantity of the the order's line items.

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

An event when a new order is placed

// Place this code in the events.js file
// of your site's Backend section.

export function wixStores_onNewOrder(event) {
  let newOrderId = event.orderId;
  let totalPrice = event.totals.total;
}

/*  Full event object:
 *  {
 *    "orderId": "2cd413bd-ddea-4101-b122-e8b146fec05f",
 *    "number": "10005",
 *    "dateCreated": "2018-08-05T12:33:18.938Z",
 *    "buyerInfo": {
 *      "id": "6g004532-732d-829f-5kf9-f9rk42afpla04m",
 *      "identityType": "MEMBER",
 *      "email": "john.doe@somedomain.com",
 *      "firstName": "John",
 *      "lastName": "Doe",
 *      "phone": "5555555555"
 *    },
 *    "currency": "USD",
 *    "weightUnit": "LB",
 *    "totals": {
 *      "subtotal": 99.99,
 *      "shipping": 4.99,
 *      "tax": 8.87,
 *      "discount": 9.99,
 *      "total": 103.86,
 *      "weight": 1.37,
 *      "quantity": 2
 *    },
 *    "paymentStatus": "PAID",
 *    "fulfillmentStatus": "FULFILLED"
 *  }
 */

ProductOptionsAvailability

An object returned by the getProductOptionsAvailability() function representing the availability of a product.

See Also

getProductOptionsAvailability( )

Syntax

type ProductOptionsAvailability = {
  availableForPurchase: boolean
  productOptions: StoreProductOptions
  mainMedia: string
  mediaItems: Array<ImageItem> | Array<VideoItem>
  selectedVariant: ProductOptionsAvailabilitySelectedVariant
}
MEMBERS
?
The properties of an object.
availableForPurchase
boolean
Whether the product with the specified option choices is available for purchase.
productOptions
An object representing all the available options for a store product.
mainMedia
string
Main product media item (image or video) URL.
mediaItems
Array<ImageItem> | Array<VideoItem>
List of product media items.
selectedVariant
The variant of the product selected using the specified option choices if there is one.

ProductOptionsAvailabilitySelectedVariant

An object representing the product variant selected using the getProductOptionsAvailability() funtion.

See Also

getProductOptionsAvailability( ), ProductOptionsAvailability( )

Syntax

type ProductOptionsAvailabilitySelectedVariant = {
  sku: string
  currency: string
  price: number
  discountedPrice: number
  formattedPrice: string
  formattedDiscountedPrice: string
  visible: boolean
  inStock: boolean
  weight: number
}
MEMBERS
?
The properties of an object.
sku
string
Product variant stock keeping unit value.
currency
string
Product variant currency.
price
number
Product variant price.
discountedPrice
number
Discounted product variant price.
formattedPrice
string
Product variant price formatted with the currency.
formattedDiscountedPrice
string
Discounted product variant price formatted with the currency.
visible
boolean
Whether the product variant is shown in the store.
inStock
boolean
Whether the product variant is in stock.
weight
number
Product variant weight.

ShippingInfo

An object representing shipping information.

See Also

onCartCompleted( )

Syntax

type ShippingInfo = {
  shippingAddress: Address
  pickupInfo: Address
}
MEMBERS
?
The properties of an object.
shippingAddress(Optional)
Shipment address.
pickupInfo(Optional)
Pickup address.

Examples

Get the current site visitor's cart

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
  return wixStores.getCurrentCart();
}

/* Returned promise resolves to:
*
* {  
*   "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc",
*   "appliedCoupon": {
*     "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
*     "name": "Summer Sale",
*     "code": "SummerSale",
*     "discountValue": "$10.00",
*     "couponType": "MoneyOff"
*   },
*   "billingAddress": {
*     "firstName": "John",
*     "lastName": "Doe",
*     "email":"john.doe@somedomain.com",
*     "phone":"5555555",
*     "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*   },
*   "buyerNote": "This is a note from the buyer.",
*   "buyerInfo":{
*     "firstName": "John",
*     "lastName": "Doe",
*     "email": "john.doe@somedomain.com",
*     "phone": "5555555555",
*     "identityType": "CONTACT"
*   },
*   "status": "INCOMPLETE",
*   "currency": {  
*      "code": "USD",
*      "symbol": "$"
*   },
*   "shippingInfo": {  
*      "deliveryOption": "Free Shipping",
*      "shippingAddress": {  
*        "firstName": "John",
*        "lastName": "Doe",
*        "email":"john.doe@somedomain.com",
*        "phone":"5555555",
*        "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States"
*      },
*      "pickupDetails":null
*   },
*   "lineItems":[  
*     {  
*       "quantity": 1,
*       "price": 120,
*       "name": "A product",
*       "productId": "a668ef33-f5b8-6569-d04c-1d123be68441",
*       "totalPrice": 120,
*       "lineItemType": "PHYSICAL",
*       "customTextFields": [
*         "title": "Custom Field",
*         "value": "Custom value"
*       ],
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "21554345656",
*       "options": [ ],
*       "weight": 3
*     },
*     {  
*       "quantity": 1,
*       "price": 25,
*       "name": "Another product",
*       "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
*       "totalPrice": 25,
*       "lineItemType": "PHYSICAL",
*       "mediaItem": {  
*         "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000",
*         "type": "IMAGE"
*       },
*       "sku": "217537123517253",
*       "options": [  
*         {  
*           "option": "Size",
*           "selection": "Medium"
*         },
*         {  
*           "option": "Color",
*           "selection": "Black"
*         }
*       ],
*       "weight": 2
*     }
*   ],
*   "totals": {  
*      "discount": 0,
*      "quantity": 2,
*      "shipping": 0,
*      "subtotal": 145,
*      "tax": 0,
*      "total": 145,
*      "weight": 5
*   },
*   "weightUnit": "LB"
* }
*/

An event with shipping details when a shopping cart is completed

// Place this code in the events.js file
// of your site's Backend section.

export function wixStores_onCartCompleted(event) {
  let total = event.totals.total;
}

/* Full event object:
 * {
 *    "cartId": "6d158831-1510-44ae-a420-1483a4200852",
 *    "completedTime": "2019-02-27T12:08:16.160Z",
 *    "buyerInfo": {
 *       "id": "091a8443-ab85-480c-918b-777156358dfc",
 *       "firstName": "John",
 *       "lastName": "Doe"
 *       "email": "john.doe@somedomain.com",
 *       "phone": "5555555555",
 *       "identityType": "CONTACT"
 *    },
 *    "weightUnit": "LB",
 *    "buyerNote": "This is a note from the buyer.",
 *    "billingAddress": {
 *       "firstName": "John",
 *       "lastName": "Doe"
 *       "email": "john.doe@somedomain.com",
 *       "phone": "5555555555",
 *       "address": "235 W 23rd St, New York, NY 10011, USA"
 *    },
 *    "currency": {
 *       "currency": "USD",
 *       "symbol": "$"
 *    },
 *    "appliedCoupon": {
 *       "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
 *       "name": "Summer Sale",
 *       "code": "SummerSale",
 *       "discountValue": "$10.00",
 *       "couponType": "MoneyOff"
 *    },
 *    "totals": {
 *       "subtotal": 250,
 *       "discount": 10,
 *       "total": 240,
 *       "quantity": 2
 *    },
 *    "shippingInfo": {
 *      "billingAddress": {
 *         "firstName": "John",
 *         "lastName": "Doe"
 *         "email": "john.doe@somedomain.com",
 *         "phone": "5555555555",
 *         "address": "235 W 23rd St, New York, NY 10011, USA"
 *      },
 *    }
 * }
 */

An event with pickup details when a shopping cart is completed

// Place this code in the events.js file
// of your site's Backend section.

export function wixStores_onCartCompleted(event) {
  let total = event.totals.total;
}

/* Full event object:
 * {
 *    "cartId": "6d158831-1510-44ae-a420-1483a4200852",
 *    "completedTime": "2019-02-27T12:08:16.160Z",
 *    "buyerInfo": {
 *       "id": "091a8443-ab85-480c-918b-777156358dfc",
 *       "firstName": "John",
 *       "lastName": "Doe"
 *       "email": "john.doe@somedomain.com",
 *       "phone": "5555555555",
 *       "identityType": "CONTACT"
 *    },
 *    "weightUnit": "LB",
 *    "buyerNote": "This is a note from the buyer.",
 *    "billingAddress": {
 *       "firstName": "John",
 *       "lastName": "Doe"
 *       "email": "john.doe@somedomain.com",
 *       "phone": "5555555555",
 *       "address": "235 W 23rd St, New York, NY 10011, USA"
 *    },
 *    "currency": {
 *       "currency": "USD",
 *       "symbol": "$"
 *    },
 *    "appliedCoupon": {
 *       "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
 *       "name": "Summer Sale",
 *       "code": "SummerSale",
 *       "discountValue": "$10.00",
 *       "couponType": "MoneyOff"
 *    },
 *    "totals": {
 *       "subtotal": 250,
 *       "discount": 10,
 *       "total": 240,
 *       "quantity": 2
 *    },
 *    "shippingInfo": {
 *      "pickupDetails": {
 *         "firstName": "John",
 *         "lastName": "Doe"
 *         "email": "john.doe@somedomain.com",
 *         "phone": "5555555555",
 *         "address": "235 W 23rd St, New York, NY 10011, USA"
 *      },
 *    }
 * }
 */

StoreProductChoices

An object representing the selection of specific choices from the product's options.

See Also

getProductOptionsAvailability( )

Syntax

type StoreProductChoices = {
  optionKey: string
}
MEMBERS
?
The properties of an object.
optionKey
string

Value of the option. This key name is dependent on the options added to the product. For example, if a product has a size option, this key value will be something like "Size" and its value will be something like "Large".