feat(core-flows,pricing,medusa,pricing,types,utils): Price List Prices can have their own rules (#5752)
**What** - Add price-rules for prices in price-lists - make rules object optional when creating prices **Why** - more price granularity Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
This commit is contained in:
co-authored by
Philip Korsholm
parent
f05c20695e
commit
079f0da83f
@@ -1,5 +1,6 @@
|
||||
import { MedusaV2Flag } from "@medusajs/utils"
|
||||
import { updatePriceLists } from "@medusajs/core-flows"
|
||||
import { MedusaContainer } from "@medusajs/types"
|
||||
import { MedusaV2Flag } from "@medusajs/utils"
|
||||
import { Type } from "class-transformer"
|
||||
import { IsArray, IsBoolean, IsOptional, ValidateNested } from "class-validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
@@ -8,7 +9,6 @@ import { PriceList } from "../../../.."
|
||||
import PriceListService from "../../../../services/price-list"
|
||||
import { AdminPriceListPricesUpdateReq } from "../../../../types/price-list"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { MedusaContainer } from "@medusajs/types"
|
||||
import { getPriceListPricingModule } from "./modules-queries"
|
||||
|
||||
/**
|
||||
|
||||
@@ -121,6 +121,12 @@ export const defaultAdminPriceListRemoteQueryObject = {
|
||||
"updated_at",
|
||||
],
|
||||
},
|
||||
price_rules: {
|
||||
fields: ["value"],
|
||||
rule_type: {
|
||||
fields: ["rule_attribute"],
|
||||
},
|
||||
},
|
||||
price_set: {
|
||||
variant_link: {
|
||||
variant: {
|
||||
|
||||
+7
-1
@@ -65,12 +65,18 @@ export async function listAndCountPriceListPricingModule({
|
||||
priceList.prices = priceSetMoneyAmounts.map((priceSetMoneyAmount) => {
|
||||
const productVariant = priceSetMoneyAmount.price_set.variant_link.variant
|
||||
|
||||
const rules = priceSetMoneyAmount.price_rules.reduce((acc, curr) => {
|
||||
acc[curr.rule_type.rule_attribute] = curr.value
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
return {
|
||||
...(priceSetMoneyAmount.money_amount as MoneyAmount),
|
||||
price_list_id: priceList.id,
|
||||
variant_id: productVariant?.id ?? null,
|
||||
variant: productVariant ?? null,
|
||||
region_id: null,
|
||||
region_id: rules["region_id"] ?? null,
|
||||
rules,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user