Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@cmbirk cmbirk requested review from aldeed and rosshadden August 18, 2019 23:51
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

@cmbirk cmbirk requested a review from aldeed August 20, 2019 16:57
@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.

2 participants