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.
AbandonedCartAn object representing an abandoned shopping cart.
ActivityAn object representing a shopping cart activity.
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.
CustomDataAn object representing custom activity data.
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.
PagingOptionsAn object representing paging options.
ProductChoicesAn object representing the selection of specific choices from the product's options.
ProductOptionsAvailabilityAn object returned by the getProductOptionsAvailability() function representing the availability of a product.
ProductOptionsAvailabilitySelectedVariantAn object representing the product variant selected using the getProductOptionsAvailability() function.
ProductVariantOptions

An object representing the selection of specific variants of a product. Use only one of choices or variantIds.

ShippingInfoAn object representing shipping information.
VariantInfoAn object containing variant information.
VariantItemAn object representing a product variants.
VariantListAn object representing product variants.

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?

getAbandonedCart( )

Gets the current site visitor's shopping cart.

Description

The getAbandonedCart() function returns a Promise that resolves to the specified abandoned shopping cart.

Syntax

function getAbandonedCart(cartId: string): Promise<AbandonedCart>
PARAMETERS
?
Values that you pass to a function.
cartId
string
ID of the abandoned cart to get.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<AbandonedCart>
Fulfilled - The retrieved cart.

Examples

Get an abandoned cart

import wixStores from 'wix-stores-backend'

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

/* Returned promise resolves to:
 *
 * {
 *   "_id": "b5b63fe3-85f0-459a-b90f-7195ebc727f8",
 *   "abandonTime": "2019-06-19T12:20:14.998Z",
 *   "total": "$25.00",
 *   "buyerInfo": {
 *     "id": "f6c0f9c2-a02d-4e9f-a58d-99729af244d9",
 *     "firstName": "John",
 *     "lastName": "Doe",
 *     "email": "john.doe@somedomain.com",
 *     "phone": "5555555555",
 *     "identityType": "CONTACT"
 *   },
 *   "activities": [
 *    {
 *      "type":"EMAIL_SENT",
 *      "timestamp":"2019-11-10T13:57:23.356Z",
 *      "message":"email status has changed to: EMAIL_SENT",
 *      "customData":{ 
 *        "namespace":"wixstores_email_status"
 *      }
 *    }
 *   ],
 *   "status": "ABANDONED"
 * }
 */

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 ProductChoices 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: ProductChoices): 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 *
 ****************/

import wixStores from 'wix-stores-backend';

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

/********************
 * client-side code *
 ********************/
import {myBackendFunction} 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 *
 ****************/

import wixStores from 'wix-stores-backend';

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

/********************
 * client-side code *
 ********************/
import {myBackendFunction} 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
 * }
 */

getProductVariants( )

Gets a product's available variants based on the specified option choices.

Description

The getProductVariants() function returns a Promise that is resolved to a VariantList object when the product variants with the specified choices or variant IDs are retrieved.

Syntax

function getProductVariants(productId: string, options: ProductVariantOptions): Promise<VariantList>
PARAMETERS
?
Values that you pass to a function.
productId
string
The ID of the product whose variants are being retrieved.
options
Option to use when checking the product's variants.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<VariantList>
Fulfilled - The variants with the specified choices.

Examples

Get product variants by specified choices

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

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, options) {
  return wixStores.getProductVariants(productId, options);
}

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

// ...

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

myBackendFunction(productId, options)
  .then( (variants) => {
    let firstVariant = variants.items[0];
    let firstPrice = firstVariant.variant.price;
    let length = variants.length;
    let totalCount = variants.totalCount;
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * variants:
 *
 * { 
 *   "items": [ 
 *     { 
 *       "_id": "00000000-0000-03e1-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible": true
 *       }
 *     },
 *     { 
 *       "id": "00000000-0000-03e2-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Houndstooth"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible":true
 *       }
 *     }
 *   ],
 *   "length": 2,
 *   "totalCount": 2
 * }
 */

Get product variants by variant IDs

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

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, options) {
  return wixStores.getProductVariants(productId, options);
}

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

// ...

let productId = // get product ID
let options = {
  "variantIds": [
    "00000000-0000-03e1-0005-957f699d0688",
    "00000000-0000-03e2-0005-957f699d0688"
  ]
};

myBackendFunction(productId, options)
  .then( (variants) => {
    let firstVariant = variants.items[0];
    let firstPrice = firstVariant.variant.price;
    let length = variants.length;
    let totalCount = variants.totalCount;
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * variants:
 *
 * { 
 *   "items": [ 
 *     { 
 *       "_id": "00000000-0000-03e1-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible": true
 *       }
 *     },
 *     { 
 *       "id": "00000000-0000-03e2-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Houndstooth"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible":true
 *       }
 *     }
 *   ],
 *   "length": 2,
 *   "totalCount": 2
 * }
 */

Get product variants using paging options

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

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, options) {
  return wixStores.getProductVariants(productId, options);
}

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

// ...

let productId = // get product ID
let options = {
  "choices": {
    "Size": "Large"
  },
  "paging": {
    "limit": 2,
    "skip": 2 
  }
};

myBackendFunction(productId, options)
  .then( (variants) => {
    let firstVariant = variants.items[0];
    let firstPrice = firstVariant.variant.price;
    let length = variants.length;
    let totalCount = variants.totalCount;
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * variants:
 *
 * { 
 *   "items": [ 
 *     { 
 *       "_id": "00000000-0000-03e1-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible": true
 *       }
 *     },
 *     { 
 *       "id": "00000000-0000-03e2-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Blue",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible":true
 *       }
 *     }
 *   ],
 *   "length": 2,
 *   "totalCount": 6
 * }
 */

AbandonedCart

An object representing an abandoned shopping cart.

See Also

getAbandonedCart( )

Syntax

type AbandonedCart = {
  _id: string
  abandonTime: Date
  total: string
  buyerInfo: BuyerInfo
  activities: Activity
  status: string
}
MEMBERS
?
The properties of an object.
_id
string
Unique identifier of the shopping cart.
abandonTime
Date
Date and time the shopping cart was abandoned.
total
string
Total price of all items in the cart.
buyerInfo
The buyer's information.
activities
status
string
Status of the abandoned cart. Either "ABANDONED" or "RECOVERED".

Examples

Get an abandoned cart

import wixStores from 'wix-stores-backend'

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

/* Returned promise resolves to:
 *
 * {
 *   "_id": "b5b63fe3-85f0-459a-b90f-7195ebc727f8",
 *   "abandonTime": "2019-06-19T12:20:14.998Z",
 *   "total": "$25.00",
 *   "buyerInfo": {
 *     "id": "f6c0f9c2-a02d-4e9f-a58d-99729af244d9",
 *     "firstName": "John",
 *     "lastName": "Doe",
 *     "email": "john.doe@somedomain.com",
 *     "phone": "5555555555",
 *     "identityType": "CONTACT"
 *   },
 *   "activities": [
 *    {
 *      "type":"EMAIL_SENT",
 *      "timestamp":"2019-11-10T13:57:23.356Z",
 *      "message":"email status has changed to: EMAIL_SENT",
 *      "customData":{ 
 *        "namespace":"wixstores_email_status"
 *      }
 *    }
 *   ],
 *   "status": "ABANDONED"
 * }
 */

Activity

An object representing a shopping cart activity.

See Also

getAbandonedCart( )

Syntax

type Activity = {
  activityType: string
  message: string
  timestamp: Date
  customData: CustomData
}
MEMBERS
?
The properties of an object.
activityType
string

One of:

  • "CUSTOM_ACTIVITY"
  • "EMAIL_NOT_SENT"
  • "EMAIL_SENT"
  • "NOTIFICATION_SENT"
  • "SCHEDULED"
  • "TASK_CREATED"
  • "UNRECOGNIZED_TYPE"
message
string
Activity message.
timestamp
Date
Time activity occurred.
customData
Custom activity data.

Examples

Get an abandoned cart

import wixStores from 'wix-stores-backend'

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

/* Returned promise resolves to:
 *
 * {
 *   "_id": "b5b63fe3-85f0-459a-b90f-7195ebc727f8",
 *   "abandonTime": "2019-06-19T12:20:14.998Z",
 *   "total": "$25.00",
 *   "buyerInfo": {
 *     "id": "f6c0f9c2-a02d-4e9f-a58d-99729af244d9",
 *     "firstName": "John",
 *     "lastName": "Doe",
 *     "email": "john.doe@somedomain.com",
 *     "phone": "5555555555",
 *     "identityType": "CONTACT"
 *   },
 *   "activities": [
 *    {
 *      "type":"EMAIL_SENT",
 *      "timestamp":"2019-11-10T13:57:23.356Z",
 *      "message":"email status has changed to: EMAIL_SENT",
 *      "customData":{ 
 *        "namespace":"wixstores_email_status"
 *      }
 *    }
 *   ],
 *   "status": "ABANDONED"
 * }
 */

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
 *    }
 * }
 */

CustomData

An object representing custom activity data.

See Also

getAbandonedCart( )

Syntax

type CustomData = {
  namespace: string
  customValue: Object
}
MEMBERS
?
The properties of an object.
namespace
string
Activity namespace.
customValue
Object
JSON object containing custom data.

Examples

Get an abandoned cart

import wixStores from 'wix-stores-backend'

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

/* Returned promise resolves to:
 *
 * {
 *   "_id": "b5b63fe3-85f0-459a-b90f-7195ebc727f8",
 *   "abandonTime": "2019-06-19T12:20:14.998Z",
 *   "total": "$25.00",
 *   "buyerInfo": {
 *     "id": "f6c0f9c2-a02d-4e9f-a58d-99729af244d9",
 *     "firstName": "John",
 *     "lastName": "Doe",
 *     "email": "john.doe@somedomain.com",
 *     "phone": "5555555555",
 *     "identityType": "CONTACT"
 *   },
 *   "activities": [
 *    {
 *      "type":"EMAIL_SENT",
 *      "timestamp":"2019-11-10T13:57:23.356Z",
 *      "message":"email status has changed to: EMAIL_SENT",
 *      "customData":{ 
 *        "namespace":"wixstores_email_status"
 *      }
 *    }
 *   ],
 *   "status": "ABANDONED"
 * }
 */

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"
 *  }
 */

PagingOptions

An object representing paging options.

See Also

getProductVariants( )

Syntax

type PagingOptions = {
  limit: number
  skip: number
}
MEMBERS
?
The properties of an object.
limit
number
Maximum number of variants to retrieve. Defaults to 300.
skip
number
Number of variants to skip before the retrieved variants. Defaults to 0.

Examples

Get product variants using paging options

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

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, options) {
  return wixStores.getProductVariants(productId, options);
}

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

// ...

let productId = // get product ID
let options = {
  "choices": {
    "Size": "Large"
  },
  "paging": {
    "limit": 2,
    "skip": 2 
  }
};

myBackendFunction(productId, options)
  .then( (variants) => {
    let firstVariant = variants.items[0];
    let firstPrice = firstVariant.variant.price;
    let length = variants.length;
    let totalCount = variants.totalCount;
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * variants:
 *
 * { 
 *   "items": [ 
 *     { 
 *       "_id": "00000000-0000-03e1-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible": true
 *       }
 *     },
 *     { 
 *       "id": "00000000-0000-03e2-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Blue",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible":true
 *       }
 *     }
 *   ],
 *   "length": 2,
 *   "totalCount": 6
 * }
 */

ProductChoices

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

See Also

getProductOptionsAvailability( ), getProductVariants( )

Syntax

type ProductChoices = {
  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".

Examples

Get a product's availability information

/****************
 * backend code *
 ****************/

import wixStores from 'wix-stores-backend';

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

/********************
 * client-side code *
 ********************/
import {myBackendFunction} 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 product variants by specified choices

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

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, options) {
  return wixStores.getProductVariants(productId, options);
}

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

// ...

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

myBackendFunction(productId, options)
  .then( (variants) => {
    let firstVariant = variants.items[0];
    let firstPrice = firstVariant.variant.price;
    let length = variants.length;
    let totalCount = variants.totalCount;
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * variants:
 *
 * { 
 *   "items": [ 
 *     { 
 *       "_id": "00000000-0000-03e1-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible": true
 *       }
 *     },
 *     { 
 *       "id": "00000000-0000-03e2-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Houndstooth"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible":true
 *       }
 *     }
 *   ],
 *   "length": 2,
 *   "totalCount": 2
 * }
 */

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.

Examples

Get a product's availability information

/****************
 * backend code *
 ****************/

import wixStores from 'wix-stores-backend';

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

/********************
 * client-side code *
 ********************/
import {myBackendFunction} 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
 *     }
 *   ]
 * }
 */

ProductOptionsAvailabilitySelectedVariant

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

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.

Examples

Get a product's availability information

/****************
 * backend code *
 ****************/

import wixStores from 'wix-stores-backend';

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

/********************
 * client-side code *
 ********************/
import {myBackendFunction} 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
 * }
 */

ProductVariantOptions

An object representing the selection of specific variants of a product. Use only one of choices or variantIds.

See Also

getProductVariants( )

Syntax

type ProductVariantOptions = {
  choices: ProductChoices
  variantIds: Array<string>
  paging: PagingOptions
}
MEMBERS
?
The properties of an object.
choices
The choices the retrieved variants will have.
variantIds
Array<string>
IDs of variants to retrieve.
paging
Paging options.

Examples

Get product variants using paging options

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

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, options) {
  return wixStores.getProductVariants(productId, options);
}

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

// ...

let productId = // get product ID
let options = {
  "choices": {
    "Size": "Large"
  },
  "paging": {
    "limit": 2,
    "skip": 2 
  }
};

myBackendFunction(productId, options)
  .then( (variants) => {
    let firstVariant = variants.items[0];
    let firstPrice = firstVariant.variant.price;
    let length = variants.length;
    let totalCount = variants.totalCount;
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * variants:
 *
 * { 
 *   "items": [ 
 *     { 
 *       "_id": "00000000-0000-03e1-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible": true
 *       }
 *     },
 *     { 
 *       "id": "00000000-0000-03e2-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Blue",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible":true
 *       }
 *     }
 *   ],
 *   "length": 2,
 *   "totalCount": 6
 * }
 */

Get product variants by variant IDs

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

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, options) {
  return wixStores.getProductVariants(productId, options);
}

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

// ...

let productId = // get product ID
let options = {
  "variantIds": [
    "00000000-0000-03e1-0005-957f699d0688",
    "00000000-0000-03e2-0005-957f699d0688"
  ]
};

myBackendFunction(productId, options)
  .then( (variants) => {
    let firstVariant = variants.items[0];
    let firstPrice = firstVariant.variant.price;
    let length = variants.length;
    let totalCount = variants.totalCount;
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * variants:
 *
 * { 
 *   "items": [ 
 *     { 
 *       "_id": "00000000-0000-03e1-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible": true
 *       }
 *     },
 *     { 
 *       "id": "00000000-0000-03e2-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Houndstooth"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible":true
 *       }
 *     }
 *   ],
 *   "length": 2,
 *   "totalCount": 2
 * }
 */

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"
 *      },
 *    }
 * }
 */

VariantInfo

An object containing variant information.

See Also

getProductVariants( )

Syntax

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

Examples

Get product variants by specified choices

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

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, options) {
  return wixStores.getProductVariants(productId, options);
}

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

// ...

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

myBackendFunction(productId, options)
  .then( (variants) => {
    let firstVariant = variants.items[0];
    let firstPrice = firstVariant.variant.price;
    let length = variants.length;
    let totalCount = variants.totalCount;
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * variants:
 *
 * { 
 *   "items": [ 
 *     { 
 *       "_id": "00000000-0000-03e1-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible": true
 *       }
 *     },
 *     { 
 *       "id": "00000000-0000-03e2-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Houndstooth"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible":true
 *       }
 *     }
 *   ],
 *   "length": 2,
 *   "totalCount": 2
 * }
 */

VariantItem

An object representing a product variants.

See Also

getProductVariants( )

Syntax

type VariantItem = {
  _id: string
  choices: ProductChoices
  variant: VariantInfo
}
MEMBERS
?
The properties of an object.
_id
string
Unique variant ID.
choices
The choices of the retrieved variant.
variant
Variant information.

Examples

Get product variants by specified choices

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

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, options) {
  return wixStores.getProductVariants(productId, options);
}

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

// ...

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

myBackendFunction(productId, options)
  .then( (variants) => {
    let firstVariant = variants.items[0];
    let firstPrice = firstVariant.variant.price;
    let length = variants.length;
    let totalCount = variants.totalCount;
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * variants:
 *
 * { 
 *   "items": [ 
 *     { 
 *       "_id": "00000000-0000-03e1-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible": true
 *       }
 *     },
 *     { 
 *       "id": "00000000-0000-03e2-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Houndstooth"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible":true
 *       }
 *     }
 *   ],
 *   "length": 2,
 *   "totalCount": 2
 * }
 */

VariantList

An object representing product variants.

See Also

getProductVariants( )

Syntax

type VariantList = {
  items: Array<VariantItem>
  length: number
  totalCount: number
}
MEMBERS
?
The properties of an object.
items
List of variant items that match the specified choices or variant IDs.
length
number
Number of items in the current results page.
totalCount
number
Total number of variants with the specified choices.

Examples

Get product variants by specified choices

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

import wixStores from 'wix-stores-backend';

export function myBackendFunction(productId, options) {
  return wixStores.getProductVariants(productId, options);
}

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

// ...

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

myBackendFunction(productId, options)
  .then( (variants) => {
    let firstVariant = variants.items[0];
    let firstPrice = firstVariant.variant.price;
    let length = variants.length;
    let totalCount = variants.totalCount;
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * variants:
 *
 * { 
 *   "items": [ 
 *     { 
 *       "_id": "00000000-0000-03e1-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Paisley"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible": true
 *       }
 *     },
 *     { 
 *       "id": "00000000-0000-03e2-0005-957f699d0688",
 *       "choices": { 
 *         "Size": "Large",
 *         "Color": "Red",
 *         "Pattern": "Houndstooth"
 *       },
 *       "variant": { 
 *         "currency": "USD",
 *         "price": 25,
 *         "discountedPrice": 25,
 *         "formattedPrice": "$25.00",
 *         "formattedDiscountedPrice": "$25.00",
 *         "weight": 5,
 *         "sku":"217537123517253",
 *         "visible":true
 *       }
 *     }
 *   ],
 *   "length": 2,
 *   "totalCount": 2
 * }
 */