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

fix: Exclude deleted price lists and prices from pricing calculations #9015

Conversation

panalgin
Copy link

@panalgin panalgin commented Sep 5, 2024

Hello,

Description of the bug

A bug was discovered in the pricing calculation logic where deleted price lists and prices were still being considered, potentially leading to incorrect pricing information.

Fix implementation

The fix adds two conditions:

  1. A condition to the left join in the calculatePrices method to ensure only non-deleted price lists are considered.
  2. A where clause to the base price table select function to exclude deleted prices.

Code changes

  1. Price List Join:
.leftJoin("price_list as pl", function () {
  this.on("pl.id", "price.price_list_id").andOn(
    "pl.status",
    knex.raw("?", [PriceListStatus.ACTIVE])
  ).andOn(knex.raw("pl.deleted_at IS NULL"))
})
  1. Base Price Table Select:
.where(knex.raw("price.deleted_at IS NULL"))

Impact and importance

These fixes are crucial for accurate pricing calculations, ensuring that only active, non-deleted price lists and prices are considered.

Testing

Unable to write test cases due to module tests not working, but the fixes have been manually verified.

Additional notes

  • No new dependencies or API changes.
  • Minimal changes addressing specific edge cases.
  • Future testing improvements are needed.
  • These changes prevent potential issues with pricing calculations that could arise from considering deleted data.

I'm open to any feedback or suggestions for improvement. Thank you for considering this pull request.

Deleting a price list from this screen:
image

In the database, the record is deleted but because its status still active, and no-check for deleted_at
image

Copy link

changeset-bot bot commented Sep 5, 2024

⚠️ No Changeset found

Latest commit: 704f8c4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

vercel bot commented Sep 5, 2024

@panalgin is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

@panalgin panalgin changed the title Fix: Exclude deleted price lists from pricing calculations fix: Exclude deleted price lists from pricing calculations Sep 5, 2024
@panalgin panalgin marked this pull request as ready for review September 5, 2024 12:00
@panalgin panalgin requested a review from a team as a code owner September 5, 2024 12:00
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.

LGTM

Copy link
Contributor

@riqwan riqwan left a comment

Choose a reason for hiding this comment

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

good catch! @panalgin

@panalgin panalgin changed the title fix: Exclude deleted price lists from pricing calculations fix: Exclude deleted price lists and prices from pricing calculations Sep 5, 2024
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.

legend @panalgin – thanks for the contribution

@Attachai77
Copy link

Could you merge this ?

@fPolic
Copy link
Contributor

fPolic commented Sep 27, 2024

This was fixed in the meantime as part of #9265.

@olivermrbl
Copy link
Contributor

@fPolic, can we close this?

@fPolic
Copy link
Contributor

fPolic commented Sep 27, 2024

Yes

@fPolic fPolic closed this Sep 27, 2024
@panalgin panalgin deleted the fix/deleted-pricelist-affects-calculated-price branch October 7, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants