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
@@ -0,0 +1,36 @@
export const defaultPriceListData = [
{
name: 'pl-1',
description: 'pl-1',
prices: [ {
id: "money-amount-USD",
currency_code: "USD",
amount: 500,
min_quantity: 1,
max_quantity: 10,
price_list_id: 'pl-1'
},
{
id: "money-amount-EUR",
currency_code: "EUR",
amount: 400,
min_quantity: 1,
max_quantity: 5,
price_list_id: 'pl-1'
}]
},
{
id: 'pl-2',
name: 'pl-2',
description: 'pl-2',
prices: [{
id: "money-amount-CAD",
currency_code: "CAD",
amount: 600,
min_quantity: 1,
max_quantity: 8,
price_list_id: 'pl-2'
}]
}
]
@@ -0,0 +1,25 @@
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { MoneyAmount, PriceList } from "@models"
import { defaultPriceListData } from "./data"
export async function createPriceLists(
manager: SqlEntityManager,
priceListsData: any[] = defaultPriceListData,
): Promise<MoneyAmount[]> {
const priceLists: PriceList[] = []
const moneyAmounts: MoneyAmount[] = []
for (let priceListdata of priceListsData) {
const { prices, ...rest } = priceListdata
const priceList = manager.create(MoneyAmount, rest)
priceLists.push(priceList)
const createdPrices = manager.create(MoneyAmount, prices)
moneyAmounts.push(createdPrices)
}
await manager.persistAndFlush(priceLists)
await manager.persistAndFlush(moneyAmounts)
return priceLists
}