+
Skip to content

feat: stackability resolution strategy #6823

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

Merged

Conversation

vanpho93
Copy link
Member

Resolves #6820
Impact: major
Type: feature

Issue

Currently we pick promotions randomly.

Solution

Pick the best combination of promotions and let other plugin override this implementation.

@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2023

🦋 Changeset detected

Latest commit: c4c69f3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@reactioncommerce/api-plugin-promotions Minor
reaction Patch

Not sure what this means? Click here to learn what changesets are.

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

@vanpho93 vanpho93 changed the title feat: pick the best combination of promotions feat: stackability resolution strategy Mar 10, 2023
@vanpho93 vanpho93 requested review from brent-hoover and removed request for brent-hoover March 10, 2023 03:51
@brent-hoover brent-hoover requested a review from sujithvn April 7, 2023 05:22
Copy link
Contributor

Choose a reason for hiding this comment

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

We could add 2 more promos with discountCalculationMethod = none and null

let copiedCart = _.cloneDeep(cart);
for (const promo of combinationPromotions) {
// eslint-disable-next-line no-await-in-loop
const { affected, temporaryAffected } = await utils.actionHandler(context, copiedCart, promo);
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume the return values affected & temporaryAffected will be defined by the actionHandler funcs of child plugins (ex packages/api-plugin-promotions-discounts/src/discountTypes/order/applyOrderDiscountToCart.js). I have not reviewed them now and will review while merging feat/promotions.
Meanwhile, I could not find the field temporaryAffected being returned by any handler. only affected & reason were returned

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add remaining entries from util folder here?


// eslint-disable-next-line no-await-in-loop
const result = await actionFn.handler(context, enhancedCart, { promotion, ...action });
({ affected, temporaryAffected, reason: rejectedReason } = result);
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned earlier, I could not find the field temporaryAffected being returned by any handler. May be I missed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vanpho93

I am not sure if my understanding is correct, thought of verifying with you.

I added few additional promotions (assuming that it is valid to have more than 1+ explicit promos also)
New input:

const promotion1 = {
    _id: "promotionId1",
    triggerType: "implicit",
    discount: 2,
    type: "order",
    stackability: {
      key: "all"
    }
  };

  const promotion1ex = {
    _id: "promotionId1ex",
    triggerType: "explicit",
    discount: 2,
    type: "order",
    stackability: {
      key: "all"
    }
  };

  const promotion2 = {
    _id: "promotionId2",
    triggerType: "implicit",
    discount: 3,
    type: "item",
    stackability: {
      key: "all"
    }
  };

  const promotion2ex = {
    _id: "promotionId2ex",
    triggerType: "explicit",
    discount: 3,
    type: "item",
    stackability: {
      key: "all"
    }
  };

  const promotion3 = {
    _id: "promotionId3",
    triggerType: "implicit",
    discount: 4,
    type: "item",
    stackability: {
      key: "all"
    }
  };

  const promotion3ex = {
    _id: "promotionId3ex",
    triggerType: "implicit",
    discount: 4,
    type: "item",
    stackability: {
      key: "none"
    }
  };

  const promotion4 = {
    _id: "promotionId4",
    triggerType: "implicit",
    discount: 4,
    type: "item",
    stackability: {
      key: "per-type"
    }
  };

My expected output was :

[
    [promotion1, promotion4],
    [promotion1, promotion1ex, promotion2, promotion2ex, promotion3],
    [promotion3ex]
  ]

Actual output was :

[
    [promotion4],
    [promotion1, promotion1ex, promotion2, promotion2ex, promotion3],
    [promotion3ex]
  ]

I was expecting prom1(type=order) could combine with promo4(type=item)

@sujithvn sujithvn self-requested a review May 19, 2023 01:57
Signed-off-by: vanpho93 <vanpho02@gmail.com>
@vanpho93 vanpho93 force-pushed the feat/pick-the-best-combination-of-promotions branch from 92dc44f to c4c69f3 Compare May 22, 2023 07:39
@vanpho93 vanpho93 changed the base branch from feat/promotions to feat/promotions-signed May 22, 2023 07:39
@vanpho93 vanpho93 merged commit 0dfebce into feat/promotions-signed May 22, 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.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载