By james, 19 December, 2023
Door 19 revealing ECA Commerce

Welcome back to the Drupal Advent calendar for another door opening! Today Nic Laflin (nicxvan) is here to tell us about the ECA Commerce module.

Today’s module integrates two important Drupal ecosystems Commerce and ECA!

In Drupal 7 if you were building a commerce site then the Rules module was essential to set up notifications and pricing changes. Rules had a rich ecosystem and you could react to almost any event, check some conditions, and perform some action in Drupal. Even though Rules is currently available for Drupal 9 and 10, the jump to 8 took some time and the ecosystem lost some of its ubiquity. (119,000 installs on Drupal 7 still and 13,000 on Drupal 8+). I had heard about ECA, but had not used it, listen to our podcast with Jürgen for more info. ECA is more than a drop-in replacement for Rules, and is an extremely powerful ecosystem in its own right.

Screenshot showing some ECA events
Some of the events provided by ECA Commerce

Until this year I had not used ECA since I had gotten used to writing my own event subscribers in custom modules, but earlier this year all that changed! I had a new ecommerce client that needed a rebuild from Drupal 7 to 9 and there were some unique pricing rules. With the ECA episode fresh in my mind I thought I would explore what it would take to write a more generic ECA integration rather than writing my own custom event subscriber module to achieve the pricing rules.

The module is called ECA Commerce! I love when a module name is easy to come up with and explains what it does in the name. After joining one of Jürgen’s Friday meetings where he pointed out the process of exposing Commerce events I was able to quickly build out the ECA → Commerce integration.

Some possible actions

Commerce and ECA both provide rich functionality to Drupal sites. ECA gives events, conditions, and actions that sitebuilders can update to create richer functionality.

Visit day 12 for an in-depth overview of ECA.

  • Events are triggers that initiate the rule such as a user logging in.
  • Conditions are statements that must be true in order for the rule to continue processing such as the user must be an administrator.
  • Actions are the task that is performed such as redirecting the user to a specific page.

Commerce allows companies to set up full featured online stores to provide services or products. There is almost an endless array of customizability especially around products, shipping and promotions.

Screenshot of checkout eventECA Commerce connects the two. All events and conditions that Commerce provides become available for use in the ECA ecosystem.

ECA Commerce provides a ton of events that Commerce provides, for example:

  • Add to cart
  • Remove from cart
  • Complete checkout
  • Update payment
  • Create product

Screenshot of example conditionECA Commerce also supports all of the conditions that Commerce provides (with thanks to czigor for building out this feature!), for example:

  • Customer role
  • Selected payment gateway
  • Products in cart

ECA Commerce only provides one Action at the moment, which is setting the final price in cart. Here is the real power of ECA Commerce though, you can mix and match events, conditions, and actions from the whole ecosystem, so you have access to any other actions that ECA provides.

Here are a couple of quick examples of what ECA commerce can do!

  • Screenshot of example actionSend an email when a user of a particular role adds an item to their cart
  • Redirect users after checking out to custom destinations based on their role
  • Add a role when a user purchases a particular product

If you have a Drupal Commerce site and want to fine tune notifications, or react on any events that commerce provides give it a try! I would appreciate any and all feedback.

Photo of Nic LaflinNic Laflin has been working with Drupal since late 2008 and is founder of nLightened Development. He helps organize New England Drupal Camp (NEDCamp) and co-hosts the Talking Drupal podcast each week. He also enjoys building Lego and customizing his home automation with the open source project Home Assistant.


Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.