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:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(core-flows): correctly delete related inventory item when deleting variant
|
||||||
@@ -2159,6 +2159,99 @@ medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should recreate a variant with the same sku after deletion", async () => {
|
||||||
|
const payload = {
|
||||||
|
title: "Test sku",
|
||||||
|
shipping_profile_id: shippingProfile.id,
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
sku: "test-sku-should-persist",
|
||||||
|
manage_inventory: true,
|
||||||
|
title: "Recreate variant",
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 100,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const created = (
|
||||||
|
await api.post(
|
||||||
|
"/admin/products?fields=*variants.inventory_items.inventory",
|
||||||
|
getProductFixture(payload),
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.product
|
||||||
|
|
||||||
|
const createdVariant = created.variants.find(
|
||||||
|
(v) => v.sku === "test-sku-should-persist"
|
||||||
|
)
|
||||||
|
|
||||||
|
const inventoryItem = createdVariant.inventory_items[0]
|
||||||
|
|
||||||
|
expect(created).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
variants: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
sku: "test-sku-should-persist",
|
||||||
|
inventory_items: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
inventory: expect.objectContaining({
|
||||||
|
sku: "test-sku-should-persist",
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
title: "Recreate variant",
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
await api.delete(
|
||||||
|
`/admin/products/${created.id}/variants/${createdVariant.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const recreated = (
|
||||||
|
await api.post(
|
||||||
|
`/admin/products/${created.id}/variants?fields=+variants.inventory_items.inventory.sku`,
|
||||||
|
{
|
||||||
|
sku: "test-sku-should-persist",
|
||||||
|
manage_inventory: true,
|
||||||
|
title: "Recreate variant",
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 100,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.product
|
||||||
|
|
||||||
|
expect(recreated).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
variants: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
sku: "test-sku-should-persist",
|
||||||
|
inventory_items: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
inventory: expect.objectContaining({
|
||||||
|
sku: "test-sku-should-persist",
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
title: "Recreate variant",
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("updates products sales channels", async () => {
|
it("updates products sales channels", async () => {
|
||||||
const salesChannel1 = (
|
const salesChannel1 = (
|
||||||
await api.post(
|
await api.post(
|
||||||
|
|||||||
@@ -54,10 +54,6 @@ export const deleteProductVariantsWorkflowId = "delete-product-variants"
|
|||||||
export const deleteProductVariantsWorkflow = createWorkflow(
|
export const deleteProductVariantsWorkflow = createWorkflow(
|
||||||
deleteProductVariantsWorkflowId,
|
deleteProductVariantsWorkflowId,
|
||||||
(input: WorkflowData<DeleteProductVariantsWorkflowInput>) => {
|
(input: WorkflowData<DeleteProductVariantsWorkflowInput>) => {
|
||||||
removeRemoteLinkStep({
|
|
||||||
[Modules.PRODUCT]: { variant_id: input.ids },
|
|
||||||
}).config({ name: "remove-variant-link-step" })
|
|
||||||
|
|
||||||
const variantsWithInventoryStepResponse = useQueryGraphStep({
|
const variantsWithInventoryStepResponse = useQueryGraphStep({
|
||||||
entity: "variants",
|
entity: "variants",
|
||||||
fields: [
|
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(
|
const toDeleteInventoryItemIds = transform(
|
||||||
{ variants: variantsWithInventoryStepResponse.data },
|
{ variants: variantsWithInventoryStepResponse.data },
|
||||||
(data) => {
|
(data) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user