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.