- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
confirmVariantInventoryWorkflow - Medusa Core Workflows Reference
This documentation provides a reference to the confirmVariantInventoryWorkflow
. It belongs to the @medusajs/medusa/core-flows
package.
This workflow validates that product variants are in-stock at the specified sales channel, before adding them or updating their quantity in the cart. If a variant doesn't have sufficient quantity in-stock, the workflow throws an error. If all variants have sufficient inventory, the workflow returns the cart's items with their inventory details.
This workflow is useful when confirming that a product variant has sufficient quantity to be added to or updated in the cart. It's executed by other cart-related workflows, such as addToCartWorkflow, to confirm that a product variant can be added to the cart at the specified quantity.
You can use this workflow within your own customizations or custom workflows, allowing you to check whether a product variant has enough inventory quantity before adding them to the cart.
Source CodeExamples#
You can retrieve a variant's required details using Query:
1const { data: variants } = await query.graph({2 entity: "variant",3 fields: [4 "id",5 "manage_inventory",6 "inventory_items.inventory_item_id",7 "inventory_items.required_quantity",8 "inventory_items.inventory.requires_shipping",9 "inventory_items.inventory.location_levels.stock_locations.id",10 "inventory_items.inventory.location_levels.stock_locations.name",11 "inventory_items.inventory.location_levels.stock_locations.sales_channels.id",12 "inventory_items.inventory.location_levels.stock_locations.sales_channels.name",13 ],14 filters: {15 id: ["variant_123"]16 }17})
Then, pass the variant's data with the other required data to the workflow:
When updating an item quantity:
Steps#
Workflow Hook
Step conditioned by when
Input#
ConfirmVariantInventoryWorkflowInputDTO
ConfirmVariantInventoryWorkflowInputDTOThe details necessary to check whether the variant has sufficient inventory.
ConfirmVariantInventoryWorkflowInputDTO
ConfirmVariantInventoryWorkflowInputDTOsales_channel_id
stringThe ID of the sales channel to check the inventory availability in.
sales_channel_id
stringvariants
object[]The variants to confirm they have sufficient in-stock quantity.
variants
object[]items
object[]The items in the cart, or to be added.
items
object[]itemsToUpdate
object[]OptionalThe new quantity of the variant to be added to the cart.
This is useful when updating a variant's quantity in the cart.
itemsToUpdate
object[]OptionalOutput#
ConfirmVariantInventoryWorkflowOutput
ConfirmVariantInventoryWorkflowOutputThe details of the cart items with inventory result computed for the specified input.
ConfirmVariantInventoryWorkflowOutput
ConfirmVariantInventoryWorkflowOutputitems
object[]The cart's line items with the computed inventory result.
items
object[]