[4.x]: Coupon Code cannot be used in conjunction with a custom order adjustment "discount"
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.
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
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?
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;
}
);
Ill attempt to reproduce using your example. Thanks.
I tried to reproduce and I could not:
https://github.com/craftcms/commerce/assets/133571/d5f3d3eb-6055-4e46-ada0-a5d0538783c5
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.
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.