Files
medusa-store/integration-tests/helpers/price-list-seeder.js
Philip Korsholm 5d10c46bb1 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>
2023-09-13 13:26:20 +02:00

102 lines
2.5 KiB
JavaScript

const { ProductVariantMoneyAmount } = require("@medusajs/medusa")
const { Region, PriceList, MoneyAmount } = require("@medusajs/medusa")
module.exports = async (dataSource, data = {}) => {
const manager = dataSource.manager
const priceListNoCustomerGroups = manager.create(PriceList, {
id: "pl_no_customer_groups",
name: "VIP winter sale",
description: "Winter sale for VIP customers. 25% off selected items.",
type: "sale",
status: "active",
starts_at: "2022-07-01T00:00:00.000Z",
ends_at: "2022-07-31T00:00:00.000Z",
})
await manager.save(priceListNoCustomerGroups)
await manager.insert(Region, {
id: "region-pl",
name: "Test Region",
currency_code: "eur",
tax_rate: 0,
})
const moneyAmount1 = manager.create(MoneyAmount, {
id: "ma_test_1",
amount: 100,
currency_code: "usd",
min_quantity: 1,
max_quantity: 100,
price_list_id: "pl_no_customer_groups",
})
await manager.save(moneyAmount1)
const moneyAmount2 = manager.create(MoneyAmount, {
id: "ma_test_2",
amount: 80,
currency_code: "usd",
min_quantity: 101,
max_quantity: 500,
price_list_id: "pl_no_customer_groups",
})
await manager.save(moneyAmount2)
const moneyAmount3 = manager.create(MoneyAmount, {
id: "ma_test_3",
amount: 50,
currency_code: "usd",
min_quantity: 501,
max_quantity: 1000,
price_list_id: "pl_no_customer_groups",
})
await manager.save(moneyAmount3)
const moneyAmount4 = manager.create(MoneyAmount, {
id: "ma_test_4",
amount: 70,
currency_code: "usd",
})
await manager.save(moneyAmount4)
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma1-pl",
money_amount_id: "ma_test_1",
variant_id: "test-variant",
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma2-pl",
money_amount_id: "ma_test_2",
variant_id: "test-variant",
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma3-pl",
money_amount_id: "ma_test_3",
variant_id: "test-variant",
})
await manager.insert(ProductVariantMoneyAmount, {
id: "pvma4-pl",
money_amount_id: "ma_test_4",
variant_id: "test-variant",
})
const priceListWithMA = manager.create(PriceList, {
id: "pl_with_some_ma",
name: "Weeken sale",
description: "Desc. of the list",
type: "sale",
status: "active",
starts_at: "2022-07-01T00:00:00.000Z",
ends_at: "2022-07-31T00:00:00.000Z",
})
priceListWithMA.prices = [moneyAmount4]
await manager.save(priceListWithMA)
}