commerce
commerce copied to clipboard
[4.x]: Gateway Events
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
- 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!'); } ); - 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!
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