fix(core-flows): properly delete variant inventory item (#12958)

* fix(core-flows): properly delete variant inventory item

* fix: rm unused code
This commit is contained in:
Frane Polić
2025-07-16 21:16:29 +02:00
committed by GitHub
parent 7669dbb03e
commit 40625c82d6
4 changed files with 127 additions and 29 deletions

View File

@@ -26,9 +26,9 @@ import { createProductVariantsStep } from "../steps/create-product-variants"
import { createVariantPricingLinkStep } from "../steps/create-variant-pricing-link"
/**
*
*
* The data to create one or more product variants, along with custom data that's passed to the workflow's hooks.
*
*
* @privateRemarks
* TODO: Create separate typings for the workflow input
*/
@@ -51,9 +51,9 @@ export type CreateProductVariantsWorkflowInput = {
*/
inventory_item_id: string
/**
* The number of units a single quantity is equivalent to. For example, if a customer orders one quantity of the variant,
* Medusa checks the availability of the quantity multiplied by the value set for `required_quantity`.
* When the customer orders the quantity, Medusa reserves the ordered quantity multiplied by the value
* The number of units a single quantity is equivalent to. For example, if a customer orders one quantity of the variant,
* Medusa checks the availability of the quantity multiplied by the value set for `required_quantity`.
* When the customer orders the quantity, Medusa reserves the ordered quantity multiplied by the value
* set for `required_quantity`.
*/
required_quantity?: number
@@ -201,19 +201,19 @@ const buildVariantItemCreateMap = (data: {
export const createProductVariantsWorkflowId = "create-product-variants"
/**
* This workflow creates one or more product variants. It's used by the [Create Product Variant Admin API Route](https://docs.medusajs.com/api/admin#products_postproductsidvariants).
*
* This workflow has a hook that allows you to perform custom actions on the created product variants. For example, you can pass under `additional_data` custom data that
*
* This workflow has a hook that allows you to perform custom actions on the created product variants. For example, you can pass under `additional_data` custom data that
* allows you to create custom data models linked to the product variants.
*
*
* You can also use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around product-variant creation.
*
*
* :::note
*
* Learn more about adding rules to the product variant's prices in the Pricing Module's
*
* Learn more about adding rules to the product variant's prices in the Pricing Module's
* [Price Rules](https://docs.medusajs.com/resources/commerce-modules/pricing/price-rules) documentation.
*
*
* :::
*
*
* @example
* const { result } = await createProductVariantsWorkflow(container)
* .run({
@@ -239,11 +239,11 @@ export const createProductVariantsWorkflowId = "create-product-variants"
* }
* }
* })
*
*
* @summary
*
*
* Create one or more product variants.
*
*
* @property hooks.productVariantsCreated - This hook is executed after the product variants are created. You can consume this hook to perform custom actions on the created product variants.
*/
export const createProductVariantsWorkflow = createWorkflow(

View File

@@ -20,7 +20,7 @@ import { deleteInventoryItemWorkflow } from "../../inventory"
/**
* The data to delete one or more product variants.
*/
export type DeleteProductVariantsWorkflowInput = {
export type DeleteProductVariantsWorkflowInput = {
/**
* The IDs of the variants to delete.
*/
@@ -29,14 +29,14 @@ export type DeleteProductVariantsWorkflowInput = {
export const deleteProductVariantsWorkflowId = "delete-product-variants"
/**
* This workflow deletes one or more product variants. It's used by the
* This workflow deletes one or more product variants. It's used by the
* [Delete Product Variants Admin API Route](https://docs.medusajs.com/api/admin#products_deleteproductsidvariantsvariant_id).
*
* This workflow has a hook that allows you to perform custom actions after the product variants are deleted. For example,
*
* This workflow has a hook that allows you to perform custom actions after the product variants are deleted. For example,
* you can delete custom records linked to the product variants.
*
*
* You can also use this workflow within your own custom workflows, allowing you to wrap custom logic around product-variant deletion.
*
*
* @example
* const { result } = await deleteProductVariantsWorkflow(container)
* .run({
@@ -44,20 +44,16 @@ export const deleteProductVariantsWorkflowId = "delete-product-variants"
* ids: ["variant_123"],
* }
* })
*
*
* @summary
*
*
* Delete one or more product variants.
*
*
* @property hooks.productVariantsDeleted - This hook is executed after the variants are deleted. You can consume this hook to perform custom actions on the deleted variants.
*/
export const deleteProductVariantsWorkflow = createWorkflow(
deleteProductVariantsWorkflowId,
(input: WorkflowData<DeleteProductVariantsWorkflowInput>) => {
removeRemoteLinkStep({
[Modules.PRODUCT]: { variant_id: input.ids },
}).config({ name: "remove-variant-link-step" })
const variantsWithInventoryStepResponse = useQueryGraphStep({
entity: "variants",
fields: [
@@ -71,6 +67,10 @@ export const deleteProductVariantsWorkflow = createWorkflow(
},
})
removeRemoteLinkStep({
[Modules.PRODUCT]: { variant_id: input.ids },
}).config({ name: "remove-variant-link-step" })
const toDeleteInventoryItemIds = transform(
{ variants: variantsWithInventoryStepResponse.data },
(data) => {