Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pricing,types): price list API + price calculations with price lists #5498

Merged
merged 52 commits into from
Nov 15, 2023

Conversation

riqwan
Copy link
Contributor

@riqwan riqwan commented Oct 30, 2023

what:

PriceList Service APIs:

  • createPriceList
  • updatePriceList
  • addPriceListPrices
  • removePriceListRules
  • setPriceListRules
  • deletePriceList
  • listPriceLists
  • listAndCountPriceLists

Price Calculations

  • Returns prices with price list prices
  • Returns a new shape with calculated and original prices

@changeset-bot
Copy link

changeset-bot bot commented Oct 30, 2023

🦋 Changeset detected

Latest commit: b4548c8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@medusajs/pricing Patch
@medusajs/types Patch
@medusajs/medusa-oas-cli Patch
@medusajs/oas-github-ci Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Visit Preview Nov 15, 2023 8:02pm
docs-ui ⬜️ Ignored (Inspect) Visit Preview Nov 15, 2023 8:02pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Nov 15, 2023 8:02pm

@riqwan riqwan changed the title [WIP] Price Lists feat(pricing,types): price list API + price calculations with price lists Nov 6, 2023
Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial reviews

packages/medusa/src/services/pricing.ts Show resolved Hide resolved
@@ -101,5 +101,39 @@ export class Migration20230929122253 extends Migration {
this.addSql(
'alter table "price_rule" add constraint "price_rule_price_set_money_amount_id_foreign" foreign key ("price_set_money_amount_id") references "price_set_money_amount" ("id") on update cascade on delete cascade;'
)

this.addSql(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: take or leave. In the product module to ensure it is always working, we have adding IF EXISTS / NOT EXISTS for every query on table/column/index etc. should we alwas do that. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In pricing migrations, I only did if exists for conflicting tables with the core. I don't think its necessary for those that are not available on the core. Happy to add if you think so, i don't have a strong opinion on this.

packages/pricing/src/models/price-list.ts Outdated Show resolved Hide resolved
packages/pricing/src/models/price-list.ts Outdated Show resolved Hide resolved
packages/pricing/src/repositories/price-list-rule-value.ts Outdated Show resolved Hide resolved
packages/pricing/src/repositories/price-list-rule.ts Outdated Show resolved Hide resolved
Comment on lines 109 to 118
this.addSql(
'create table "price_list_rule" ("id" text not null, "rule_type_id" text not null, "value" text not null, "priority" integer not null default 0, "price_list_id" text not null, constraint "price_list_rule_pkey" primary key ("id"));'
)

this.addSql(
'create index "IDX_price_list_rule_rule_type_id" on "price_list_rule" ("rule_type_id");'
)
this.addSql(
'create index "IDX_price_list_rule_price_list_id" on "price_list_rule" ("price_list_id");'
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be necessary considering id is the PK, but do we also want to add a Unique Index on (rule_type_id, price_list_id) unique combination?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, added in the unique constraint. 🔥

On the first comment, these are foreign keys here with which we scope on the table by, can you elaborate on why you think these aren't needed?

Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have a few comments regarding softDelete methods that we should consider to have in all the entities we expose and therefore can be extended.
But it doesn't need to be in this PR.

@riqwan riqwan requested review from olivermrbl and removed request for olivermrbl November 15, 2023 11:12
packages/medusa/src/services/pricing.ts Outdated Show resolved Hide resolved
packages/pricing/src/migrations/Migration20231107141520.ts Outdated Show resolved Hide resolved
packages/pricing/src/models/price-list.ts Outdated Show resolved Hide resolved
packages/pricing/src/repositories/price-list-rule.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, really awesome work 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants