Promotion compatibility logic fails when invoked from the admin

Created on 14 January 2021, about 4 years ago
Updated 20 March 2025, 20 days ago

Describe your bug or feature request.

If a bug, provide steps to reproduce it from a clean install.

  1. Edit a "draft" order
  2. Apply a coupon code to it, belonging to a promotion that has a compatibility set to "not with any other promotions"
  3. Re-edit the same order, simply save the form
  4. You now get a validation error with the following message: "The provided coupon code is invalid".

The reason for that is that the order is validated before being saved/refresh, therefore the logic in "Promotion::applies()" considers that the promotion doesn't apply because there's already a promotion applied.

I think we should add an additional check in that logic (check that the adjustment source ID doesn't match the promotion being evaluated, though I'm wondering if that wouldn't technically allow reapplying the same promotion.

We should probably change the following:

        foreach ($order->collectAdjustments() as $adjustment) {
          if ($adjustment->getType() == 'promotion') {
            return FALSE;
          }
        }

to

        foreach ($order->collectAdjustments() as $adjustment) {
          if ($adjustment->getType() == 'promotion' && $adjustment->getSourceId() !== $this->id()) {
            return FALSE;
          }
        }
🐛 Bug report
Status

Closed: duplicate

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

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024