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

load account into context during surcharges #5466

Merged
merged 3 commits into from Aug 20, 2019

Conversation

cmbirk
Copy link
Contributor

@cmbirk cmbirk commented Aug 18, 2019

Original PR here: https://github.com/sportsdirect/reaction/pull/498

Resolves(but doesn't close) sportsdirect/reaction-plugin-pricing-engine#48
Impact: critical
Type: bug

Issue
Loads the account into the context object in the surcharges afterCartUpdate event. This is needed in context to choose the correct price in getVariantPrice from the pricing engine. It was previously calculating tax based on the full priced item instead of the member price, which was causing a mismatch at checkout time of the expected pricing.

cc @rosshadden @jrphilo @kkuzemka

Signed-off-by: Chris Birk <cmbirk@gmail.com>
if (cart.accountId && !context.account) {
const { Accounts } = context.collections;
const account = await Accounts.findOne({ _id: cart.accountId });
context.account = account;
Copy link
Contributor

Choose a reason for hiding this comment

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

The cart account may not be the same as the request account, and may have different permissions. Also, by mutating the “base” context, this value might stick around longer than you’re expecting and be used in subsequent event handler calls.

If you instead do contextWithAccount = { ...context, account, accountId: cart.accountId }; and then pass through contextWithAccount instead of context below, that's safe, though potentially not the best fix in the long run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed in bdc57ed

Signed-off-by: Chris Birk <cmbirk@gmail.com>
@cmbirk
Copy link
Contributor Author

cmbirk commented Aug 20, 2019

@aldeed this should be good to go. Have tested that member priced items can go through the entire checkout flow

@aldeed aldeed merged commit 3f577cb into reactioncommerce:develop Aug 20, 2019
@kieckhafer kieckhafer mentioned this pull request Aug 28, 2019
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.

None yet

2 participants