deleteProductOptions( )


Deletes all options for an existing product.

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

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

ID of the product with options to delete.

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

getCurrentCart( )


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

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

Migration Instructions

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

To migrate to the new function:

  1. Add the new import statement:

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

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

Gets the current site visitor's shopping cart.

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

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

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

This example uses a deprecated function.

JavaScript
import wixStoresBackend from "wix-stores-backend"; export function getCurrentCart() { return wixStoresBackend.getCurrentCart(); } /* Returned promise resolves to: * * { * "_id": "b36eb035-635a-450e-b74d-acf86ee4dfcc", * "appliedCoupon": { * "couponId": "e81e9c48-f954-4044-ba64-ccfe5c103c8f", * "name": "Summer Sale", * "code": "SummerSale", * "discountValue": "$10.00", * "couponType": "MoneyOff" * }, * "billingAddress": { * "firstName": "John", * "lastName": "Doe", * "email":"john.doe@somedomain.com", * "phone":"5555555", * "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States" * }, * "buyerNote": "This is a note from the buyer.", * "buyerInfo":{ * "firstName": "John", * "lastName": "Doe", * "email": "john.doe@somedomain.com", * "phone": "5555555555", * "identityType": "CONTACT" * }, * "status": "INCOMPLETE", * "currency": { * "code": "USD", * "symbol": "$" * }, * "shippingInfo": { * "deliveryOption": "Free Shipping", * "shippingAddress": { * "firstName": "John", * "lastName": "Doe", * "email":"john.doe@somedomain.com", * "phone":"5555555", * "address":"235 West 23rd Street\nNew York, New York 10011\nUnited States" * }, * "pickupDetails":null * }, * "lineItems":[ * { * "quantity": 1, * "price": 120, * "name": "A product", * "productId": "a668ef33-f5b8-6569-d04c-1d123be68441", * "totalPrice": 120, * "lineItemType": "PHYSICAL", * "customTextFields": [ * "title": "Custom Field", * "value": "Custom value" * ], * "mediaItem": { * "src": "wix:image://v1/a9ff3b_ed3b544c319b4fad9c222c791a997832.jpg/file.jpg#originWidth=1000&originHeight=1000", * "type": "IMAGE" * }, * "sku": "21554345656", * "options": [ ], * "weight": 3, * "id": 1 * }, * { * "quantity": 1, * "price": 25, * "name": "Another product", * "productId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09", * "totalPrice": 25, * "lineItemType": "PHYSICAL", * "mediaItem": { * "src": "wix:image://v1/a9ff3b_c6158b4d41784ae8b08337a331e1de7f.jpg/file.jpg#originWidth=1000&originHeight=1000", * "type": "IMAGE" * }, * "sku": "217537123517253", * "options": [ * { * "option": "Size", * "selection": "Medium" * }, * { * "option": "Color", * "selection": "Black" * } * ], * "weight": 2, * "id": 2 * } * ], * "totals": { * "discount": 0, * "quantity": 2, * "shipping": 0, * "subtotal": 145, * "tax": 0, * "total": 145, * "weight": 5 * }, * "weightUnit": "LB" * } */
Did this help?



getProductOptionsAvailability( )


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

The getProductOptionsAvailability() function returns a Promise that is resolved to a ProductOptionsAvailability object when the product's availability information is retrieved.

The information returned in the selectedVariant and availableForPurchase properties reflects the option choices passed in using the ProductChoices parameter.

If the specified choices result in the selection of a single product variant, that variant is returned in the selectedVariant property and the availableForPurchase property indicates whether that product variant is available for purchase.

If the specified choices do not result in the selection of a single product variant, no variant is returned in the selectedVariant property and the availableForPurchase property will be false.

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

The ID of the product whose availability is being checked.


choicesProductChoicesRequired

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

Returns
Return Type:Promise<ProductOptionsAvailability>

This example gets a product's availability information using an option choice. The product contains more than one option, so no variant is selected and the product with the specified choices is not available for purchase.

JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from 'wix-stores-backend'; export function getProductOptionsAvailability(productId, choices) { return wixStoresBackend.getProductOptionsAvailability(productId, choices); } /************* * Page code * *************/ import { getProductOptionsAvailability } from 'backend/products'; // ... let productId = // get product ID; let choices = { "Size": "Large" }; getProductOptionsAvailability(productId, choices) .then((availability) => { let available = availability.availableForPurchase; // false let options = availability.productOptions; // see below let mainMedia = availability.mainMedia; let mediaItems = availability.mediaItems; let selectedVariant = availability.selectedVariant; // null }) .catch((error) => { console.log(error); }); /* * options: * * "Size": { * "optionType": "drop_down", * "name": "Size", * "choices": [ * { * "value": "Small", * "description": "Small", * "inStock": true, * "visible": true * }, * { * "value": "Large", * "description": "Large", * "inStock": true, * "visible": true * } * ] * }, * "Color": { * "optionType": "color", * "name": "Color", * "choices": [ * { * "value": "rgb(0, 128, 0)", * "description": "green", * "inStock": true, * "visible": true * }, * { * "value": "rgb(255, 0, 0)", * "description": "red", * "inStock": true, * "visible": true * } * ] * } */
Did this help?

getProductVariants( )


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

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

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

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


optionsProductVariantOptions

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

Returns
Return Type:Promise<Array<VariantItem>>
JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from "wix-stores-backend"; export function getProductVariants(productId, options) { return wixStoresBackend.getProductVariants(productId, options); } /************* * Page code * *************/ import { getProductVariants } from "backend/products"; let productId = "3fb6a3c8-988b-7895-04bd-5c59ae0b18ea"; // get product ID let options = { choices: { Size: "Large", Color: "Red", }, }; getProductVariants(productId, options) .then((variants) => { let firstVariant = variants[0]; let firstPrice = firstVariant.variant.price; let numberOfReturnedVariants = variants.length; }) .catch((error) => { console.error(error); }); /* Example of returned variants array: * * [ * { * "_id": "00000000-0000-03e1-0005-957f699d0688", * "choices": { * "Size": "Large", * "Color": "Red", * "Pattern": "Paisley" * }, * "variant": { * "currency": "USD", * "price": 25, * "discountedPrice": 25, * "formattedPrice": "$25.00", * "formattedDiscountedPrice": "$25.00", * "pricePerUnit": 0.25, * "formattedPricePerUnit": "$0.25", * "weight": 5, * "sku": "217537123517253", * "visible": true * } * }, * { * "id": "00000000-0000-03e2-0005-957f699d0688", * "choices": { * "Size": "Large", * "Color": "Red", * "Pattern": "Houndstooth" * }, * "variant": { * "currency": "USD", * "price": 25, * "discountedPrice": 25, * "formattedPrice": "$25.00", * "formattedDiscountedPrice": "$25.00", * "pricePerUnit": 0.25, * "formattedPricePerUnit": "$0.25", * "weight": 5, * "sku": "217537123517253", * "visible": true * } * } * ] * */
Did this help?

incrementInventory( )


Adds a set number of items from inventory.

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

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

Inventory items to increment.

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

removeProductMedia( )


Removes media items by ID from a product.

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

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

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

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

ID of the product from which to remove media items.


mediaArray<Media>Required

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

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

removeProductMediaFromChoices( )


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

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

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

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

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

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


mediaChoicesArray<MediaChoice>Required

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

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

removeProductsFromCollection( )


Removes products by ID from a collection.

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

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

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

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

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

ID of the collection from which to remove products.


productIdsArray<string>Required

IDs of the products to remove from the collection.

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

resetVariantData( )


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

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

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

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

ID of the product whose variants should be reset.

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