1

In Craft Commerce 1, there is documentation on how to re-order adjustments that do similar things. https://docs.craftcms.com/commerce/v1/adjusters.html#ordering-adjustments

But I don't see any similar documentation for how to do that in Commerce 2.

I have 2 plugins that make adjustments to the Sale price and then Order total, but if run in the wrong order, it doesn't work.

Simple solution is to uninstall the plugins and install them in the correct sequence, but was wondering if there was still a way to force them to run in a certain order.

1

Looking at the \craft\commerce\services\OrderAdjustments you should be able to change the ordering of your adjustments by using the \craft\commerce\services\OrderAdjustments::EVENT_REGISTER_ORDER_ADJUSTERS event.

use craft\events\RegisterComponentTypesEvent;
use craft\commerce\services\OrderAdjustments;
use yii\base\Event;

Event::on(
    OrderAdjustments::class,
    OrderAdjustments::EVENT_REGISTER_ORDER_ADJUSTERS,
    function (RegisterComponentTypesEvent $e) {
        $e->types = [
            // Add the adjusters in whatever order you want here. Leaving this empty would disable all adjusters.
        ];
    }
);
  • So I'm using the Verbb Gift Voucher plugin in conjunction with my custom one. You're saying when I register my Adjuster, it should look something like: $event->types = [ GiftVoucherAdjuster::class, CartAdjustmentsAdjuster::class ]; – Marc Miller Mar 5 '19 at 21:16
  • Actually, I need the Gift Vouchers Adjuster to run before my CartAdjustementAdjuster. Doing this in my plugin, then disabling and enabling the 2 plugins again doesn't seem to work. Do I have to uninstall and install again? Then I'm back to square one and just easier to install in the correct order. – Marc Miller Mar 6 '19 at 3:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.