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:
co-authored by
Carlos R. L. Rodrigues
Oli Juhl
parent
3d68be2b6b
commit
5d10c46bb1
@@ -5,9 +5,11 @@ import {
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
} from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { simpleCustomerGroupFactory } from "./simple-customer-group-factory"
|
||||
import { ProductVariantMoneyAmount } from "@medusajs/medusa"
|
||||
|
||||
type ProductListPrice = {
|
||||
variant_id: string
|
||||
@@ -64,18 +66,27 @@ export const simplePriceListFactory = async (
|
||||
}
|
||||
|
||||
const toSave = manager.create(PriceList, toCreate)
|
||||
const toReturn = await manager.save(toSave)
|
||||
const toReturn = await manager.save(toSave) as PriceList
|
||||
|
||||
if (typeof data.prices !== "undefined") {
|
||||
for (const ma of data.prices) {
|
||||
toReturn.prices = await Promise.all(data.prices.map(async (ma) => {
|
||||
const factoryData = {
|
||||
...ma,
|
||||
price_list_id: listId,
|
||||
}
|
||||
const toSave = manager.create(MoneyAmount, factoryData)
|
||||
const toSave: MoneyAmount = manager.create(MoneyAmount, factoryData)
|
||||
await manager.save(toSave)
|
||||
}
|
||||
|
||||
await manager.insert(ProductVariantMoneyAmount, {
|
||||
id: `${ma.variant_id}-${toSave.id}`,
|
||||
variant_id: ma.variant_id,
|
||||
money_amount_id: toSave.id,
|
||||
})
|
||||
|
||||
return toSave
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
return toReturn
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user