feat(medusa): Separate money amount and variant (#4906)

* initial changes

* working test

* final changes to product tests

* update integration tests

* update price list integration tests

* update integration tests

* update unit tests

* update plugin integration tests

* remove catch from integration test

* undo change

* add andWhere

* update upsertCurrencyMoneyAmount method

* undo line item changes

* undo changes

* update deprecated method

* Update packages/medusa/src/migrations/1692953518123-drop_money_amount_constraints_for_pricing_module.ts

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>

* rename joinTable

* update with joinTable entity

* update load methods

* remove await create

* re-add context test

* update price list behavior for prices

* update price list snapshots

* re-add admin seeder

* pr feedback

* fix unit tests

* fix plugin integration tests

* initial review changes

* redo changes to variant creation

---------

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Philip Korsholm
2023-09-13 13:26:20 +02:00
committed by GitHub
co-authored by Carlos R. L. Rodrigues Oli Juhl
parent 3d68be2b6b
commit 5d10c46bb1
52 changed files with 2465 additions and 910 deletions
+33 -12
View File
@@ -16,6 +16,8 @@ const {
ShippingProfileType,
} = require("@medusajs/medusa")
const { simpleSalesChannelFactory } = require("../factories")
const { ProductOption } = require("@medusajs/medusa")
const { ProductVariantMoneyAmount } = require("@medusajs/medusa")
module.exports = async (dataSource, data = {}) => {
const manager = dataSource.manager
@@ -34,14 +36,19 @@ module.exports = async (dataSource, data = {}) => {
title: "test product",
profile_id: defaultProfile.id,
profiles: [{ id: defaultProfile.id }],
options: [{ id: "test-option", title: "Size" }],
})
await manager.query(
`insert into product_sales_channel values ('test-product', '${salesChannel.id}');`
)
await manager.insert(ProductVariant, {
await manager.save(ProductOption, {
id: "test-option",
title: "Size",
product_id: "test-product",
})
const variant = manager.create(ProductVariant, {
id: "test-variant",
title: "test variant",
product_id: "test-product",
@@ -54,7 +61,21 @@ module.exports = async (dataSource, data = {}) => {
],
})
await manager.insert(ProductVariant, {
await manager.save(variant)
await manager.insert(MoneyAmount, {
id: "test-price",
currency_code: "usd",
amount: 8000,
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma",
money_amount_id: "test-price",
variant_id: "test-variant",
})
const variant2 = manager.create(ProductVariant, {
id: "test-variant-2",
title: "Swap product",
product_id: "test-product",
@@ -67,19 +88,19 @@ module.exports = async (dataSource, data = {}) => {
],
})
const ma2 = manager.create(MoneyAmount, {
variant_id: "test-variant-2",
currency_code: "usd",
amount: 8000,
})
await manager.save(ma2)
await manager.save(variant2)
const ma = manager.create(MoneyAmount, {
variant_id: "test-variant",
await manager.insert(MoneyAmount, {
id: "test-price_2",
currency_code: "usd",
amount: 8000,
})
await manager.save(ma)
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma4",
money_amount_id: "test-price_2",
variant_id: "test-variant-2",
})
await manager.insert(Region, {
id: "test-region",