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.
function addProductMedia(productId: string, media: Array<Media>): Promise<void>;
Product ID.
Sources of media items already uploaded to the Wix site.
/*******************************
* 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)
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function addProductMediaToChoices(
productId: string,
mediaChoices: Array<MediaChoice>,
): Promise<void>;
ID of the product with choices to which to add media items.
Product media items, and the choices to add the media to.
Note: Media must already be added to the product.
/*******************************
* 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)
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function addProductsToCollection(
collectionId: string,
productIds: Array<string>,
): Promise<void>;
ID of the product collection to which to add products.
IDs of the products to add to the product collection, separated by commas.
/*******************************
* 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
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function bulkAdjustProductProperty(
ids: Array<string>,
adjust: BulkAdjustProperties,
): Promise<BulkUpdateResponse>;
IDs of the products to adjust.
Numeric property to adjust.
/**************************************
* 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
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function bulkUpdateProductProperty(
ids: Array<string>,
set: BulkUpdateProperties,
): Promise<BulkUpdateResponse>;
IDs of the products to update.
Property to update.
/**************************************
* 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
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
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:
Add the new import statement:
import { orderFulfillments } from "wix-ecom-backend";
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.
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.
function createFulfillment(
orderId: string,
fulfillment: FulfillmentInfo,
): Promise<NewFulfillmentAndOrder>;
ID of the order to create the fulfillment in.
Fulfillment information.
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
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
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:
Add the new import statement:
import { orders } from "wix-ecom-backend";
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.
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.
function createOrder(orderInfo: OrderInfo): Promise<Order>;
The information for the order being created.
/**************
* 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"
* }
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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:
"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.function createProduct(productInfo: ProductInfo): Promise<Product>;
Information for the product being created.
/*******************************
* 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
* }
* }
* ]
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function decrementInventory(items: Array<DecrementInfo>): Promise<void>;
Inventory items to decrement.
/*******************************
* 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);
});
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
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:
Add the new import statement:
import { orderFulfillments } from "wix-ecom-backend";
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.
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.
function deleteFulfillment(
orderId: string,
fulfillmentId: string,
): Promise<Order>;
ID of the order to delete the fulfillment from.
ID of the fulfillment to delete.
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
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deletes an existing product.
The deleteProduct()
function returns a Promise that resolves when the
product with the given ID is deleted.
function deleteProduct(productId: string): Promise<void>;
ID of the product to delete.
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
});
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function deleteProductOptions(productId: string): Promise<void>;
ID of the product with options to delete.
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
});
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
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:
Add the new import statement:
import { currentCart } from "wix-ecom-backend";
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.
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.
function getCurrentCart(): Promise<Cart>;
This example uses a deprecated function.
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"
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Generates a link to a PDF file containing information about one or more specified orders, up to 1000 orders.
The getOrdersLink()
function returns a Promise that resolves to an object containing the URL of a PDF file with the specified orders' information, 1 order per page.
function getOrdersLink(orderIds: Array<string>): Promise<LinkToPdf>;
IDs of the orders for which to generate a PDF file.
/*****************************
* Backend code - orders.jsw *
*****************************/
import wixStoresBackend from "wix-stores-backend";
import wixData from "wix-data";
export function getOrdersLink(orderIds) {
return wixStoresBackend.getOrdersLink(orderIds);
}
// Get IDs of the last 10 paid orders
export function getPaidOrderIds() {
let options = {
suppressAuth: true,
};
return wixData
.query("Stores/Orders")
.eq("paymentStatus", "PAID")
.descending("_dateCreated")
.limit(10)
.find(options)
.then((results) => {
if (results.items.length > 0) {
// Order IDs found
const orderIds = results.items.map((order) => order._id);
return orderIds;
} else {
return "No orders found";
}
})
.catch((error) => {
return error;
});
}
/**************
* Page code *
**************/
import { getOrdersLink, getPaidOrderIds } from "backend/orders";
getPaidOrderIds()
.then((orderIds) => {
getOrdersLink(orderIds)
.then((link) => {
// Orders PDF link retrieved
const orderPdfUrl = link;
})
.catch((error) => {
// Orders PDF link not retrieved
console.error(error);
});
})
.catch((error) => {
// Orders not retrieved from backend
console.error(error);
});
/* Example orderPdfUrl:
*
* {
* link: "https://wixmp-2a4e9...a5977f91b.appspot.com/_api/download/file?downloadToken=E43f...QiOns"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Generates a link to a PDF file containing an order's packing slip.
The getPackingSlipLink()
function returns a Promise that resolves to an object containing the URL of a PDF file with the specified order's packing slip.
function getPackingSlipLink(orderId: string): Promise<LinkToPdf>;
ID of the order for which to generate a packing slip.
/*****************************
* Backend code - orders.jsw *
*****************************/
import wixStoresBackend from "wix-stores-backend";
import wixData from "wix-data";
export function getPackingSlipLink(orderId) {
return wixStoresBackend.getPackingSlipLink(orderId);
}
// Get the most recent order's ID
export function getLatestOrderId() {
let options = {
suppressAuth: true,
};
return wixData
.query("Stores/Orders")
.descending("_dateCreated")
.limit(1)
.find(options)
.then((results) => {
if (results.items.length > 0) {
// Order ID found
return results.items[0]._id;
} else {
return "No orders found";
}
})
.catch((error) => {
return error;
});
}
/**************
* Page code *
**************/
import { getPackingSlipLink, getLatestOrderId } from "backend/orders";
getLatestOrderId()
.then((orderId) => {
getPackingSlipLink(orderId)
.then((link) => {
// Packing slip PDF link retrieved
const packingSlipUrl = link;
})
.catch((error) => {
// Packing slip PDF link not retrieved
console.error(error);
});
})
.catch((error) => {
// Orders not retrieved from backend
console.error(error);
});
/* Example packingSlipUrl:
*
* {
* link: "https://wixmp-2a4e9...a5977f91b.appspot.com/_api/download/file?downloadToken=eyJ...jwAc"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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
.
function getProductOptionsAvailability(
productId: string,
choices: ProductChoices,
): Promise<ProductOptionsAvailability>;
The ID of the product whose availability is being checked.
Option choices to use when checking the product's availability.
This example gets a product's availability information using an option choice. The product contains more than one option, so no variant is selected and the product with the specified choices is not available for purchase.
/*******************************
* Backend code - 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
* }
* ]
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function getProductVariants(
productId: string,
options: ProductVariantOptions,
): Promise<Array<VariantItem>>;
The ID of the product whose variants are being retrieved. Pass only this field to retrieve all the specified product's variants.
Variant options to return. If not specified, all the product's variants are returned.
/*******************************
* 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
* }
* }
* ]
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function incrementInventory(items: Array<IncrementInfo>): Promise<void>;
Inventory items to increment.
/*******************************
* 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);
});
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function removeProductMedia(
productId: string,
media: Array<Media>,
): Promise<void>;
ID of the product from which to remove media items.
Sources of media items already uploaded to the Wix site. If no media
is specified, all media items are removed from the product.
/*******************************
* 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
});
}
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function removeProductMediaFromChoices(
productId: string,
mediaChoices: Array<MediaChoice>,
): Promise<void>;
ID of the product from whose options to remove media items.
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.
/*******************************
* 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
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function removeProductsFromCollection(
collectionId: string,
productIds: Array<string>,
): Promise<void>;
ID of the collection from which to remove products.
IDs of the products to remove from the collection.
/*******************************
* 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
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function resetVariantData(productId: string): Promise<void>;
ID of the product whose variants should be reset.
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
});
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function sendFulfillmentEmail(
orderId: string,
fulfillerId: string,
): Promise<void>;
ID of the order for fulfillment.
ID of the custom fulfiller.
/***********************************
* 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);
});
});
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
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:
Add the new import statement:
import { orderFulfillments } from "wix-ecom-backend";
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.
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.
function updateFulfillment(
orderId: string,
fulfillmentId: string,
trackingInfo: TrackingInfo,
): Promise<Order>;
ID of the order to update the fulfillment in.
ID of the fulfillment to update.
Tracking information to update in the fulfillment.
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
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function updateInventoryVariantFields(
inventoryId: string,
inventoryInfo: InventoryItemVariantInfo,
): Promise<void>;
Inventory ID of the item with variants to update.
The inventory information to update in the variant.
/*******************************
* 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
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function updateInventoryVariantFieldsByProductId(
productId: string,
inventoryInfo: InventoryItemVariantInfo,
): Promise<void>;
The corresponding product ID for the inventory item in a Wix store.
The information to update in the variant.
/*******************************
* 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
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function updateProductFields(
productId: string,
productInfo: UpdateProductInfo,
): Promise<Product>;
ID of the product to update.
The information to update in the product.
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);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
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.
function updateVariantData(
productId: string,
variantInfo: Array<VariantInfo>,
): Promise<VariantItem>;
ID of the product to update.
The information to update for the variant.
/*******************************
* 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
});
}
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This event will continue to work until September 4, 2024, but a newer version is available at
wix-ecom-backend.Events.onCheckoutCompleted()
.
We recommend you migrate to the new Wix eCommerce APIs as soon as possible.
An event that fires when a visitor completes a purchase from a shopping cart.
The onCartCompleted()
event handler runs when a visitor completes a
purchase from a shopping cart.
Note: Backend events don't work when previewing your site.
function onCartCompleted(event: CartCompletedEvent): void;
Information about the cart that was completed.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onCartCompleted(event) {
let total = event.totals.total;
}
/* Full event object:
*
* {
* "cartId": "6d158831-1510-44ae-a420-1483a4200852",
* "completedTime": "2019-02-27T12:08:16.160Z",
* "buyerInfo": {
* "id": "091a8443-ab85-480c-918b-777156358dfc",
* "firstName": "John",
* "lastName": "Doe"
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "identityType": "CONTACT"
* },
* "weightUnit": "LB",
* "buyerNote": "This is a note from the buyer.",
* "billingAddress": {
* "firstName": "John",
* "lastName": "Doe"
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "address": "235 W 23rd St, New York, NY 10011, USA"
* },
* "currency": {
* "currency": "USD",
* "symbol": "$"
* },
* "appliedCoupon": {
* "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f",
* "name": "Summer Sale",
* "code": "SummerSale",
* "discountValue": "$10.00",
* "couponType": "MoneyOff"
* },
* "totals": {
* "subtotal": 250,
* "discount": 10,
* "total": 240,
* "quantity": 2
* },
* "shippingInfo": {
* "pickupDetails": {
* "firstName": "John",
* "lastName": "Doe"
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "address": "235 W 23rd St, New York, NY 10011, USA"
* },
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This event will continue to work until September 4, 2024, but a newer version is available at
wix-ecom-backend.Events.onCartCreated()
.
We recommend you migrate to the new Wix eCommerce APIs as soon as possible.
For more info about the differences between the Stores Cart and eCommerce Cart, refer to the cart conversion table.
An event that fires when a cart is created.
The onCartCreated()
event handler runs the first time a site visitor adds a product to their shopping cart.
Removing all items from the cart and adding a new item does not create a new cart and does not trigger this event.
Note: Backend events don't work when previewing your site.
function onCartCreated(event: CartCreatedEvent): void;
Information about the cart that was created.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onCartCreated(event) {
let total = event.totals.total;
}
/* Full event object:
*
* {
* "cartId": "6d158831-1510-44ae-a420-1483a4200852",
* "creationTime": "2019-02-27T12:03:22.079Z",
* "buyerInfo": {
* "id": "4kf9ka09-4e9f-a02d-972f-9a5844d9d9a2",
* "email": "john.doe@somedomain.com",
* "phone": "5555555555",
* "firstName": "John",
* "lastName": "Doe"
* },
* "weightUnit": "LB",
* "currency": {
* "currency": "USD",
* "symbol": "$"
* },
* "totals": {
* "subtotal": 130,
* "discount": 0,
* "total": 130,
* "quantity": 1
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
An event that fires when a product collection is created.
The onCollectionCreated()
event handler runs when a product collection
is added to a store.
Note: Backend events don't work when previewing your site.
function onCollectionCreated(event: CollectionCreatedEvent): void;
Information about the product collection that was created.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onCollectionCreated(event) {
let collectionId = event._id;
}
/* Full event object:
*
* {
* "name": "New Collection",
* "_id": "a7698dfb-12e8-1bd6-cdc1-0116554f18d1",
* "mainMedia": "wix:image://v1/c...8.jpg/file.jpg#originWidth=2700&originHeight=2186"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
An event that fires when a product collection is deleted.
The onCollectionDeleted()
event handler runs when a product collection
is deleted from a store.
Note: Backend events don't work when previewing your site.
function onCollectionDeleted(event: CollectionDeletedEvent): void;
Information about the product collection that was deleted.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onCollectionDeleted(event) {
let collectionId = event.collectionId;
}
/* Full event object:
*
* {
* "collectionId": "a7698dfb-12e8-1bd6-cdc1-0116554f18d1"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
An event that fires when a product collection is updated.
The onCollectionUpdated()
event handler runs when a product collection
is updated in a store.
Note: Backend events don't work when previewing your site.
function onCollectionUpdated(event: CollectionUpdatedEvent): void;
Information about the product collection that was updated.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onCollectionUpdated(event) {
let collectionId = event.collectionId;
let firstUpdatedField = event.updateFields[0];
}
/* Full event object:
*
* {
* "collectionId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
* "updatedFields": [
* "name",
* "media"
* ]
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This event will continue to work until September 4, 2024, but a newer version is available at
wix-ecom-backend.Events.onFulfillmentsUpdated()
.
We recommend you migrate to the new Wix eCommerce APIs as soon as possible.
An event that fires when an order fulfillment is created.
The onFulfillmentCreated()
event handler runs when one of the following occurs:
Note: Backend events don't work when previewing your site.
function onFulfillmentCreated(event: FulfillmentCreatedEvent): void;
Information about a fulfillment that was created.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onFulfillmentCreated(event) {
const orderId = event.orderId;
const fulfillmentId = event.fulfillmentId;
const trackingNumber = event.trackingInfo.trackingNumber;
}
/* Full event object:
*
* {
* "orderId": "2c6ce6e5-8b40-4d2c-882a-edeb30fb3ec2",
* "fulfillmentId": "4afd9175-b3c5-41b9-b3cc-e65b7544e84b",
* "dateCreated": "2020-02-22T10:41:32.487Z",
* "buyerInfo": {
* "id": "a158c93a-2f1e-4e86-a38f-475931a337ce",
* "identityType": "MEMBER",
* "firstName": "John",
* "lastName": "Doe",
* "phone": "5555555555",
* "email": "john@doe.com"
* },
* "fulfillmentStatus": "FULFILLED",
* "trackingInfo": {
* "trackingNumber": "1234",
* "shippingProvider": "fedex",
* "trackingLink": "https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber=1234"
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This event will continue to work until September 4, 2024, but a newer version is available at
wix-ecom-backend.Events.onFulfillmentsUpdated()
.
We recommend you migrate to the new Wix eCommerce APIs as soon as possible.
An event that fires when an order fulfillment is deleted.
The onFulfillmentDeleted()
event handler runs when the deleteFulfillment() function is called.
Note: Backend events don't work when previewing your site.
function onFulfillmentDeleted(event: FulfillmentDeletedEvent): void;
Information about a fulfillment that was deleted.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onFulfillmentDeleted(event) {
let orderId = event.orderId;
let fulfillmentId = event.fulfillmentId;
}
/* Full event object:
*
* {
* "orderId": "2c6ce6e5-8b40-4d2c-882a-edeb30fb3ec2",
* "fulfillmentId": "4afd9175-b3c5-41b9-b3cc-e65b7544e84b",
* "fulfillmentStatus": "NOT_FULFILLED"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This event will continue to work until September 4, 2024, but a newer version is available at
wix-ecom-backend.Events.onFulfillmentsUpdated()
.
We recommend you migrate to the new Wix eCommerce APIs as soon as possible.
An event that fires when an order fulfillment is updated.
The onFulfillmentUpdated()
event handler runs when one of the following occurs:
Note: Backend events don't work when previewing your site.
function onFulfillmentUpdated(event: FulfillmentUpdatedEvent): void;
Information about a fulfillment that was updated.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onFulfillmentUpdated(event) {
let orderId = event.orderId;
let fulfillmentId = event.fulfillmentId;
let trackingNumber = event.trackingInfo.trackingNumber;
}
/* Full event object:
*
* {
* "orderId": "2c6ce6e5-8b40-4d2c-882a-edeb30fb3ec2",
* "fulfillmentId": "4afd9175-b3c5-41b9-b3cc-e65b7544e84b",
* "trackingInfo": {
* "trackingNumber": "6789",
* "shippingProvider": "Some other provider",
* "trackingLink": "https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber=6789"
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
An event that fires when an inventory item's information is updated.
The onInventoryItemUpdated()
event handler runs when information for an inventory item
is updated in a store.
Note: Backend events don't work when previewing your site.
function onInventoryItemUpdated(event: InventoryItemUpdatedEvent): void;
Information about the updated inventory item.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onInventoryItemUpdated(event) {
let inventoryItemId = event.inventoryItemId;
}
/* Full event object:
*
* {
* "inventoryItemId":"70170fa0-6ae1-ea9c-46e8-775207d7babc",
* "externalId":"8fe8f05f-951e-1563-b917-88adf8284543",
* "trackInventory":true
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
An event that fires when the inventory information of a product variant is updated.
The onInventoryVariantUpdated()
event handler runs when inventory information for a product
variant is updated in a store.
Note: Backend events don't work when previewing your site.
function onInventoryVariantUpdated(event: InventoryVariantUpdatedEvent): void;
Information about the updated variant.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onInventoryVariantUpdated(event) {
let inventoryItemId = event.inventoryItemId;
let firstVariant = event.variants[0];
let firstNewQuantity = firstVariant.newValue.quantity;
}
/* Full event object:
*
* {
* "variants": [
* {
* "oldValue": {
* "inStock": true,
* "quantity": 10
* },
* "newValue": {
* "inStock": true,
* "quantity": 50
* },
* "id": "00000000-0000-0000-0000-000000000000"
* }
* ],
* "externalId": "8fe8f05f-951e-1563-b917-88adf8284543",
* "inventoryItemId": "70170fa0-6ae1-ea9c-46e8-775207d7babc"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This event will continue to work until September 4, 2024, but a newer version is available at
wix-ecom-backend.Events.onOrderApproved()
.
We recommend you migrate to the new Wix eCommerce APIs as soon as possible.
An event that fires when a new order is placed.
The onNewOrder()
event handler runs when a new order is placed in your site's store.
The received NewOrderEvent
object contains information about the new order that was placed.
Note: Backend events don't work when previewing your site.
function onNewOrder(event: NewOrderEvent): void;
The order data.
// Place this code in the events.js file
// of your site's Backend section.
import wixData from "wix-data";
export function wixStores_onNewOrder(event) {
const newOrderId = event.orderId;
const newOrderBuyerInfo = event.buyerInfo;
// Get the new order's line items from the Stores/Orders collection
const orderLineItems = wixData
.get("Stores/Orders", newOrderId)
.then((results) => {
return results.lineItems;
})
.catch((error) => {
// Order not found in the Stores/Orders collection
console.error(error);
});
}
/* Full event object:
*
* {
* "orderId": "2cd413bd-ddea-4101-b122-e8b146fec05f",
* "number": "10005",
* "dateCreated": "2018-08-05T12:33:18.938Z",
* "buyerInfo": {
* "id": "6g004532-732d-829f-5kf9-f9rk42afpla04m",
* "identityType": "MEMBER",
* "email": "janedoe@gmail.com",
* "firstName": "Jane",
* "lastName": "Doe",
* "phone": "5555555555"
* },
* "currency": "USD",
* "weightUnit": "LB",
* "totals": {
* "subtotal": 99.99,
* "shipping": 4.99,
* "tax": 8.87,
* "discount": 9.99,
* "total": 103.86,
* "weight": 1.37,
* "quantity": 2
* },
* "paymentStatus": "PAID",
* "fulfillmentStatus": "FULFILLED",
* "billingInfo": {
* "paymentMethod": "VISA",
* "externalTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb",
* "paymentGatewayTransactionId": "29A06193U6234935D",
* "paymentProviderTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb"
* "address": {
* "fullName": {
* "firstName": "Jane",
* "lastName": "Doe"
* },
* "country": "US",
* "subdivision": "US-NY",
* "city": "New York",
* "zipCode": "11215",
* "phone": "0555555555",
* "email": "janedoe@gmail.com",
* "addressLine1": "525 5th Avenue"
* }
* },
* // The following field is only present when
* // the order is a subscription
* "subscriptionInfo": {
* "id": "6b320feb-ddde-45be-950b-8ed277033579",
* "cycleNumber": 1,
* "subscriptionSettings": {
* "frequency": "MONTH",
* "autoRenewal": false,
* "billingCycles": 3
* },
* "subscriptionOptionInfo": {
* "id": "17c145c2-5d23-42c3-ac0a-e579e99c67fd",
* "title": "Coffee of the month",
* "description": "Monthly Coffee Sub"
* }
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This event will continue to work until September 4, 2024, but a newer version is available at
wix-ecom-backend.Events.onOrderCanceled()
.
We recommend you migrate to the new Wix eCommerce APIs as soon as possible.
An event that fires when an order is canceled.
The onOrderCanceled()
event handler runs when an order is canceled. For example, when an order is canceled in the site's Dashboard.
Note: Backend events don't work when previewing your site.
function onOrderCanceled(event: OrderCanceledEvent): void;
Order canceled event.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onOrderCanceled(event) {
const canceledOrderId = event.order._id;
}
/* Full event object
*
* {
* "order": {
* "_id": "d5d43d01-d9a4-4cc2-b257-61184b881447",
* "_updatedDate": "2020-05-27T12:20:37.994Z",
* "buyerLanguage": "en",
* "cartId": "74621781-b3hf-7845-8c9e-09879063da9",
* "channelInfo": {
* "type": "WEB"
* },
* "enteredBy": {
* "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9",
* "identityType": "MEMBER"
* },
* "refunds": [
* {
* "id": "0bf46037-de62-7848-af43-3a7f3c28b041",
* "dateCreated": "2020-12-14T13:02:04.557Z",
* "amount": "50",
* "externalRefund": true
* }
* ],
* "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": "USD",
* "fulfillmentStatus": "CANCELED",
* "archived": false,
* "activities": [
* {
* "type": "ORDER_PLACED",
* "timestamp": "2020-05-27T12:20:37.966Z"
* }
* ],
* "number": 10019,
* "paymentStatus": "FULLY_REFUNDED",
* "shippingInfo": {
* "deliveryOption": "Free Shipping",
* "estimatedDeliveryTime": "4:30pm",
* "shippingRegion": "Domestic",
* "shipmentDetails": {
* "address": {
* "formatted": "235 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": {
* "price": 0,
* "taxIncludedInPrice": false
* },
* },
* "pickupDetails": null
* },
* "lineItems": [
* {
* "index": 1,
* "quantity": 1,
* "price": 50,
* "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": "50",
* "totalPrice": 50,
* "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": 50,
* "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": "558b511f-6eb7-82d3-53fca7374dfa",
* "name": "Summer sale - Free Shipping"
* }
* }
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This event will continue to work until September 4, 2024, but a newer version is available at
wix-ecom-backend.Events.onOrderPaymentStatusUpdated()
.
We recommend you migrate to the new Wix eCommerce APIs as soon as possible.
An event that fires when an order is marked as paid.
The onOrderPaid()
event handler runs when an order is paid either via customer checkout, or when marked as paid on your site's Dashboard.
Note: Backend events don't work when previewing your site.
function onOrderPaid(event: Order): void;
Paid order data.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onOrderPaid(event) {
const paidOrderId = event._id;
}
/* Full event object
*
* {
* "_id": "d5d43d01-d9a4-4cc2-b257-61184b881447",
* "_updatedDate": "2020-05-27T12:20:37.994Z",
* "buyerLanguage": "en",
* "cartId": "74621781-b3hf-7845-8c9e-09879063da9",
* "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": "Jane",
* "lastName": "Doe",
* "email": "janedoe@gmail.com",
* "phone": "+15555555555",
* "company": "My company name",
* "paidDate": "2020-05-27T12:20:37.994Z",
* "paymentMethod": "VISA",
* "externalTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb",
* "paymentGatewayTransactionId": "29A06193U6234935D",
* "paymentProviderTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb"
* },
* "buyerInfo": {
* "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9",
* "identityType": "MEMBER",
* "firstName": "Jane",
* "lastName": "Doe",
* "phone": "+15555555555",
* "email": "janedoe@gmail.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": "Jane",
* "lastName": "Doe",
* "email": "janedoe@gmail.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": "558b511f-6eb7-82d3-53fca7374dfa",
* "name": "Summer sale"
* }
* }
* // The following field is only present when
* // the order is a subscription
* "subscriptionInfo": {
* "id": "6b320feb-ddde-45be-950b-8ed277033579",
* "cycleNumber": 1,
* "subscriptionSettings": {
* "frequency": "MONTH",
* "autoRenewal": false,
* "billingCycles": 3
* },
* "subscriptionOptionInfo": {
* "id": "17c145c2-5d23-42c3-ac0a-e579e99c67fd",
* "title": "Coffee of the month",
* "description": "Monthly Coffee Sub"
* }
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Deprecated.
This event will continue to work until September 4, 2024, but a newer version is available at
wix-ecom-backend.Events.onOrderTransactionsUpdated()
.
We recommend you migrate to the new Wix eCommerce APIs as soon as possible.
An event that fires when an order is refunded.
The onOrderRefunded()
event handler runs when an order is refunded. For example, when an order is refunded in your site's Dashboard.
Note: Backend events don't work when previewing your site.
function onOrderRefunded(event: OrderRefundedEvent): void;
Order refunded event.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onOrderRefunded(event) {
const refundedOrderId = event.order._id;
const refundId = event.refundId;
}
/* Full event object:
*
* {
* "refundId": "0bf46037-de62-7848-af43-3a7f3c28b041",
* "order": {
* "_id": "d5d43d01-d9a4-4cc2-b257-61184b881447",
* "_updatedDate": "2020-05-27T12:20:37.994Z",
* "buyerLanguage": "en",
* "cartId": "74621781-b3hf-7845-8c9e-09879063da9",
* "channelInfo": {
* "type": "WEB"
* },
* "enteredBy": {
* "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9",
* "identityType": "MEMBER"
* },
* "refunds": [
* {
* "id": "0bf46037-de62-7848-af43-3a7f3c28b041",
* "dateCreated": "2020-12-14T13:02:04.557Z",
* "amount": "50",
* "externalRefund": true,
* "reason": "returned"
* }
* ],
* "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": "USD",
* "fulfillmentStatus": "CANCELED",
* "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": "FULLY_REFUNDED",
* "shippingInfo": {
* "deliveryOption": "Free Shipping",
* "estimatedDeliveryTime": "4:30pm",
* "shippingRegion": "Domestic",
* "shipmentDetails": {
* "address": {
* "formatted": "235 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": {
* "price": 0,
* "taxIncludedInPrice": false
* },
* },
* "pickupDetails": null
* },
* "lineItems": [
* {
* "index": 1,
* "quantity": 1,
* "price": 50,
* "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": "50",
* "totalPrice": 50,
* "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": 50,
* "tax": 0,
* "total": 50,
* "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": "558b511f-6eb7-82d3-53fca7374dfa",
* "name": "Summer sale - Free Shipping"
* }
* }
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
An event that fires when a product is created.
The onProductCreated()
event handler runs when a new product
is added to a store.
Note: Backend events don't work when previewing your site.
function onProductCreated(event: ProductCreatedEvent): void;
Information about the product that was created.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onProductCreated(event) {
let productId = event._id;
}
/* Full event object:
*
* {
* "_id": "5096485f-0239-3881-3f6a-63955708a4ec",
* "name": "New Product",
* "sku": "abc123",
* "formattedDiscountedPrice": "$100.00",
* "visible": true,
* "mainMedia": "wix:image://v1/6...6.jpg/file.jpg#originWidth=2700&originHeight=2186",
* "price": 100,
* "formattedPrice": "$100.00",
* "discountedPrice": 100,
* "pricePerUnit": 0.1,
* "formattedPricePerUnit": "$0.10",
* "mediaItems": [
* {
* "title": "Main Image",
* "description": "Main Image",
* "type": "IMAGE",
* "src": "wix:image://v1/6...6.jpg/file.jpg#originWidth=2700&originHeight=2186"
* }
* ],
* "currency": "USD",
* "productPageUrl": "/product-page/new-product",
* "ribbon": "New Arrival"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
An event that fires when a product is deleted.
The onProductDeleted()
event handler runs when a product
is deleted from a store.
Note: Backend events don't work when previewing your site.
function onProductDeleted(event: ProductDeletedEvent): void;
Information about the product that was deleted.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onProductDeleted(event) {
let productId = event.productId;
}
/* Full event object:
*
* {
* "productId": "5096485f-0239-3881-3f6a-63955708a4ec"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
An event that fires when a product is updated.
The onProductUpdated()
event handler runs when a product
is updated in a store.
Note: Backend events don't work when previewing your site.
function onProductUpdated(event: ProductUpdatedEvent): void;
Information about the product that was updated.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onProductUpdated(event) {
let productId = event.productId;
let firstUpdatedField = event.updateFields[0];
}
/* Full event object:
*
* {
* "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",
* "updatedFields": [
* "name",
* "productOptions",
* "description",
* "price",
* "slug",
* "ribbon",
* "brand",
* "customTextFields",
* "media",
* "productPageUrl",
* "manageVariants",
* "discount",
* "additionalInfoSections"
* ]
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
An event that fires when variant information for a product is updated.
The onVariantsUpdated()
event handler runs when variant information for a product
is updated in a store.
Note: Backend events don't work when previewing your site.
function onVariantsUpdated(event: VariantsUpdatedEvent): void;
Information about the product collection that was deleted.
// Place this code in the events.js file
// of your site's Backend section.
export function wixStores_onVariantsUpdated(event) {
let productId = event.productId;
let firstVariant = event.variants[0];
}
/* Full event object:
*
* {
* "variants":[
* {
* "updatedFields":[
* "price"
* ],
* "choices":{
* "Color":"Red"
* },
* "variantId":"00000000-0000-0001-0005-970d993bafe9"
* }, {
* "updatedFields":[
* "sku"
* ],
* "choices":{
* "Color":"Blue"
* },
* "variantId":"00000000-0000-0002-0005-970d993bafe9"
* }
* ],
* "productId":"1a2d7e83-4bef-31d5-09e1-3326ee271c09"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.