-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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: promotions discounts v2 #6575
Conversation
|
f928e8e
to
8d4f6ea
Compare
f327784
to
3eca2c1
Compare
apps/reaction/tests/integration/api/mutations/discountCodes/discountCodes.test.js
Outdated
Show resolved
Hide resolved
packages/api-plugin-promotions-discounts/src/discountTypes/order/applyOrderDiscountToCart.js
Outdated
Show resolved
Hide resolved
packages/api-plugin-promotions-discounts/src/discountTypes/shipping/getGroupDisountTotal.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update the sample data to reflect these changes
Applied discounts is not coming through on the order. Also I think should include at least one top level integration test that tests the functionality end to end:
I think this will really help us as we make tweaks to this to ensure we don't break it |
f14f2a1
to
1efb2de
Compare
1efb2de
to
7d1ba64
Compare
7d1ba64
to
f4cf8fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few typos and things but it looks good
opaqueFulfillmentMethodId = option.fulfillmentMethod._id; | ||
}); | ||
|
||
test("select the `Standard mockMethod` fulfillment option", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are set up like separate tests but in fact there is only one test, which should describe what it's testing, e.g. "place an order with discount and get the correct values"
@@ -34,5 +34,10 @@ | |||
}, | |||
"publishConfig": { | |||
"access": "public" | |||
}, | |||
"scripts": { | |||
"test": "jest --passWithNoTests", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove this passWithNoTests
because it should not pass with no tests
packages/api-plugin-discounts/src/util/setDiscountsOnCart.test.js
Outdated
Show resolved
Hide resolved
packages/api-plugin-promotions-discounts/src/actions/discountAction.js
Outdated
Show resolved
Hide resolved
packages/api-plugin-promotions-discounts/src/discountTypes/item/applyItemDiscountToCart.test.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason when i diff the working tree of the base feat/promotions
branch with this PR's branch, it says that it deletes the defaultRoles for the promotions.
"reaction:legacy:promotions/create",
"reaction:legacy:promotions/read",
"reaction:legacy:promotions/update"
I think Brian just hasn't rebased against the feature branch as that just got merged today |
* @returns {Number} - The discount amount | ||
*/ | ||
export function getCartDiscountAmount(context, items, discount) { | ||
const merchandiseTotal = getTotalEligibleItemsAmount(items); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we calculate the merchandise total here, when the enhancer is doing the same?
Another question is if we calculate it here, why do we need the enhancer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this variable should be rename to totalEligibleItemsAmount
, this total is different, it counts inclusion and exclusion and used for discount value calculation.
Enhancer can do sth more dynamic like total of item quantity. Enhancer is at general level of the framework. this totalEligibleItemsAmount
is in detail of discount plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
In the
api-plugin-promotions
graphql schema thePromotionFilter
input should be suffixed byInput
to match the style of all graphql inputs. -
The
createPromotion
mutation should usePromotionInput
simple schema for the input. Also the following code in the same mutation:
const { triggerKey } = promotions.triggers[0];
const trigger = promotions.triggers.find((tr) => tr.triggerKey === triggerKey);
promotion.triggerType = trigger.type;
Can't it be simplified to:
promotion.triggerType = promotions.triggers[0].type;
Regarding the |
@@ -7,6 +7,9 @@ import getDiscountsTotalForCart from "../queries/getDiscountsTotalForCart.js"; | |||
* @returns {undefined} | |||
*/ | |||
export default async function setDiscountsOnCart(context, cart) { | |||
const { total } = await getDiscountsTotalForCart(context, cart); | |||
cart.discount = total; | |||
// check if promotion discounts are enabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to remove this plugin altogether?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding this code is safer. Someone may still install both dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- In the
api-plugin-promotions
graphql schema thePromotionFilter
input should be suffixed byInput
to match the style of all graphql inputs.- The
createPromotion
mutation should usePromotionInput
simple schema for the input. Also the following code in the same mutation:const { triggerKey } = promotions.triggers[0]; const trigger = promotions.triggers.find((tr) => tr.triggerKey === triggerKey); promotion.triggerType = trigger.type;
Can't it be simplified to:
promotion.triggerType = promotions.triggers[0].type;
No, because it may be an array with multiple triggers at some point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to remove this plugin altogether?
The plugin should be removed but I would like to retain backwards compatibility if possible
Overall, the plugin looks excellent with the sample data. I still don't have a settled mindmap of the whole framework but it seems like it's really extendable. |
I agree about putting together an (an ADR is what I am assuming you meant) but I don't think we want to introduce new legacy code here |
Yes, this is just discounts. This is being addressed here |
@zenweasel Do you have opinion on this, it seems like the API part. I think it should address these in another PR. |
Yes, all the comments about the api should be dealt in a different pr |
…nts-v2 feat: promotions discounts v2
Resolves #6458 #6462 #6459 #6453 #6468
Impact: major
Type: feature
Issue
Missing discounts in the new promotion framework
Solution
Adding api-plugin-discounts