The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
fix(core): associate new scoped-axis option values with the product (#1454)
Viktor Holik0f25d7ff05ed
diff --git a/integration-tests/http/product/admin/product.spec.ts b/integration-tests/http/product/admin/product.spec.tsindex 7545ec139..46ff300ac 100644--- a/integration-tests/http/product/admin/product.spec.ts+++ b/integration-tests/http/product/admin/product.spec.ts@@ -793,6 +793,34 @@ medusaIntegrationTestRunner({expect(data.length).toBe(1)})+ it("update: a value added to a scoped axis is usable by a new variant (200)", async () => {+ const created = await api.post(+ "/admin/products",+ {+ title: "Scoped Axis Variant Product",+ status: "published",+ attributes: [+ { title: "Size", values: ["S", "M"], is_variant_axis: true },+ ],+ },+ adminHeaders,+ )+ const productId = created.data.product.id+ const sizeId = scopedAttr(created.data.product, "Size").id++ const res = await batch(productId, {+ update: [{ id: sizeId, add: [{ value: "L" }] }],+ })+ expect(res.status).toEqual(200)++ const variantRes = await api.post(+ `/admin/products/${productId}/variants`,+ { title: "Large", options: { Size: "L" } },+ adminHeaders,+ )+ expect([200, 201]).toContain(variantRes.status)+ })+it("remove: inline non-axis scoped attribute delete drops scoped attr + value (200)", async () => {const productId = await createProduct()const added = await batch(productId, {@@ -863,6 +891,44 @@ medusaIntegrationTestRunner({])})+ it("update: shared-axis value subset add + remove re-syncs the product (200)", async () => {+ const multi = await createAttr({+ name: "Shared Size",+ type: "multi_select",+ is_variant_axis: true,+ values: ["S", "M", "L"],+ })+ const created = await api.post(+ "/admin/products",+ {+ title: "Shared Axis Subset Product",+ status: "published",+ attributes: [{ id: multi.id, value_ids: [multi.byName.get("S")!] }],+ },+ adminHeaders,+ )+ const productId = created.data.product.id++ const res = await batch(productId, {+ update: [+ {+ id: multi.id,+ add: [multi.byName.get("M")!],+ remove: [multi.byName.get("S")!],+ },+ ],+ })+ expect(res.status).toEqual(200)+ expect(await optionAttached(productId, "Shared Size")).toBe(true)++ const variantRes = await api.post(+ `/admin/products/${productId}/variants`,+ { title: "Medium", options: { "Shared Size": "M" } },+ adminHeaders,+ )+ expect([200, 201]).toContain(variantRes.status)+ })+it.skip("update: exclusive option value mutation (add XXL / remove S,M,L)", async () => {})it.skip("remove: shared-axis global unlinks product↔option", async () => {})it.skip("remove: inline/exclusive scoped axis delete (option still associated)", async () => {})diff --git a/packages/core/src/workflows/product-attribute/workflows/update-product-attributes-on-product.ts b/packages/core/src/workflows/product-attribute/workflows/update-product-attributes-on-product.tsindex 03b7eff38..6ba5d1258 100644--- a/packages/core/src/workflows/product-attribute/workflows/update-product-attributes-on-product.ts+++ b/packages/core/src/workflows/product-attribute/workflows/update-product-attributes-on-product.ts@@ -143,11 +143,6 @@ export const updateProductAttributesOnProductWorkflow = createWorkflow(},)- when(- { subsetPlan },- ({ subsetPlan }) => subsetPlan.updates.length > 0,- ).then(() => updateProductOptionValuesOnProductStep(subsetPlan.updates))-when({ subsetPlan },({ subsetPlan }) => subsetPlan.dismissLinks.length > 0,@@ -395,6 +390,33 @@ export const updateProductAttributesOnProductWorkflow = createWorkflow(}),)+ const optionValueUpdates = transform(+ { input, subsetPlan, exclusivePlan, createdExclusiveValues },+ ({ input, subsetPlan, exclusivePlan, createdExclusiveValues }) => {+ const updates = [...subsetPlan.updates]+ const add = (+ (createdExclusiveValues ?? []) as {+ product_option_value_id?: string | null+ }[]+ )+ .map((v) => v.product_option_value_id)+ .filter((id): id is string => !!id)+ if (add.length) {+ updates.push({+ product_id: input.product_id,+ product_option_id: exclusivePlan.product_option_id,+ add,+ })+ }+ return updates+ },+ )++ when(+ { optionValueUpdates },+ ({ optionValueUpdates }) => optionValueUpdates.length > 0,+ ).then(() => updateProductOptionValuesOnProductStep(optionValueUpdates))+const exclusiveAddLinks = transform({ input, createdExclusiveValues },({ input, createdExclusiveValues }) =>