feat: Update the product options model and refactor the product module (#6685)

The changes in this PR are:
1. Change how product options are created and stored. The relationship changed from
`options --> option values <-- variants`
to
`options --> option values --> variant options <-- variants`

Now we can enforce non-duplicate option values, easier creation and updates of options, and more.

2. Refactors the product module. The product module did a lot of things in a non-ideal approach, and this is a step towards a more consistent usage of the base repository and methods exposed by a module. There is still work left to improve the module, but a large chunk of the changes are included in this PR


Things to do as a follow-up:
1. Remove many-to-many relationships  if an empty list is passed in the base repository.
2. Improve the typings of the module
3. Further cleanup and improvements (there are few questions that I need answered before I can improve the API)
This commit is contained in:
Stevche Radevski
2024-03-15 13:35:46 +01:00
committed by GitHub
parent a1b4aff127
commit 1956dce80a
40 changed files with 1517 additions and 1896 deletions

View File

@@ -49,24 +49,23 @@ medusaIntegrationTestRunner({
name: "VIP",
})
region = await regionModule.create({ name: "US", currency_code: "USD" })
;[product] = await productModule.create([{ title: "test product" }])
;[product] = await productModule.create([
{
title: "test product",
variants: [
{
title: "test product variant",
},
],
},
])
variant = product.variants[0]
await pricingModule.createRuleTypes([
{ name: "Customer Group ID", rule_attribute: "customer_group_id" },
{ name: "Region ID", rule_attribute: "region_id" },
])
const [productOption] = await productModule.createOptions([
{ title: "Test option 1", product_id: product.id },
])
;[variant] = await productModule.createVariants([
{
product_id: product.id,
title: "test product variant",
options: [{ value: "test", option_id: productOption.id }],
},
])
})
describe("GET /admin/price-lists", () => {