fix(pricing, medusa): resolve minor pricing-module bugs (#5685)

* fix region price updates

* pricing migration: include title/name field value migration

* update migration scripts for pricing module

* move file to script utils

* rename file

* rename file

* add changeset

* remove redundant maps

* update migration script

* nit

* remove unnecessary variable

* filter before map

* array function naming cleanup

* chore: address pr reviews

---------

Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com>
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
This commit is contained in:
Riqwan Thamir
2023-11-23 17:11:47 +01:00
committed by GitHub
co-authored by Philip Korsholm Philip Korsholm
parent 02ea9ac3ac
commit 1e39a95f8a
9 changed files with 404 additions and 337 deletions
@@ -78,29 +78,34 @@ export async function upsertVariantPrices({
)
for (const price of prices) {
const region = price.region_id && regionsMap.get(price.region_id)
let region_currency_code: string | undefined
let region_rules: Record<string, string> | undefined
if (region) {
region_currency_code = region.currency_code
region_rules = {
region_id: region.id,
}
}
if (price.id) {
moneyAmountsToUpdate.push({
const priceToUpdate = {
id: price.id,
min_quantity: price.min_quantity,
max_quantity: price.max_quantity,
amount: price.amount,
currency_code: price.currency_code,
})
currency_code: region_currency_code ?? price.currency_code,
}
moneyAmountsToUpdate.push(priceToUpdate)
} else {
const region = price.region_id && regionsMap.get(price.region_id)
const variantPrice: PricingTypes.CreatePricesDTO = {
min_quantity: price.min_quantity,
max_quantity: price.max_quantity,
amount: price.amount,
currency_code: price.currency_code,
rules: {},
}
if (region) {
variantPrice.currency_code = region.currency_code
variantPrice.rules = {
region_id: region.id,
}
currency_code: region_currency_code ?? price.currency_code,
rules: region_rules ?? {},
}
delete price.region_id