Where are Commerce 2 hooks (or Events) in Commerce 2

Drupal Answers Asked by Wally Kolcz on October 26, 2021

I am working on replacing our payment system from D7/DC1 to D8/DC2 and the original code makes use of hooks. I have replaced some of them with events but I cannot find any information on the DC2 versions of:


Are they still the same or much like the former cart (add, update, remove) hooks, these are also events but I can’t locate documentation on them. Anyone know the equivalent events or where to find the docs on these (or their replacements)

/* Small Update */

I found OrderEvents and I think I need ORDER_PAID to replace mymodule_form_commerce_checkout_complete()

Does this look correct?

I added OrderEvents::ORDER_PAID => ‘orderPaid’ to my getSubscribedEvents(){} array and have:

public function orderPaid(OrderEvent $event){
    $order = $event->getEntity();
    //Some internal logic here

Tried a hook form alter and ran through my checkout process and nothing is showing in the logs

function srs_hook_form_alter(&$form, $form_state, $form_id){
  Drupal::logger('hook_form_alter fires')->info('<pre><code>' . print_r($form_id, TRUE) . '</code></pre>');


One Answer

as you've discovered, you can look in any module's src/Event/*Events.php file to find a list of their events. Using the order paid event is one way to react once you know that payment has been collected, but note that in scenarios where an order is placed with only a payment authorization (and not a capture), that event would not have been fired yet.

That may be fine in your case - if not, I'd recommend the or events that are triggered when the order is placed. That event is coming from the state machine module and correlates to order workflow transitions. You can read more about it in the module's readme.

As for form alters, those exist in D8 as they did in D7.

Answered by Ryan Szrama on October 26, 2021

Add your own answers!

Related Questions

How to create and check block revisions?

1  Asked on November 8, 2021 by user3560198


Custom module with config exposed in json api

1  Asked on November 8, 2021 by daniel-harper


Not able to see < character in front end

2  Asked on November 5, 2021 by jos-l


Limit filter operators

1  Asked on November 5, 2021


Dynamic filters based on another filter

1  Asked on November 5, 2021 by soundcheese


How to add a field to menus?

1  Asked on October 26, 2021


Drush cr is responding with Bootstrap Failed

0  Asked on October 26, 2021 by chanel


How do I create a table when a module is installed?

1  Asked on October 26, 2021 by david-montera


Approaches for multi-field values

0  Asked on October 26, 2021 by ian-stewart


Pager not being rebuilt after $form_state->setRebuild() is called

0  Asked on October 26, 2021 by kenny83


Where are Commerce 2 hooks (or Events) in Commerce 2

1  Asked on October 26, 2021 by wally-kolcz


Show own content in Media Library

0  Asked on October 26, 2021 by rafaticarte


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP