commerce icon indicating copy to clipboard operation
commerce copied to clipboard

[4.x]: Coupon Code cannot be used in conjunction with a custom order adjustment "discount"

Open philipboomy opened this issue 2 years ago • 5 comments

What happened?

Description

Not sure if its classed as a bug but here goes.

In some cases the client need to be able to use a coupon code on orders where there is a custom adjustment "discount".

Whenever he enters the coupon code it removes the custom adjuster making it impossible to have both. Please see attached screenshots.

after-coupon before-coupon

Is it possible to have both somehow?

Craft CMS version

4.5.9

Craft Commerce version

4.3.1

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

philipboomy avatar Nov 01 '23 09:11 philipboomy

Is it possible that the conditions for the coupon and adjuster (or their calculations) conflict or are mutually exclusive?

Adjusters are applied in a consistent order (based on how they're registered), and may depend on previous adjustments at the time they're evaluated against the order. Are you able to share the full adjuster class, and your Event::on() block where it's registered?

AugustMiller avatar Nov 01 '23 21:11 AugustMiller

Hi August,

Thanks for looking into it. I cant see anything that would cause a conflict except the adjuster is a "discount" one.

class GiftCardAdjuster extends Component implements AdjusterInterface
{
    public function adjust(Order $order): array
    {
        $adjustment = new OrderAdjustment();

        $adjustment->type = 'discount';
        $adjustment->name = 'Gift Card';
        $adjustment->amount = 10;

        $adjustment->setOrder($order);

        return [$adjustment];
    }
}
Event::on(OrderAdjustments::class, OrderAdjustments::EVENT_REGISTER_ORDER_ADJUSTERS,
            function(RegisterComponentTypesEvent $event) {
              $event->types[] = GiftCardAdjuster::class;
            }
        );
 

philipboomy avatar Nov 02 '23 17:11 philipboomy

Ill attempt to reproduce using your example. Thanks.

lukeholder avatar Nov 08 '23 06:11 lukeholder

I tried to reproduce and I could not:

https://github.com/craftcms/commerce/assets/133571/d5f3d3eb-6055-4e46-ada0-a5d0538783c5

CleanShot 2023-11-08 at 14 57 07@2x

Let me know if I missed anything.

I am inclined to agree with August that maybe the custom adjuster is more complicated and logic is conflicting with the built-in discount rules.

lukeholder avatar Nov 08 '23 06:11 lukeholder

Thanks for looking into this. Could you try via the admin panel? Sorry I should have mentioned that we are only applying coupon codes via admin panel.

I did just test frontend and I can get it working like you but not via admin panel.

philipboomy avatar Nov 08 '23 07:11 philipboomy