feat(pricing, types, utils): Exact match based on context + fallback on rule priority if not (#5214)
* initial * initial service * update pricing module service * add integration test for rule-type * update pricing-module integration tests * update pricing service interface * feat(pricing): PriceSets as entry point to pricing module * chore: add price set money amount * chore: add price set money amount * chore: change name of test * chore: added changeset * chore: use filterable props from money amount in price sets * chore: update migrations * test update integration test * fix weird behavior * Update packages/pricing/integration-tests/__fixtures__/rule-type/index.ts Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> * Apply suggestions from code review Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> * move rule-type to common * chore: reset migration * chore: remove incorrect conflicts * chore: address review * chore: remove ghost price list * Apply suggestions from code review Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> * update id prefix * use persist not persistAndflush * rename key_value to rule_attribute * more renaming * feat(types,pricing): add price set money amount rules to pricing module * chore: cleanup + add test cases for relationship update * chore: revert package json * chore: cleanup * initial * update pricing module service * update pricing-module integration tests * update pricing service interface * chore: update migrations * fix weird behavior * Apply suggestions from code review Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> * move rule-type to common * chore: delete duplicate migration files * fix(link-modules): Fix link module initialization (#4990) **What** Add a new configuration on the relationship to specify if the relation is consumed from an internal service (from medusa core). In that case do not check if the service is part of the loaded modules * initial price rule * rebase develop * save here * final changes to create * update price rule integration test * add module integraiton tests for price rules * fix merge * redo wierd order change * pr cleanup * pr cleanup * pr cleanup * update pr * sort out migrations * [wip] * wip * chore: temporarily emulate mikroorm internals * currency code hard filtering * before creating subqueries * chore: wip * chore: wip * chore: add exact match multiple contexts * chore: add one more test * chore: add query that works with exact match * chore: qb the thingy * chore: add some comments * chore: removed extra filter * chore: added some more comments + prettify * chore: test with carlos * chore: add fallbacks and exact match tests * chore: cleanup * feat(types,pricing): add price set money amount rules to pricing module (#5065) * initial * initial service * update pricing module service * add integration test for rule-type * update pricing-module integration tests * update pricing service interface * feat(pricing): PriceSets as entry point to pricing module * chore: add price set money amount * chore: add price set money amount * chore: change name of test * chore: added changeset * chore: use filterable props from money amount in price sets * chore: update migrations * test update integration test * fix weird behavior * Update packages/pricing/integration-tests/__fixtures__/rule-type/index.ts Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> * Apply suggestions from code review Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> * move rule-type to common * chore: reset migration * chore: remove incorrect conflicts * chore: address review * chore: remove ghost price list * Apply suggestions from code review Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> * update id prefix * use persist not persistAndflush * rename key_value to rule_attribute * more renaming * feat(types,pricing): add price set money amount rules to pricing module * chore: cleanup + add test cases for relationship update * chore: revert package json * chore: cleanup --------- Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com> Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> * chore: minor cleanup * chore: added money amount scoping * chore: added review comments * chore: update changset and undo test scoping * chore: introduce group by util + no queries on empty context * Feat/pricing module methods (#5218) chore: add removePrices to pricing module * Revert "Feat/pricing module methods (#5218)" (#5236) This reverts commit 95c8aaa66423d290a35b6e736e5b187e12d44a36. * chore: review changes * chore: update schema * chore: reset migration --------- Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com> Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
export { default as Currency } from "./currency"
|
||||
export { default as MoneyAmount } from "./money-amount"
|
||||
export { default as PriceRule } from "./price-rule"
|
||||
export { default as PriceSet } from "./price-set"
|
||||
export { default as PriceSetMoneyAmount } from "./price-set-money-amount"
|
||||
export { default as PriceSetMoneyAmountRules } from "./price-set-money-amount-rules"
|
||||
export { default as RuleType } from "./rule-type"
|
||||
export { default as PriceRule } from "./price-rule"
|
||||
@@ -1,21 +1,16 @@
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
ManyToMany,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import MoneyAmount from "./money-amount"
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import PriceSet from "./price-set"
|
||||
import PriceSetMoneyAmount from "./price-set-money-amount"
|
||||
import RuleType from "./rule-type"
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
|
||||
type OptionalFields = "id" | "is_dynamic" | "priority"
|
||||
type OptionalRelations = "price_set" | "rule_type" | "price_set_money_amount"
|
||||
@@ -31,6 +26,8 @@ export default class PriceRule {
|
||||
entity: () => PriceSet,
|
||||
fieldName: "price_set_id",
|
||||
name: "price_rule_price_set_id_unique",
|
||||
onDelete: "cascade",
|
||||
index: "IDX_price_rule_price_set_id",
|
||||
})
|
||||
price_set: PriceSet
|
||||
|
||||
@@ -38,6 +35,7 @@ export default class PriceRule {
|
||||
entity: () => RuleType,
|
||||
fieldName: "rule_type_id",
|
||||
name: "price_rule_rule_type_id_unique",
|
||||
index: "IDX_price_rule_rule_type_id",
|
||||
})
|
||||
rule_type: RuleType
|
||||
|
||||
@@ -54,6 +52,7 @@ export default class PriceRule {
|
||||
entity: () => PriceSetMoneyAmount,
|
||||
fieldName: "price_set_money_amount_id",
|
||||
name: "price_set_money_amount_id_unique",
|
||||
index: "IDX_price_rule_price_set_money_amount_id",
|
||||
})
|
||||
price_set_money_amount: PriceSetMoneyAmount
|
||||
|
||||
|
||||
35
packages/pricing/src/models/price-set-money-amount-rules.ts
Normal file
35
packages/pricing/src/models/price-set-money-amount-rules.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import PriceSetMoneyAmount from "./price-set-money-amount"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
@Entity()
|
||||
export default class PriceSetMoneyAmountRules {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@ManyToOne(() => PriceSetMoneyAmount, {
|
||||
index: "IDX_price_set_money_amount_rules_price_set_money_amount_id",
|
||||
})
|
||||
price_set_money_amount?: PriceSetMoneyAmount | string
|
||||
|
||||
@ManyToOne(() => RuleType, {
|
||||
index: "IDX_price_set_money_amount_rules_rule_type_id",
|
||||
})
|
||||
rule_type?: RuleType | string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
value: string
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "psmar")
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,19 @@
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryKey,
|
||||
PrimaryKeyType,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import MoneyAmount from "./money-amount"
|
||||
import PriceRule from "./price-rule"
|
||||
import PriceSet from "./price-set"
|
||||
import PriceSetMoneyAmountRules from "./price-set-money-amount-rules"
|
||||
|
||||
@Entity()
|
||||
export default class PriceSetMoneyAmount {
|
||||
@@ -30,6 +34,21 @@ export default class PriceSetMoneyAmount {
|
||||
})
|
||||
money_amount?: MoneyAmount
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
number_rules?: number
|
||||
|
||||
@OneToMany({
|
||||
entity: () => PriceRule,
|
||||
mappedBy: (pr) => pr.price_set_money_amount,
|
||||
})
|
||||
price_rules = new Collection<PriceRule>(this)
|
||||
|
||||
@OneToMany({
|
||||
entity: () => PriceSetMoneyAmountRules,
|
||||
mappedBy: (psmar) => psmar.price_set_money_amount,
|
||||
})
|
||||
price_set_money_amount_rules = new Collection<PriceSetMoneyAmountRules>(this)
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "psma")
|
||||
|
||||
@@ -1,20 +1,36 @@
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
ManyToMany,
|
||||
OneToMany,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import MoneyAmount from "./money-amount"
|
||||
import PriceRule from "./price-rule"
|
||||
import PriceSetMoneyAmount from "./price-set-money-amount"
|
||||
|
||||
@Entity()
|
||||
export default class PriceSet {
|
||||
[OptionalProps]?: "price_set_money_amounts"
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@OneToMany(() => PriceSetMoneyAmount, (psma) => psma.price_set, {
|
||||
cascade: [Cascade.REMOVE],
|
||||
})
|
||||
price_set_money_amounts = new Collection<PriceSetMoneyAmount>(this)
|
||||
|
||||
@OneToMany(() => PriceRule, (pr) => pr.price_set, {
|
||||
cascade: [Cascade.REMOVE],
|
||||
})
|
||||
price_rules = new Collection<PriceRule>(this)
|
||||
|
||||
@ManyToMany({
|
||||
entity: () => MoneyAmount,
|
||||
pivotEntity: () => PriceSetMoneyAmount,
|
||||
|
||||
Reference in New Issue
Block a user