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: promotions discounts v2 #6575

Merged
merged 19 commits into from
Nov 16, 2022
Merged

Conversation

vanpho93
Copy link
Member

@vanpho93 vanpho93 commented Oct 19, 2022

Resolves #6458 #6462 #6459 #6453 #6468
Impact: major
Type: feature

Issue

Missing discounts in the new promotion framework

Solution

Adding api-plugin-discounts

@changeset-bot
Copy link

changeset-bot bot commented Oct 19, 2022

⚠️ No Changeset found

Latest commit: bc2451b

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

@vanpho93 vanpho93 changed the base branch from trunk to feat/promotion-framework-secound-approach October 19, 2022 06:37
Base automatically changed from feat/promotion-framework-secound-approach to feat/promotions October 25, 2022 01:14
@vanpho93 vanpho93 force-pushed the feat/promotions-discounts-v2 branch 2 times, most recently from f327784 to 3eca2c1 Compare October 31, 2022 11:15
@vanpho93 vanpho93 marked this pull request as ready for review November 7, 2022 07:11
Copy link
Collaborator

@zenweasel zenweasel left a 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

@zenweasel
Copy link
Collaborator

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:

  1. Create a promotion (using the mutation preferably)
  2. Create a cart (there is existing test stuff you can reuse)
  3. Validate that the promotions and discounts are applied
  4. Place an order
  5. Validate that the promotions and discounts are carried through to the order

I think this will really help us as we make tweaks to this to ensure we don't break it

Copy link
Collaborator

@zenweasel zenweasel left a 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 () => {
Copy link
Collaborator

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",
Copy link
Collaborator

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

zenweasel and others added 2 commits November 15, 2022 05:03
Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
Copy link

@traykov1 traykov1 left a 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"

@zenweasel
Copy link
Collaborator

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);
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

@tedraykov tedraykov left a 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 the PromotionFilter input should be suffixed by Input to match the style of all graphql inputs.

  • The createPromotion mutation should use PromotionInput 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;

@tedraykov
Copy link
Collaborator

Regarding the success field in the PromotionCreateUpdatePayload I would suggest we create and accept an ARD before we start introducing new schema styles.

@@ -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
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

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 the PromotionFilter input should be suffixed by Input to match the style of all graphql inputs.
  • The createPromotion mutation should use PromotionInput 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

Copy link
Collaborator

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

@tedraykov
Copy link
Collaborator

tedraykov commented Nov 15, 2022

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.
In this PR I don't see being addressed what happens with existing carts with applied promotions when existing promotion parameters are changed but I assume it will be addressed separately.

@zenweasel
Copy link
Collaborator

Regarding the success field in the PromotionCreateUpdatePayload I would suggest we create and accept an ARD before we start introducing new schema styles.

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

@zenweasel
Copy link
Collaborator

zenweasel commented Nov 16, 2022

In this PR I don't see being addressed what happens with existing carts with applied promotions when existing promotion parameters are changed but I assume it will be addressed separately.

Yes, this is just discounts. This is being addressed here

@vanpho93
Copy link
Member Author

  • In the api-plugin-promotions graphql schema the PromotionFilter input should be suffixed by Input to match the style of all graphql inputs.
  • The createPromotion mutation should use PromotionInput 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;

@zenweasel Do you have opinion on this, it seems like the API part. I think it should address these in another PR.

@zenweasel
Copy link
Collaborator

Yes, all the comments about the api should be dealt in a different pr

@zenweasel zenweasel merged commit e8f5762 into feat/promotions Nov 16, 2022
@zenweasel zenweasel deleted the feat/promotions-discounts-v2 branch November 16, 2022 04:00
vanpho93 pushed a commit that referenced this pull request Apr 24, 2023
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.

As an admin I want to be able to apply a discount to an order via a trigger
4 participants