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 });
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 * } * } * */
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 * } * } * */
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
  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 * } * } * */
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
  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" * } * } * } * */
Did this help?