Introduction

Note: There is a new version of the Stores API. If you're already using Stores modules in your code, they will continue to work.

Before using the wix-stores-backend functions, set up your site for stores. To learn more, see Adding Wix Stores. When setting up your Wix Stores site, be sure to select the payment methods you want to offer and set your payment currency.

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

Copy
import wixStoresBackend from "wix-stores-backend";
Did this help?

addProductMedia( )


Adds media items by ID to a product.

The addProductMedia() function returns a Promise that resolves when the adding of the media (images or videos) to a product has started.

Limitation The URL is not validated and no event is triggered to indicate if the media was added successfully.

Method Declaration
Copy
function addProductMedia(productId: string, media: Array<Media>): Promise<void>;
Method Parameters
productIdstringRequired

Product ID.


mediaArray<Media>Required

Sources of media items already uploaded to the Wix site.

Add media items to a product
JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from 'wix-stores-backend'; export function addProductMedia(productId, mediaData) { return wixStoresBackend.addProductMedia(productId, mediaData); } /************* * Page code * *************/ import { addProductMedia } from 'backend/myModule'; // ... const productId = ...; // get product ID const src = "wix:image://v1/1a11a1_..._1a~mv2.jpg/1a11a1_..._1a~mv2.jpg"; const choice = "Color"; const option = "Blue"; if (choice !== "" && option !== "") { const mediaData = [{ // add media item to a choice src, "choice": { choice, option } }] } else { const mediaData = [{ // add media item to the product src }] } addProductMedia(productId, mediaData)
Errors

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

Did this help?

addProductMediaToChoices( )


Adds media items by ID to product options.

The addProductMediaToChoices() function returns a Promise that resolves when the adding of media (images or videos) to a product's options has started.

Method Declaration
Copy
function addProductMediaToChoices(
  productId: string,
  mediaChoices: Array<MediaChoice>,
): Promise<void>;
Method Parameters
productIdstringRequired

ID of the product with choices to which to add media items.


mediaChoicesArray<MediaChoice>Required

Product media items, and the choices to add the media to.

Note: Media must already be added to the product.

Add media items to product options
JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from 'wix-stores-backend'; export function addProductMediaToChoices(productId, mediaData) { return wixStoresBackend.addProductMediaToChoices(productId, mediaData); } /************* * Page code * *************/ import { addProductMediaToChoices } from 'backend/products'; // ... const productId = ...; // get product ID const mediaSources = ["wix:image://v1/1a11a1_..._1a~mv2.jpg/1a11a1_..._1a~mv2.jpg"]; const option = "Color"; const choice = "Blue"; const mediaData = [{ mediaSources, option, choice }]; addProductMediaToChoices(productId, mediaData)
Errors

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

Did this help?

addProductsToCollection( )


Adds products by ID to a product collection.

The addProductsToCollection() function returns a Promise that resolves when the products with the given IDs are added to a product collection with a given ID.

You can add multiple products to a collection at one time by delimiting the list of products with commas.

With this function, you can only add existing products to a collection. You cannot use the addProductsToCollection() function to create a product. See createProduct() to add a product to the store.

Method Declaration
Copy
function addProductsToCollection(
  collectionId: string,
  productIds: Array<string>,
): Promise<void>;
Method Parameters
collectionIdstringRequired

ID of the product collection to which to add products.


productIdsArray<string>Required

IDs of the products to add to the product collection, separated by commas.

Add products to a product collection
JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from 'wix-stores-backend'; export function addProductsToCollection(collectionId, productIds) { return wixStoresBackend.addProductsToCollection(collectionId, productIds); } /************* * Page code * *************/ import { addProductsToCollection } from 'backend/products'; // ... const collectionId = ... // get collection ID const productIds = ["id1", "id2", "id3"]; addProductsToCollection(collectionId, productIds) .then(() => { // products added to the collection }) .catch((error) => { // products not added to the collection });
Errors

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

Did this help?

bulkAdjustProductProperty( )


Adjusts a numeric property for up to 100 products at a time.

The bulkAdjustProductProperty() function returns a Promise that resolves when the property of the products have been adjusted.

A property can be increased or decreased either by percentage or amount. The properties that can be bulk-adjusted are detailed in the adjust object in the parameters section below.

Note: Do not pass important information from client-side code. Doing so opens a vulnerability that a malicious user can exploit to change information, such as a buyer’s personal details (address, email, etc.) or product price information. To learn more about how to keep your code secure, see Security Considerations When Working with Wix Code.

Method Declaration
Copy
function bulkAdjustProductProperty(
  ids: Array<string>,
  adjust: BulkAdjustProperties,
): Promise<BulkUpdateResponse>;
Method Parameters
idsArray<string>Required

IDs of the products to adjust.


adjustBulkAdjustPropertiesRequired

Numeric property to adjust.

Returns
Return Type:Promise<BulkUpdateResponse>
JavaScript
/************************************** * Backend code - my-backend-file.jsw * **************************************/ import wixStoresBackend from "wix-stores-backend"; export async function myBulkAdjustProductPropertyFunction(ids, adjust) { try { const productAdjustmentResults = await wixStoresBackend.bulkAdjustProductProperty(ids, adjust); console.log("Bulk action results:", productAdjustmentResults); return productAdjustmentResults; } catch (error) { console.error(error); // Handle the error } } /************* * Page code * *************/ import { myBulkAdjustProductPropertyFunction } from "backend/my-backend-file"; // Sample product IDs: const ids = [ "91f7ac8b-2baa-289c-aa50-6d64764f35d3", "0614129c-8777-9f3b-4dfe-b80a54df10d5", ]; // Increase the weight by 10 const adjust = { weight: { amount: 10, }, }; myBulkAdjustProductPropertyFunction(ids, adjust) .then((productAdjustmentResults) => { console.log("Bulk action results:", productAdjustmentResults); return productAdjustmentResults; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "results": [ * { * "itemMetadata": { * "_id": "91f7ac8b-2baa-289c-aa50-6d64764f35d3", * "originalIndex": 0, * "success": true * } * }, * { * "itemMetadata": { * "_id": "0614129c-8777-9f3b-4dfe-b80a54df10d5", * "originalIndex": 1, * "success": true * } * } * ], * "bulkActionMetadata": { * "totalSuccesses": 2, * "totalFailures": 0, * "undetailedFailures": 0 * } * } * */
Errors

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

Did this help?

bulkUpdateProductProperty( )


Updates a property for up to 100 products at a time.

The bulkUpdateProductProperty() function returns a Promise that resolves when the property of the products have been updated.

The properties that can be bulk-updated are detailed in the set object in the parameters section below.

Note: Do not pass important information from client-side code. Doing so opens a vulnerability that a malicious user can exploit to change information, such as a buyer’s personal details (address, email, etc.) or product price information. To learn more about how to keep your code secure, see Security Considerations When Working with Wix Code.

Method Declaration
Copy
function bulkUpdateProductProperty(
  ids: Array<string>,
  set: BulkUpdateProperties,
): Promise<BulkUpdateResponse>;
Method Parameters
idsArray<string>Required

IDs of the products to update.


setBulkUpdatePropertiesRequired

Property to update.

Returns
Return Type:Promise<BulkUpdateResponse>
JavaScript
/************************************** * Backend code - my-backend-file.jsw * **************************************/ import wixStoresBackend from "wix-stores-backend"; export async function myBulkUpdateProductPropertyFunction(ids, set) { try { const productUpdateResults = await wixStoresBackend.bulkUpdateProductProperty(ids, set); console.log("Bulk action results:", productUpdateResults); return productUpdateResults; } catch (error) { console.error(error); // Handle the error } } /************* * Page code * *************/ import { myBulkUpdateProductPropertyFunction } from "backend/my-backend-file"; // Sample product IDs: const ids = [ "bb6ddd51-7295-4fc8-8a4f-2521485c738d", "c36bbdbe-fbf8-4a43-810e-a0abdffe70ae", "2966543c-2b2f-4ca1-862c-6a04736c1063", "c9adb138-96f8-4f08-8626-9fef2445c490", "4ed1aa2c-c441-4e3f-8e57-a18886bf52bb", ]; // Set the price to 10.25 const set = { price: 10.25, }; myBulkUpdateProductPropertyFunction(ids, set) .then((productUpdateResults) => { console.log("Bulk action results:", productUpdateResults); return productUpdateResults; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "results": [ * {"itemMetadata": { * "id": "bb6ddd51-7295-4fc8-8a4f-2521485c738d", * "originalIndex": 0, * "success": true * }}, * {"itemMetadata": { * "id": "c36bbdbe-fbf8-4a43-810e-a0abdffe70ae", * "originalIndex": 1, * "success": true * }}, * {"itemMetadata": { * "id": "2966543c-2b2f-4ca1-862c-6a04736c1063", * "originalIndex": 2, * "success": true * }}, * {"itemMetadata": { * "id": "c9adb138-96f8-4f08-8626-9fef2445c490", * "originalIndex": 3, * "success": true * }}, * {"itemMetadata": { * "id": "4ed1aa2c-c441-4e3f-8e57-a18886bf52bb", * "originalIndex": 4, * "success": true * }} * ], * "bulkActionMetadata": { * "totalSuccesses": 5, * "totalFailures": 0, * "undetailedFailures": 0 * } * } * */
Errors

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

Did this help?

createFulfillment( )


Deprecated. This function will continue to work until September 4, 2024, but a newer version is available at wix-ecom-backend.OrderFulfillments.createFulfillment().

We recommend you migrate to the new Wix eCommerce APIs as soon as possible.

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-ecom-backend.OrderFulfillments.createFulfillment().

To migrate to the new function:

  1. Add the new import statement:

    Copy
    import { orderFulfillments } from "wix-ecom-backend";
  2. Look for any code that uses wixStoresBackend.createFulfillment(), and replace it with orderFulfillments.createFulfillment(). Update your code to work with the new createFulfillment() response properties.

  3. Test your changes to make sure your code behaves as expected.

Creates a new fulfillment in an order. The createFulfillment() function returns a Promise that is resolved to an object with the fulfillmentId and the updated Order when the fulfillment is created.

Method Declaration
Copy
function createFulfillment(
  orderId: string,
  fulfillment: FulfillmentInfo,
): Promise<NewFulfillmentAndOrder>;
Method Parameters
orderIdstringRequired

ID of the order to create the fulfillment in.


fulfillmentFulfillmentInfoRequired

Fulfillment information.

Returns
Return Type:Promise<NewFulfillmentAndOrder>
Create a new fulfillment
JavaScript
import wixStoresBackend from "wix-stores-backend"; const fulfillment = { lineItems: [{ index: 1, quantity: 1 }], trackingInfo: { shippingProvider: "fedex", trackingLink: "https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber=12345", trackingNumber: "12345", }, }; export function createFulfillment(orderId) { return wixStoresBackend .createFulfillment(orderId, fulfillment) .then((updatedOrder) => { // Fulfillment created const fulfillmentId = updatedOrder.id; const orderId = updatedOrder.order._id; const fulfillmentStatus = updatedOrder.order.fulfillmentStatus; }) .catch((error) => { // Fulfillment not created console.error(error); }); } /* Returns a promise that resolves to: * * { * "id": "75159953-1234-4490-9b4a-9301f9264427", * "order": { * "_id": "d5d43d01-d9a4-4cc2-b257-61184b881447", * "_updatedDate": "2020-05-27T12:20:37.994Z", * "buyerLanguage": "en", * "channelInfo": { * "type": "WEB" * }, * "enteredBy": { * "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9", * "identityType": "MEMBER" * }, * "billingInfo": { * "address": { * "formatted": "My company name\n235 W 23rd St\nNew York, New York 10011\nUnited States\n+15555555555", * "city": "New York", * "country": "USA", * "addressLine": "235 W 23rd St", * "postalCode": "10011", * "subdivision": "NY" * }, * "firstName": "John", * "lastName": "Doe", * "email": "john.doe@somedomain.com", * "phone": "+15555555555", * "company": "My company name", * "externalTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb", * "paidDate": "2020-05-27T12:20:37.994Z", * "paymentMethod": "VISA", * "paymentGatewayTransactionId": "29A06193U6234935D", * "paymentProviderTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb" * }, * "buyerInfo": { * "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9", * "identityType": "MEMBER", * "firstName": "John", * "lastName": "Doe", * "phone": "+15555555555", * "email": "john.doe@somedomain.com" * }, * "_dateCreated": "2020-05-27T12:20:37.966Z", * "currency": "ILS", * "fulfillmentStatus": "FULFILLED", * "archived": false, * "activities": [ * { * "type": "ORDER_PLACED", * "timestamp": "2020-05-27T12:20:37.966Z" * }, * { * "type": "ORDER_PAID", * "timestamp": "2020-05-27T12:20:37.994Z" * } * ], * "number": 10019, * "paymentStatus": "PAID", * "shippingInfo": { * "deliveryOption": "Free Shipping", * "estimatedDeliveryTime": "4:30pm", * "shippingRegion": "Domestic", * "shipmentDetails": { * "address": { * "formatted": "company name\n235 W 23rd St\nNew York, New York 10011\nUnited States\n5555555555", * "city": "New York", * "country": "USA", * "addressLine": "235 W 23rd St", * "postalCode": "10011", * "subdivision": "NY" * }, * "firstName": "John", * "lastName": "Doe", * "email": "john.doe@somedomain.com", * "phone": "5555555555", * "company": "company name", * "tax": 0, * "discount": 0, * "priceData": null * }, * "pickupDetails": null * }, * "lineItems": [ * { * "index": 1, * "quantity": 1, * "price": 5, * "name": "my product's name", * "translatedName": "Nombre traducido", * "productId": "3fb6a3c8-988b-8755-04bd-5c59ae0b18ea", * "totalPrice": 5, * "lineItemType": "PHYSICAL", * "options": [ * { * "option": "Size", * "selection": "Medium" * } * ], * "customTextFields": [ * { * "title": "Notes for delivery", * "value": "Please leave at front door" * } * ], * "weight": 1.42, * "sku": "36523641234523", * "discount": 0, * "tax": 5, * "taxIncludedInPrice": true, * "priceData": { * "price": "5", * "totalPrice": 5, * "taxIncludedInPrice": true * }, * "mediaItem": null * } * ], * "totals": { * "discount": 0, * "quantity": 1, * "shipping": 0, * "subtotal": 5, * "tax": 0, * "total": 5, * "weight": 1.42 * }, * "weightUnit": "KG", * "customField": { * "value": "Please call when outside", * "title": "Notes for delivery", * "translatedTitle": "Notas de entrega" * }, * "fulfillments": [ * { * "id": "cfbc5122-8766-4209-8bf4-611a10f9c546", * "dateCreated": "2020-06-10T15:38:10.938Z", * "lineItems": [ * { * "index": 1, * "quantity": 1 * } * ], * "trackingInfo": { * "trackingNumber": "12345", * "shippingProvider": "fedex", * "trackingLink": "https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber=12345" * }, * } * ], * "discount": null * } * } * */
Errors

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

Did this help?

createOrder( )


Deprecated. This function will continue to work until September 4, 2024, but a newer version is available at wix-ecom-backend.Orders.createOrder().

We recommend you migrate to the new Wix eCommerce APIs as soon as possible.

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-ecom-backend.Orders.createOrder().

To migrate to the new function:

  1. Add the new import statement:

    Copy
    import { orders } from "wix-ecom-backend";
  2. Look for any code that uses wixStoresBackend.createOrder(), and replace it with orders.createOrder(). Update your code to work with the new createOrder() response properties.

  3. Test your changes to make sure your code behaves as expected.

Creates a new order.

The createOrder() function returns a Promise that resolves to an Order object when the order has been created.

Note: Do not pass important information from client-side code. Doing so opens a vulnerability that a malicious user can exploit to change information, such as a buyer’s personal details (address, email, etc.) or product price information. To learn more about how to keep your code secure, see Security Considerations When Working with Wix Code.

Method Declaration
Copy
function createOrder(orderInfo: OrderInfo): Promise<Order>;
Method Parameters
orderInfoOrderInfoRequired

The information for the order being created.

Returns
Return Type:Promise<Order>
JavaScript
/************** * Page code * **************/ import { createOrder } from "backend/orders"; createOrder() .then((order) => { // Order created const newOrderId = order._id; const buyerEmail = order.buyerInfo.email; }) .catch((error) => { // Order not created console.error(error); }); /***************************** * Backend code - orders.jsw * *****************************/ import wixStoresBackend from "wix-stores-backend"; export function createOrder() { return wixStoresBackend.createOrder(fullOrder); } const fullOrder = { buyerLanguage: "en", cartId: "055e1808-b236-48dc-94d5-45288e06ef9c", currency: "USD", weightUnit: "KG", billingInfo: { address: { formatted: "235 W 23rd St New York, NY 10011, USA", city: "New York", country: "US", addressLine: "235 W 23rd St", postalCode: "10011", subdivision: "NY", }, lastName: "Doe", firstName: "John", email: "john.doe@somedomain.com", phone: "+15555555555", company: "My company name", paymentMethod: "VISA", paymentGatewayTransactionId: "29A06193U6234935D", paymentProviderTransactionId: "7c03ca74-eaf5-4541-8678-9b857634fdcb", }, totals: { subtotal: 5, total: 5, shipping: 0, }, channelInfo: { type: "WEB", }, paymentStatus: "PAID", shippingInfo: { deliverByDate: "2019-06-23T13:58:47.871Z", deliveryOption: "Free Shipping", shippingRegion: "Domestic", estimatedDeliveryTime: "4:30pm", shipmentDetails: { address: { formatted: "235 W 23rd St, New York, NY 10011, USA", city: "New York", country: "US", addressLine: "235 W 23rd St", postalCode: "10011", subdivision: "NY", }, lastName: "Doe", firstName: "John", email: "john.doe@somedomain.com", phone: "5555555555", company: "company name", shipmentPriceData: { price: 5, taxIncludedInPrice: false, }, }, }, lineItems: [ { customTextFields: [ { title: "Notes for delivery", value: "Please leave at front door", }, ], productId: "3fb6a3c8-988b-8755-04bd-5c59ae0b18ea", lineItemType: "PHYSICAL", mediaItem: { altText: "This is a description of the image", src: "wix:image://v1/689fa9...ccdc8a.jpg/file.jpg#originWidth=5760&originHeight=3840", }, name: "my product's name", options: [ { option: "Size", selection: "Medium", }, ], quantity: 1, sku: "36523641234523", weight: 1.42, translatedName: "Nombre traducido", discount: 0, tax: 5, priceData: { price: 5, taxIncludedInPrice: true, }, }, ], customField: { title: "Notes for delivery", translatedTitle: "Notas de entrega", value: "Please call when outside", }, discount: { appliedCoupon: { code: "47d259d6-7d1e-4ea5-a75c79ca9bb1", couponId: "d293d777-5aad-4f70-aa91-36c7c5f16740", name: "Summer sale", }, }, }; /* Example of returned order object * * { * "_id": "d5d43d01-d9a4-4cc2-b257-61184b881447", * "_updatedDate": "2020-05-27T12:20:37.994Z", * "buyerLanguage": "en", * "cartId": "055e1808-b236-48dc-94d5-45288e06ef9c", * "channelInfo": { * "type": "WEB" * }, * "enteredBy": { * "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9", * "identityType": "MEMBER" * }, * "billingInfo": { * "address": { * "formatted": "My company name\n235 W 23rd St\nNew York, New York 10011\nUnited States\n+15555555555", * "city": "New York", * "country": "USA", * "addressLine": "235 W 23rd St", * "postalCode": "10011", * "subdivision": "NY" * }, * "firstName": "John", * "lastName": "Doe", * "email": "john.doe@somedomain.com", * "phone": "+15555555555", * "company": "My company name", * "externalTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb", * "paidDate": "2020-05-27T12:20:37.994Z", * "paymentMethod": "VISA", * "paymentGatewayTransactionId": "29A06193U6234935D", * "paymentProviderTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb" * }, * "buyerInfo": { * "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9", * "identityType": "MEMBER", * "firstName": "John", * "lastName": "Doe", * "phone": "+15555555555", * "email": "john.doe@somedomain.com" * }, * "_dateCreated": "2020-05-27T12:20:37.966Z", * "currency": "ILS", * "fulfillmentStatus": "NOT_FULFILLED", * "archived": false, * "activities": [ * { * "type": "ORDER_PLACED", * "timestamp": "2020-05-27T12:20:37.966Z" * }, * { * "type": "ORDER_PAID", * "timestamp": "2020-05-27T12:20:37.994Z" * } * ], * "number": 10019, * "paymentStatus": "PAID", * "shippingInfo": { * "deliveryOption": "Free Shipping", * "estimatedDeliveryTime": "4:30pm", * "shippingRegion": "Domestic", * "shipmentDetails": { * "address": { * "formatted": "company name\n235 W 23rd St\nNew York, New York 10011\nUnited States\n5555555555", * "city": "New York", * "country": "USA", * "addressLine": "235 W 23rd St", * "postalCode": "10011", * "subdivision": "NY" * }, * "firstName": "John", * "lastName": "Doe", * "email": "john.doe@somedomain.com", * "phone": "5555555555", * "company": "company name", * "tax": 0, * "discount": 0, * "priceData": null * }, * "pickupDetails": null * }, * "lineItems": [ * { * "index": 1, * "quantity": 1, * "price": 5, * "name": "my product's name", * "translatedName": "Nombre traducido", * "productId": "3fb6a3c8-988b-8755-04bd-5c59ae0b18ea", * "totalPrice": 5, * "lineItemType": "PHYSICAL", * "options": [ * { * "option": "Size", * "selection": "Medium" * } * ], * "customTextFields": [ * { * "title": "Notes for delivery", * "value": "Please leave at front door" * } * ], * "weight": 1.42, * "sku": "36523641234523", * "discount": 0, * "tax": 5, * "taxIncludedInPrice": true, * "priceData": { * "price": 5, * "totalPrice": 5, * "taxIncludedInPrice": true * }, * "mediaItem": { * "altText": "This is a description of the image", * "id": "fac9dc352bf7d54ed0458d64ce41a3ec.jpg", * "src": "wix:image://v1/fac9dc352bf7d54ed0458d64ce41a3ec.jpg/file.jpg#originWidth=1348&originHeight=899", * "type": "IMAGE" * } * } * ], * "totals": { * "discount": 0, * "quantity": 1, * "shipping": 0, * "subtotal": 5, * "tax": 0, * "total": 5, * "weight": 1.42 * }, * "weightUnit": "KG", * "customField": { * "value": "Please call when outside", * "title": "Notes for delivery", * "translatedTitle": "Notas de entrega" * }, * "discount": { * "appliedCoupon": { * "code": "47d259d6-7d1e-4ea5-a75c79ca9bb1", * "couponId": "d293d777-5aad-4f70-aa91-36c7c5f16740", * "name": "Summer sale" * } * } * } * */
Errors

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

Did this help?

createProduct( )


Creates a new product.

The createProduct() function receives a ProductInfo object and returns a Promise that resolves to a Product object when the product has been created.

Creating a product is the first step in the process of enabling visitors to buy your products. After you create a product, you can add choices and variants to the product.

Notes:

  • If you create a product immediately before adding it to the cart, we suggest setting a timeout for "1000" milliseconds (1 second) before calling wix-stores.cart.addProducts(). While this slows down the operation slightly, it also ensures proper retrieval of the newly created product before adding it to the cart.
  • Do not pass important information from client-side code. Doing so opens a vulnerability that a malicious user can exploit to change information, such as a buyer’s personal details (address, email, etc.) or product price information. To learn more about how to keep your code secure, see Security Considerations When Working with Wix Code.
Method Declaration
Copy
function createProduct(productInfo: ProductInfo): Promise<Product>;
Method Parameters
productInfoProductInfoRequired

Information for the product being created.

Returns
Return Type:Promise<Product>
JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from "wix-stores-backend"; export function createProduct(myProduct) { return wixStoresBackend.createProduct(myProduct); } /************* * Page code * *************/ import { createProduct } from "backend/products"; // ... const myProduct = { name: "Colombian Arabica", description: "The best organic coffee that Colombia has to offer.", price: 35, pricePerUnitData: { totalQuantity: 100, totalMeasurementUnit: "G", baseQuantity: 1, baseMeasurementUnit: "G", }, sku: "Colombian-001", visible: true, discount: { type: "AMOUNT", value: "5", }, productOptions: { Weight: { choices: [ { value: "250g", description: "250g", }, { value: "500g", description: "500g", }, ], }, }, manageVariants: true, productType: "physical", weight: 250, ribbon: "Organic", brand: "Coffee Company", seoData: { tags: [ { type: "title", children: "Colombian Arabica", custom: false, disabled: false, }, { type: "meta", props: { name: "description", content: "The best organic coffee that Colombia has to offer.", }, custom: false, disabled: false, }, ], }, }; createProduct(myProduct) .then((product) => { // product created const productId = product._id; const description = product.description; }) .catch((error) => { // product not created console.error(error); }); /* Example of returned product object * * { * "_id": "3ceafef8-7f07-413b-8f72-0229049fab19", * "_updatedDate": "Mon Feb 15 2021 17:03:18 GMT+0200 (Israel Standard Time)", * "name": "Colombian Arabica", * "description": "The best organic coffee that Colombia has to offer.", * "mainMedia": "wix:image://v1/614034_103e8f4ab0ae4536a38b319d3eb437ed~mv2.png/missing-media.png#originWidth=500&originHeight=500", * "mediaItems": [], * "ribbon": "Organic", * "brand": "Coffee Company" * "currency": "USD", * "price": 35, * "discountedPrice": 30, * "formattedPrice": "$35.00", * "formattedDiscountedPrice": "$30.00", * "pricePerUnit": 0.3, * "formattedPricePerUnit": "$0.30", * "pricePerUnitData": { * "totalQuantity": 100, * "totalMeasurementUnit": "G", * "baseQuantity": 1, * "baseMeasurementUnit": "G" * }, * "inventoryItemId": "c3150107-80f8-bec4-708d-fdd6fb6054e6", * "discount": { * "type": "AMOUNT", * "value": 5 * }, * "trackInventory": false, * "inStock": true, * "additionalInfoSections": [], * "productOptions": { * "Weight": { * "optionType": "drop_down", * "name": "Weight", * "choices": [ * { * "value": "250g", * "description": "250g", * "inStock": true, * "visible": true, * "mainMedia": "null", * "mediaItems": [] * }, * { * "value": "500g", * "description": "500g", * "inStock": true, * "visible": true, * "mainMedia": "null", * "mediaItems": [] * } * ] * } * }, * "productPageUrl": "/product-page/colombian-arabica", * "customTextFields": [], * "manageVariants": true, * "productType": "physical", * "slug": "colombian-arabica", * "seoData": { * "tags": [ * { * "type": "title", * "children": "Colombian Arabica", * "custom": false, * "disabled": false * }, * { * "type": "meta", * "props": { * "name": "description", * "content": "The best organic coffee that Colombia has to offer." * }, * "children": "", * "custom": false, * "disabled": false * } * ] * }, * "variants": [ * { * "_id": "33599a3c-73a6-4532-9786-8d70f096d669", * "choices": { * "Weight": "250g" * }, * "variant": { * "currency": "USD", * "price": 35, * "discountedPrice": 30, * "pricePerUnit": 0.3, * "formattedPrice": "$35.00", * "formattedDiscountedPrice": "$35.00", * "formattedPricePerUnit": "$0.30", * "weight": 250, * "sku": "Colombian-001", * "visible": true * } * }, * { * "_id": "4cf12a28-d493-47b1-8475-f45b043ac683", * "choices": { * "Weight": "500g" * }, * "variant": { * "currency": "USD", * "price": 35, * "discountedPrice": 30, * "pricePerUnit": 0.3, * "formattedPrice": "$35.00", * "formattedDiscountedPrice": "$35.00", * "formattedPricePerUnit": "$0.30", * "weight": 250, * "sku": "Colombian-001", * "visible": true * } * } * ] * } * */
Errors

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

Did this help?

decrementInventory( )


Subtracts a set number of items from inventory.

The decrementInventory() function returns a Promise that is resolved when the specified item's quantity has been updated in the inventory.

Method Declaration
Copy
function decrementInventory(items: Array<DecrementInfo>): Promise<void>;
Method Parameters
itemsArray<DecrementInfo>Required

Inventory items to decrement.

Decrement the inventory of a product's first variant
JavaScript
/******************************* * Backend code - inventory.jsw * *******************************/ import wixStoresBackend from "wix-stores-backend"; export function decrementInventory(decrementInfo) { return wixStoresBackend.decrementInventory(decrementInfo); } /************** * Page code * **************/ import { decrementInventory } from "backend/inventory"; async function decrementHandler() { const productId = "3fb6a3c8-988b-8755-04bd-ks75ae0b18ea"; let variants = await getProductVariants(productId); decrementInventory([ { variantId: variants[0]._id, productId: productId, decrementBy: 1, }, ]) .then(() => { console.log("Inventory decremented successfully"); }) .catch((error) => { // Inventory decrement failed console.error(error); }); }
Errors

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

Did this help?

deleteFulfillment( )


Deprecated. This function will continue to work until September 4, 2024, but a newer version is available at wix-ecom-backend.OrderFulfillments.deleteFulfillment().

We recommend you migrate to the new Wix eCommerce APIs as soon as possible.

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-ecom-backend.OrderFulfillments.deleteFulfillment().

To migrate to the new function:

  1. Add the new import statement:

    Copy
    import { orderFulfillments } from "wix-ecom-backend";
  2. Look for any code that uses wixStoresBackend.deleteFulfillment(), and replace it with orderFulfillments.deleteFulfillment(). Update your code to work with the new deleteFulfillment() response properties.

  3. Test your changes to make sure your code behaves as expected.

Deletes a fulfillment from an order.

The deleteFulfillment() function returns a Promise that is resolved to an updated Order object when the specified fulfillment is deleted from the order.

Method Declaration
Copy
function deleteFulfillment(
  orderId: string,
  fulfillmentId: string,
): Promise<Order>;
Method Parameters
orderIdstringRequired

ID of the order to delete the fulfillment from.


fulfillmentIdstringRequired

ID of the fulfillment to delete.

Returns
Return Type:Promise<Order>
Delete a fulfillment
JavaScript
import wixStoresBackend from "wix-stores-backend"; export function deleteFulfillment(orderId, fulfillmentId) { return wixStoresBackend .deleteFulfillment(orderId, fulfillmentId) .then((updatedOrderObject) => { // Fulfillment deleted const orderFulfillmentStatus = updatedOrderObject.fulfillmentStatus; }) .catch((error) => { // Fulfillment not deleted }); } /* Returns a promise that resolves to: * * { * "order": { * "_id": "d5d43d01-d9a4-4cc2-b257-61184b881447", * "_updatedDate": "2020-06-16T12:39:10.399Z", * "buyerLanguage": "en", * "channelInfo": { * "type": "WEB" * }, * "enteredBy": { * "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9", * "identityType": "MEMBER" * }, * "billingInfo": { * "address": { * "formatted": "My company name\n235 W 23rd St\nNew York, New York 10011\nUnited States\n+15555555555", * "city": "New York", * "country": "USA", * "addressLine": "235 W 23rd St", * "postalCode": "10011", * "subdivision": "NY" * }, * "firstName": "John", * "lastName": "Doe", * "email": "john.doe@somedomain.com", * "phone": "+15555555555", * "company": "My company name", * "externalTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb", * "paidDate": "2020-05-27T12:20:37.994Z", * "paymentMethod": "VISA", * "paymentGatewayTransactionId": "29A06193U6234935D", * "paymentProviderTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb" * }, * "buyerInfo": { * "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9", * "identityType": "MEMBER", * "firstName": "John", * "lastName": "Doe", * "phone": "+15555555555", * "email": "john.doe@somedomain.com" * }, * "_dateCreated": "2020-05-27T12:20:37.966Z", * "currency": "ILS", * "fulfillmentStatus": "NOT_FULFILLED", * "archived": false, * "activities": [ * { * "type": "ORDER_PLACED", * "timestamp": "2020-05-27T12:20:37.966Z" * }, * { * "type": "ORDER_PAID", * "timestamp": "2020-05-27T12:20:37.994Z" * } * ], * "number": 10019, * "paymentStatus": "PAID", * "shippingInfo": { * "deliveryOption": "Free Shipping", * "estimatedDeliveryTime": "4:30pm", * "shippingRegion": "Domestic", * "shipmentDetails": { * "address": { * "formatted": "company name\n235 W 23rd St\nNew York, New York 10011\nUnited States\n5555555555", * "city": "New York", * "country": "USA", * "addressLine": "235 W 23rd St", * "postalCode": "10011", * "subdivision": "NY" * }, * "firstName": "John", * "lastName": "Doe", * "email": "john.doe@somedomain.com", * "phone": "5555555555", * "company": "company name", * "tax": 0, * "discount": 0, * "priceData": null * }, * "pickupDetails": null * }, * "lineItems": [ * { * "index": 1, * "quantity": 1, * "price": 5, * "name": "my product's name", * "translatedName": "Nombre traducido", * "productId": "3fb6a3c8-988b-8755-04bd-5c59ae0b18ea", * "totalPrice": 5, * "lineItemType": "PHYSICAL", * "options": [ * { * "option": "Size", * "selection": "Medium" * } * ], * "customTextFields": [ * { * "title": "Notes for delivery", * "value": "Please leave at front door" * } * ], * "weight": 1.42, * "sku": "36523641234523", * "discount": 0, * "tax": 5, * "taxIncludedInPrice": true, * "priceData": { * "price": "5", * "totalPrice": 5, * "taxIncludedInPrice": true * }, * "mediaItem": null * } * ], * "totals": { * "discount": 0, * "quantity": 1, * "shipping": 0, * "subtotal": 5, * "tax": 0, * "total": 5, * "weight": 1.42 * }, * "weightUnit": "KG", * "customField": { * "value": "Please call when outside", * "title": "Notes for delivery", * "translatedTitle": "Notas de entrega" * }, * "fulfillments": [], * "discount": null * } * } * */
Errors

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

Did this help?

deleteProduct( )


Deletes an existing product.

The deleteProduct() function returns a Promise that resolves when the product with the given ID is deleted.

Method Declaration
Copy
function deleteProduct(productId: string): Promise<void>;
Method Parameters
productIdstringRequired

ID of the product to delete.

Delete a product by ID
JavaScript
import wixStoresBackend from "wix-stores-backend"; export function deleteProduct(productId) { wixStoresBackend .deleteProduct(productId) .then(() => { // product has been deleted }) .catch((err) => { // there was an error deleting the product }); }
Errors

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

Did this help?

deleteProductOptions( )


Deletes all options for an existing product.

The deleteProductOptions() function returns a Promise that resolves when the options for the product with the given ID are deleted.

Method Declaration
Copy
function deleteProductOptions(productId: string): Promise<void>;
Method Parameters
productIdstringRequired

ID of the product with options to delete.

Delete the options for a product
JavaScript
import wixStoresBackend from "wix-stores-backend"; export function deleteProductOptions(productId) { wixStoresBackend .deleteProductOptions(productId) .then(() => { // product options have been deleted }) .catch((err) => { // there was an error deleting the options }); }
Errors

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

Did this help?

getCurrentCart( )


Deprecated. This function will continue to work until September 4, 2024, but a newer version is available at wix-ecom-backend.CurrentCart.getCurrentCart().

We recommend you migrate to the new Wix eCommerce APIs as soon as possible.

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-ecom-backend.CurrentCart.getCurrentCart().

To migrate to the new function:

  1. Add the new import statement:

    Copy
    import { currentCart } from "wix-ecom-backend";
  2. Look for any code that uses wixStoresBackend.getCurrentCart(), and replace it with currentCart.getCurrentCart(). Update your code to work with the new getCurrentCart() response properties. For more info about the differences between the Stores Cart and eCommerce Cart, refer to the cart conversion table.

  3. Test your changes to make sure your code behaves as expected.

Gets the current site visitor's shopping cart.

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

Note: When editing a site as a collaborator, getCurrentCart() will only work when viewing the live site.

Method Declaration
Copy
function getCurrentCart(): Promise<Cart>;
Request
This method does not take any parameters
Returns
Return Type:Promise<Cart>
Get the current site visitor's cart

This example uses a deprecated function.

JavaScript
import wixStoresBackend from "wix-stores-backend"; export function getCurrentCart() { return wixStoresBackend.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, * "id": 1 * }, * { * "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, * "id": 2 * } * ], * "totals": { * "discount": 0, * "quantity": 2, * "shipping": 0, * "subtotal": 145, * "tax": 0, * "total": 145, * "weight": 5 * }, * "weightUnit": "LB" * } */
Errors

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

Did this help?



getProductOptionsAvailability( )


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

The getProductOptionsAvailability() function returns a Promise that is resolved to a ProductOptionsAvailability object when the product's availability information 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.

Method Declaration
Copy
function getProductOptionsAvailability(
  productId: string,
  choices: ProductChoices,
): Promise<ProductOptionsAvailability>;
Method Parameters
productIdstringRequired

The ID of the product whose availability is being checked.


choicesProductChoicesRequired

Option choices to use when checking the product's availability.

Returns
Return Type:Promise<ProductOptionsAvailability>

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.

JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from 'wix-stores-backend'; export function getProductOptionsAvailability(productId, choices) { return wixStoresBackend.getProductOptionsAvailability(productId, choices); } /************* * Page code * *************/ import { getProductOptionsAvailability } from 'backend/products'; // ... let productId = // get product ID; let choices = { "Size": "Large" }; getProductOptionsAvailability(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 * } * ] * } */
Errors

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

Did this help?

getProductVariants( )


Gets a product's available variants based on the specified product ID and either option choices or variant IDs.

The getProductVariants() function returns a Promise that is resolved to an array of VariantItem objects when the product variants with the specified choices or variant IDs are retrieved.

Method Declaration
Copy
function getProductVariants(
  productId: string,
  options: ProductVariantOptions,
): Promise<Array<VariantItem>>;
Method Parameters
productIdstringRequired

The ID of the product whose variants are being retrieved. Pass only this field to retrieve all the specified product's variants.


optionsProductVariantOptions

Variant options to return. If not specified, all the product's variants are returned.

Returns
Return Type:Promise<Array<VariantItem>>
JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from "wix-stores-backend"; export function getProductVariants(productId, options) { return wixStoresBackend.getProductVariants(productId, options); } /************* * Page code * *************/ import { getProductVariants } from "backend/products"; let productId = "3fb6a3c8-988b-7895-04bd-5c59ae0b18ea"; // get product ID let options = { choices: { Size: "Large", Color: "Red", }, }; getProductVariants(productId, options) .then((variants) => { let firstVariant = variants[0]; let firstPrice = firstVariant.variant.price; let numberOfReturnedVariants = variants.length; }) .catch((error) => { console.error(error); }); /* Example of returned variants array: * * [ * { * "_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", * "pricePerUnit": 0.25, * "formattedPricePerUnit": "$0.25", * "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", * "pricePerUnit": 0.25, * "formattedPricePerUnit": "$0.25", * "weight": 5, * "sku": "217537123517253", * "visible": true * } * } * ] * */
Errors

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

Did this help?

incrementInventory( )


Adds a set number of items from inventory.

The incrementInventory() function returns a Promise that is resolved when the specified item's quantity has been updated in the inventory.

Method Declaration
Copy
function incrementInventory(items: Array<IncrementInfo>): Promise<void>;
Method Parameters
itemsArray<IncrementInfo>Required

Inventory items to increment.

Increment the inventory of a product's first variant
JavaScript
/******************************* * Backend code - inventory.jsw * *******************************/ import wixStoresBackend from "wix-stores-backend"; export function incrementInventory(incrementInfo) { return wixStoresBackend.incrementInventory(incrementInfo); } /************** * Page code * **************/ import { incrementInventory } from "backend/inventory"; async function incrementHandler() { const productId = "3fb6a3c8-988b-8755-04bd-ks75ae0b18ea"; let variants = await getProductVariants(productId); incrementInventory([ { variantId: variants[0]._id, productId: productId, incrementBy: 1, }, ]) .then(() => { console.log("Inventory incremented successfully"); }) .catch((error) => { // Inventory increment failed console.error(error); }); }
Errors

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

Did this help?

removeProductMedia( )


Removes media items by ID from a product.

The removeProductMedia() function returns a Promise that resolves when the media items with the given IDs are removed from a product with a given ID. You can remove multiple media items from a product at one time by delimiting the list of products with commas.

If you do not specify any media IDs, all media items are removed from the product.

Removing media items from a product does not delete the media from the site.

Method Declaration
Copy
function removeProductMedia(
  productId: string,
  media: Array<Media>,
): Promise<void>;
Method Parameters
productIdstringRequired

ID of the product from which to remove media items.


mediaArray<Media>Required

Sources of media items already uploaded to the Wix site. If no media is specified, all media items are removed from the product.

Remove all media items from a product
JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from 'wix-stores-backend'; export function removeProductMedia(productId, media) { return wixStoresBackend.removeProductMedia(productId, media); } /************* * Page code * *************/ import wixData from 'wix-data'; import { removeProductMedia } from 'backend/products'; // ... const productName = ...; // get name of product wixData.query("Stores/Products") .eq("name", productName) .find() .then((results) => { if (results.items.length > 0) { const productId = results.items[0]._id; removeProductMedia(productId) // not passing media will remove all media from product .then(() => { // all media items removed from the product }) .catch((error) => { // media items not removed from the product }); } });
Errors

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

Did this help?

removeProductMediaFromChoices( )


Removes media items by ID from a product's options.

The removeProductMediaFromChoices() function returns a Promise that resolves when the products with the given IDs are removed from a product's options.

You can remove multiple media items from a product's option at one time by delimiting the list of options with commas.

Removing media items from a product option does not delete the media items from the product.

Method Declaration
Copy
function removeProductMediaFromChoices(
  productId: string,
  mediaChoices: Array<MediaChoice>,
): Promise<void>;
Method Parameters
productIdstringRequired

ID of the product from whose options to remove media items.


mediaChoicesArray<MediaChoice>Required

Media items already uploaded to the Wix site, and the choices to which to upload the media. If no choices are specified, the media items are removed from all choices for the given product.

Remove media items from product choices
JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from "wix-stores-backend"; export function removeProductMediaFromChoices(productId, choiceIds) { return wixStoresBackend.removeProductMediaFromChoices(productId, choiceIds); } /************* * Page code * *************/ import { removeProductMediaFromChoices } from "backend/products"; // ... const productId = "1a11aaa3-...-111a1aaa111"; const choices = [ { option: "Color", choice: "Blue", }, ]; removeProductMediaFromChoices(productId, choices) .then(() => { // media items removed from the product choices }) .catch((error) => { // media items not removed from the product choices });
Errors

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

Did this help?

removeProductsFromCollection( )


Removes products by ID from a collection.

The removeProductsFromCollection() function returns a Promise that resolves when the products with the given IDs are removed from a specified collection.

You can remove multiple products from a collection at one time by delimiting the list of products with commas.

If you do not specify any IDs, all products are removed from the collection.

Removing products from a collection does not delete the products from the store. See deleteProduct() to delete a product from the store.

Method Declaration
Copy
function removeProductsFromCollection(
  collectionId: string,
  productIds: Array<string>,
): Promise<void>;
Method Parameters
collectionIdstringRequired

ID of the collection from which to remove products.


productIdsArray<string>Required

IDs of the products to remove from the collection.

Remove products from a product collection
JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from 'wix-stores-backend'; export function removeProductsFromCollection(collectionId, productIds) { return wixStoresBackend.removeProductsFromCollection(collectionId, productIds); } /************* * Page code * *************/ import { removeProductsFromCollection } from 'backend/products'; // ... const collectionId = ... // get collection ID const productIds = ["id1", "id2", "id3"]; removeProductsFromCollection(collectionId, productIds) .then(() => { // products removed from the collection }) .catch((error) => { // products not removed from the collection });
Errors

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

Did this help?

resetVariantData( )


Resets the data (such as the price and the weight) of all variants for a given product to their default values.

The resetVariantData() function returns a Promise that resolves when a product's variants have been reset.

Note: The Manage Variants field for the product must be set to true to reset variant data.

Method Declaration
Copy
function resetVariantData(productId: string): Promise<void>;
Method Parameters
productIdstringRequired

ID of the product whose variants should be reset.

Reset the data of a variant to their default values
JavaScript
import wixStoresBackend from "wix-stores-backend"; export function resetVariantData(productId) { wixStoresBackend .resetVariantData(productId) .then(() => { // product variants have been reset to original values }) .catch((err) => { // there was an error resetting the product variants }); }
Errors

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

Did this help?

sendFulfillmentEmail( )


Sends a fulfillment email to a specified custom fulfiller of a line item in a given order.

The sendFulfillmentEmail() function returns a Promise that is resolved when the fulfillment email for the specified order is sent to the specified custom fulfiller. A custom fulfiller is a fulfiller that is not integrated with the Wix App Market. Learn more about Connecting Your Wix Store to a Fulfillment Service.

Method Declaration
Copy
function sendFulfillmentEmail(
  orderId: string,
  fulfillerId: string,
): Promise<void>;
Method Parameters
orderIdstringRequired

ID of the order for fulfillment.


fulfillerIdstringRequired

ID of the custom fulfiller.

JavaScript
/*********************************** * Backend code - fulfillments.jsw * ***********************************/ import wixStoresBackend from "wix-stores-backend"; export function sendFulfillmentEmail(orderId, fulfillerId) { return wixStoresBackend.sendFulfillmentEmail(orderId, fulfillerId); } /************** * Page code * **************/ import { sendFulfillmentEmail } from "backend/fulfillments"; export function button1_click(event) { $w("#thankYouPage1") .getOrder() .then((order) => { sendFulfillmentEmail(order._id, order.lineItems[0].fulfillerId) .then(() => { // Fulfillment email sent }) .catch((error) => { // Fulfillment email not sent console.log(error); }); }); }
Errors

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

Did this help?

updateFulfillment( )


Deprecated. This function will continue to work until September 4, 2024, but a newer version is available at wix-ecom-backend.OrderFulfillments.updateFulfillment().

We recommend you migrate to the new Wix eCommerce APIs as soon as possible.

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-ecom-backend.OrderFulfillments.updateFulfillment().

To migrate to the new function:

  1. Add the new import statement:

    Copy
    import { orderFulfillments } from "wix-ecom-backend";
  2. Look for any code that uses wixStoresBackend.updateFulfillment(), and replace it with orderFulfillments.updateFulfillment(). Update your code to work with the new updateFulfillment() response properties.

  3. Test your changes to make sure your code behaves as expected.

Updates an existing fulfillment in an order.

The updateFulfillment() function returns a Promise that is resolved to an updated Order object when the specified fulfillment in the order is updated.

Currently, you can only update a fulfillment's tracking information.

Method Declaration
Copy
function updateFulfillment(
  orderId: string,
  fulfillmentId: string,
  trackingInfo: TrackingInfo,
): Promise<Order>;
Method Parameters
orderIdstringRequired

ID of the order to update the fulfillment in.


fulfillmentIdstringRequired

ID of the fulfillment to update.


trackingInfoTrackingInfoRequired

Tracking information to update in the fulfillment.

Returns
Return Type:Promise<Order>
Update a fulfillment
JavaScript
import wixStoresBackend from "wix-stores-backend"; const trackingInfo = { shippingProvider: "fedex", trackingLink: "https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber=6789", trackingNumber: "6789", }; export function updateFulfillment(orderId, fulfillmentId) { return wixStoresBackend .updateFulfillment(orderId, fulfillmentId, trackingInfo) .then((updatedOrder) => { // Fulfillment updated const orderFulfillmentStatus = updatedOrder.fulfillmentStatus; }) .catch((error) => { // Fulfillment not updated console.error(error); }); } /* Returns promise that resolves to: * * { * "order": { * "_id": "d5d43d01-d9a4-4cc2-b257-61184b881447", * "_updatedDate": "2020-06-12T10:24:22.938Z", * "buyerLanguage": "en", * "channelInfo": { * "type": "WEB" * }, * "enteredBy": { * "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9", * "identityType": "MEMBER" * }, * "billingInfo": { * "address": { * "formatted": "My company name\n235 W 23rd St\nNew York, New York 10011\nUnited States\n+15555555555", * "city": "New York", * "country": "USA", * "addressLine": "235 W 23rd St", * "postalCode": "10011", * "subdivision": "NY" * }, * "firstName": "John", * "lastName": "Doe", * "email": "john.doe@somedomain.com", * "phone": "+15555555555", * "company": "My company name", * "externalTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb", * "paidDate": "2020-05-27T12:20:37.994Z", * "paymentMethod": "VISA", * "paymentGatewayTransactionId": "29A06193U6234935D", * "paymentProviderTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb" * }, * "buyerInfo": { * "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9", * "identityType": "MEMBER", * "firstName": "John", * "lastName": "Doe", * "phone": "+15555555555", * "email": "john.doe@somedomain.com" * }, * "_dateCreated": "2020-05-27T12:20:37.966Z", * "currency": "ILS", * "fulfillmentStatus": "FULFILLED", * "archived": false, * "activities": [ * { * "type": "ORDER_PLACED", * "timestamp": "2020-05-27T12:20:37.966Z" * }, * { * "type": "ORDER_PAID", * "timestamp": "2020-05-27T12:20:37.994Z" * } * ], * "number": 10019, * "paymentStatus": "PAID", * "shippingInfo": { * "deliveryOption": "Free Shipping", * "estimatedDeliveryTime": "4:30pm", * "shippingRegion": "Domestic", * "shipmentDetails": { * "address": { * "formatted": "company name\n235 W 23rd St\nNew York, New York 10011\nUnited States\n5555555555", * "city": "New York", * "country": "USA", * "addressLine": "235 W 23rd St", * "postalCode": "10011", * "subdivision": "NY" * }, * "firstName": "John", * "lastName": "Doe", * "email": "john.doe@somedomain.com", * "phone": "5555555555", * "company": "company name", * "tax": 0, * "discount": 0, * "priceData": null * }, * "pickupDetails": null * }, * "lineItems": [ * { * "index": 1, * "quantity": 1, * "price": 5, * "name": "my product's name", * "translatedName": "Nombre traducido", * "productId": "3fb6a3c8-988b-8755-04bd-5c59ae0b18ea", * "totalPrice": 5, * "lineItemType": "PHYSICAL", * "options": [ * { * "option": "Size", * "selection": "Medium" * } * ], * "customTextFields": [ * { * "title": "Notes for delivery", * "value": "Please leave at front door" * } * ], * "weight": 1.42, * "sku": "36523641234523", * "discount": 0, * "tax": 5, * "taxIncludedInPrice": true, * "priceData": { * "price": "5", * "totalPrice": 5, * "taxIncludedInPrice": true * }, * "mediaItem": null * } * ], * "totals": { * "discount": 0, * "quantity": 1, * "shipping": 0, * "subtotal": 5, * "tax": 0, * "total": 5, * "weight": 1.42 * }, * "weightUnit": "KG", * "customField": { * "value": "Please call when outside", * "title": "Notes for delivery", * "translatedTitle": "Notas de entrega" * }, * "fulfillments": [ * { * "id": "cfbc5122-8766-4209-8bf4-611a10f9c546", * "dateCreated": "2020-06-10T15:38:10.938Z", * "lineItems": [ * { * "index": 1, * "quantity": 1 * } * ], * "trackingInfo": { * "trackingNumber": "6789", * "shippingProvider": "fedex", * "trackingLink": "https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber=6789" * }, * } * ], * "discount": null * } * } * */
Errors

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

Did this help?

updateInventoryVariantFields( )


Updates an existing inventory item's variants by inventory ID.

The updateInventoryVariantFields() function returns a Promise that resolves when the variant with the specified inventory ID has been updated.

Only the properties passed in the inventory item object will be updated. All other properties will remain the same.

Note: You can also update a variant's inventory by product ID instead of inventory ID using the updateInventoryVariantFieldsByProductId() function. The product ID is the corresponding product ID for the inventory item in a Wix store.

Method Declaration
Copy
function updateInventoryVariantFields(
  inventoryId: string,
  inventoryInfo: InventoryItemVariantInfo,
): Promise<void>;
Method Parameters
inventoryIdstringRequired

Inventory ID of the item with variants to update.


inventoryInfoInventoryItemVariantInfoRequired

The inventory information to update in the variant.

JavaScript
/******************************* * Backend code - inventory.jsw * *******************************/ import wixStoresBackend from "wix-stores-backend"; export function updateInventoryVariantFields(id, item) { return wixStoresBackend.updateInventoryVariantFields(id, item); } export function getProductVariantsBackend(productId, options) { return wixStoresBackend.getProductVariants(productId, options); } /************* * Page code * *************/ import wixData from "wix-data"; import { updateInventoryVariantFields, getProductVariantsBackend, } from "backend/inventory"; $w.onReady(async function () { // we want to change the inventory info for // a small, blue suit. let item = "Suit"; let size = "small"; let color = "blue"; // query to get the product ID and inventory ID for a suit let myProductDetails = await getMyProduct(item); let myProductId = myProductDetails[0]; let myInventoryId = myProductDetails[1]; // query to get the variant ID for the small, blue suit let myVariantId = await getMyVariant(myProduct, size, color); // set up the inventory information to update for the variant let myVariantData = { trackQuantity: true, variants: [ { quantity: 1, variantId: myVariantId, }, ], }; try { // run the function to update the inventory for the variant await updateInventoryVariantFields(myInventoryId, myVariantData); } catch (err) { // handle the error } }); export function getMyProduct(theItem) { return wixData .query("Stores/Products") .eq("name", theItem) .find() .then((results) => { if (results.items.length > 0) { return [results.items[0]._id, results.items[0].inventoryItem]; } else { // handle the error return; } }); } export function getMyVariant(productId, size, color) { let productOptions = { choices: { Size: size, Color: color, }, }; return getProductVariantsBackend(productId, productOptions).then( (variantResults) => { if (variantResults.items.length > 0) { return variantResults.items[0]._id; } else { // handle the error return; } }, ); } /* A sample inventory item with variants is: * * { * "_id" : 133c6\-...-0fb2, * "productId" : ecc3-...-1f04d, * "trackQuantity" : true, * "variants" : -[ * { * "variantId" : 00000000-0000-0020-0005-9ec14dfb2270, * "inStock" : false, * "quantity" : 0 * }, * { * "variantId" : 00000000-0000-0021-0005-9ec14dfb2270, * "inStock" : false, * "quantity" : 0 * }, * { * "variantId" : 00000000-0000-0022-0005-9ec14dfb2270, * "inStock" : true, * "quantity" : 100 * }, * { * "variantId" : 00000000-0000-003f-0005-9ec14dfb2270, * "inStock" : true, * "quantity" : 123 * }, * { * "variantId" : 00000000-0000-0040-0005-9ec14dfb2270, * "inStock" : false, * "quantity" : 0 * }, * { * "variantId" : 00000000-0000-0041-0005-9ec14dfb2270, * "inStock" : true, * "quantity" : 1 * } * ], * "_updatedDate" : 2020-02-17T08:25:57.734Z * } */
Errors

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

Did this help?

updateInventoryVariantFieldsByProductId( )


Updates an existing inventory item's variants by product ID.

The updateInventoryVariantFieldsByProductId() function returns a Promise that resolves when the variant with the specified product ID has been updated.

Only the properties passed in the inventory item object will be updated. All other properties will remain the same.

Note: You can also update a variant's inventory by inventory ID instead of product ID using the updateInventoryVariantFields() function.

Method Declaration
Copy
function updateInventoryVariantFieldsByProductId(
  productId: string,
  inventoryInfo: InventoryItemVariantInfo,
): Promise<void>;
Method Parameters
productIdstringRequired

The corresponding product ID for the inventory item in a Wix store.


inventoryInfoInventoryItemVariantInfoRequired

The information to update in the variant.

JavaScript
/******************************* * Backend code - inventory.jsw * *******************************/ import wixStoresBackend from "wix-stores-backend"; export function updateInventoryVariantFieldsByProductId(productId, item) { return wixStoresBackend.updateInventoryVariantFieldsByProductId( productId, item, ); } /************* * Page code * *************/ import { updateInventoryVariantFieldsByProductId } from "backend/inventory"; $w.onReady(async function () { const product = await $w("#productPage1").getProduct(); let options = product.variants; let foundVariant = options.find((option) => { return option.choices.Color === "red" && option.choices.Size === "large"; }); let variantInfo = { trackQuantity: false, variants: [ { inStock: true, variantId: foundVariant._id, }, ], }; updateInventoryVariantFieldsByProductId(product._id, variantInfo); }); /* A sample inventory item with variants is: * * { * "_id" : 133c6\-...-0fb2, * "productId" : ecc3-...-1f04d, * "trackQuantity" : true, * "variants" : -[ * { * "variantId" : 00000000-0000-0020-0005-9ec14dfb2270, * "inStock" : false, * "quantity" : 0 * }, * { * "variantId" : 00000000-0000-0021-0005-9ec14dfb2270, * "inStock" : false, * "quantity" : 0 * }, * { * "variantId" : 00000000-0000-0022-0005-9ec14dfb2270, * "inStock" : true, * "quantity" : 100 * }, * { * "variantId" : 00000000-0000-003f-0005-9ec14dfb2270, * "inStock" : true, * "quantity" : 123 * }, * { * "variantId" : 00000000-0000-0040-0005-9ec14dfb2270, * "inStock" : false, * "quantity" : 0 * }, * { * "variantId" : 00000000-0000-0041-0005-9ec14dfb2270, * "inStock" : true, * "quantity" : 1 * } * ], * "_updatedDate" : 2020-02-17T08:25:57.734Z * } */
Errors

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

Did this help?

updateProductFields( )


Updates an existing product by ID.

The updateProductFields() function returns a Promise that resolves when the product with the specified ID has been updated.

Only the properties passed in the Product object will be updated. All other properties will remain the same.

Note: Do not pass important information from client-side code. Doing so opens a vulnerability that a malicious user can exploit to change information, such as a buyer’s personal details (address, email, etc.) or product price information. To learn more about how to keep your code secure, see Security Considerations When Working with Wix Code.

Method Declaration
Copy
function updateProductFields(
  productId: string,
  productInfo: UpdateProductInfo,
): Promise<Product>;
Method Parameters
productIdstringRequired

ID of the product to update.


productInfoUpdateProductInfoRequired

The information to update in the product.

Returns
Return Type:Promise<Product>
Update a product
JavaScript
import wixStoresBackend from "wix-stores-backend"; wixStoresBackend .updateProductFields(productId, { name: "new name", price: "new price", }) .then((product) => { // Product has been updated const newProductName = product.name; const slug = product.slug; }) .catch((error) => { // There was an error updating the product console.error(error); });
Errors

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

Did this help?

updateVariantData( )


Updates the data (such as the price and the weight) of an existing product variant in the store.

The updateVariantData() function returns a Promise that resolves when a product's variant, with the specified choice and corresponding value, has been updated.

For example, if my product is a ring, I can update the price of the Gold value of the Metal choice, or the price of the Silver value of the Metal choice. In this example, "price" is the variant's data.

When passing parameters to updateVariantData(), if the combination of the product ID, choice, or choice value does not match any existing variants, an error is issued.

Only the properties passed in the VariantInfo object will be updated. All other properties remain the same.

Note: The Manage Variants field for the product must be set to true to update a variant's data.

Method Declaration
Copy
function updateVariantData(
  productId: string,
  variantInfo: Array<VariantInfo>,
): Promise<VariantItem>;
Method Parameters
productIdstringRequired

ID of the product to update.


variantInfoArray<VariantInfo>Required

The information to update for the variant.

Returns
Return Type:Promise<VariantItem>
Update the data of a variant
JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from "wix-stores-backend"; export function updateVariantData(productId, variantInfo) { return wixStoresBackend.updateVariantData(productId, variantInfo); } /************* * Page code * *************/ import { updateVariantData } from "backend/products"; // ... $w("#myProductPage") .getProduct() .then((product) => { let productId = product._id; let productManageVariants = product.manageVariants; // check that variants can be added and updated // for this product if (productManageVariants) { const weight = 10; const price = 15; const variantInfo = [ { weight, price, choices: { Color: "Blue", Size: "Large", }, }, ]; updateVariantData(productId, variantInfo) .then(() => { // product variant data have been updated }) .catch((error) => { // there was an error updating the product variant }); } });
Errors

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

Did this help?