Introduce a new event for filtering the available promotions for an order

Created on 8 February 2023, almost 2 years ago
Updated 3 March 2023, over 1 year ago

Describe your bug or feature request.

Similar to the event that exists in Commerce shipping, we need a new event dispatched when available promotions are loaded for a given order from the promotion storage.

This event would allow event subscribers to filter out promotions that aren't available based on custom logic and/or alter the sorting that is currently solely based on weight.

Thanks to the subscriber, it'd be possible to sort the available promotions based on the value it provides to the customer for example.

Patch to follow.

Feature request
Status

Fixed

Version

2.0

Component

Promotions

Created by

🇮🇱Israel jsacksick

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jsacksick
  • Status changed to Needs review almost 2 years ago
  • 🇮🇱Israel jsacksick

    Patch needs test, but attached a first stab at this.

  • 🇺🇸United States lisastreeter

    This is great! Thank you. We are using a custom PromotionStorage class to override the loadAvailable method to sort promotions by value to the customer.

    The approach here will work perfectly for us--we can use the same code in an event subscriber instead of the custom class.

  • 🇳🇴Norway zaporylie

    This will work great for some simple scenarios where promotions can be universally sorted, ie. Promotion A has a better value than Promotion B so it should apply first.

    Example:
    Merchant has Promotion A with the amount-based offer of 30 USD and Promotion B with the amount-based offer of 50 USD. Given both promotions apply to the Order and both have the compatibility set to none one can decide whether to apply Promotion A OR Promotion B by sorting them accordingly, ex. by the amount value.

    I think this case alone makes it a good API addition.

    My case however is slightly more complex.

    Example:
    Merchant has Promotion A with the amount-based offer of 30 USD and Promotion B with the percentage-based offer of 30%. Given both promotions apply to the Order and both have the compatibility set to none one should be able to determine which promotion gives a better value to the customer in the context of order item. Therefore if the Unit Price of the Order Item is lower than 100 USD Promotion A gives a better value, but if the Unit Price of the Order Item is greater than 100 USD then Promotion B gives a better value to the customer. When the Unit Price is equal to 100 USD the discount value is equal for Promotion A and Promotion B therefore one with the lower weight applies.

    This example can get more complex by utilizing Combination Offers plugin.

    As I said earlier I think this addition makes sense and is in line with how it is done in the Commerce Shipping module (as already mentioned in the issue summary) but at the same time I hope we can find a way where one can sort Promotions by their value in the context of Order Item

  • 🇮🇱Israel jsacksick

    Added tests coverage.

  • 🇮🇱Israel jsacksick

    Minor code refactoring + code styling changes.

    • jsacksick committed a1db0a2d on 8.x-2.x
      Issue #3340212 by jsacksick: Introduce a new event for filtering the...
  • Status changed to Fixed over 1 year ago
  • 🇮🇱Israel jsacksick

    Committed the patch from #6, thanks for your feedbacks!

    • jsacksick committed e366cde8 on 3.0.x
      Issue #3340212 by jsacksick: Introduce a new event for filtering the...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024