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
});
}
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:
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"
* }
*/
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"
* }
*
*/
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"
* }
*
*/
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
* }
* ]
* }
*/
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
* }
* }
* ]
*
*/
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);
});
}
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
});
}
});
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
});
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
});
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
});
}