commerce icon indicating copy to clipboard operation
commerce copied to clipboard

[4.x]: Gateway Events

Open AugustMiller opened this issue 2 years ago • 1 comments

What happened?

Description

Events are not currently emitted by craft\commerce\base\Gateway or craft\commerce\services\Gateways when saving a Gateway’s configuration.

Craft typically emits events from the service class when saving Project Config-bound changes (beforeSave when modifying values, then afterSave in a PC event handler). The model events appear to be less consistently triggered…

Steps to reproduce

  1. Add a listener in a custom module:
    use craft\events\ModelEvent;
    use craft\commerce\base\Gateway;
    use yii\base\Event;
    
    Event::on(
       Gateway::class,
       Gateway::EVENT_BEFORE_SAVE,
        function(craft\events\ModelEvent $event) {
            Craft::dd('Got it!');
        }
    );
    
  2. Save a new or existing gateway

Expected behavior

  • Using the example code, the page is halted.
  • I should also be able to listen to events from the service class, i.e. craft\commerce\services\Gateways::EVENT_BEFORE_SAVE_GATEWAY.

Actual behavior

No event is triggered.


Originally reported on Discord!

AugustMiller avatar Jul 18 '23 18:07 AugustMiller

Thanks for reporting. This is the same for some other project config based settings. Added this to the list for Commerce 5.

Others will include:

  • [ ] Order Statuses
  • [ ] Line Item Statuses
  • [ ] Gateways
  • [x] Emails
  • [x] PDFs
  • [x] Product Types

lukeholder avatar Jul 25 '23 08:07 lukeholder