Adding Events

eCommerce allows you to hook into several related events. These are stubbed out for developers who wish to extend the package's functionality.

Looking in packages/core_commerce/models/events, we see three files:

  • add_to_cart.php
  • change_order_status.php
  • product.php

Each provides us an opportunity to fire other code when these events happen.

This discussion details some modifications that community members have used to add them.

For instance, to send a simple mail message when a customer completes all the steps in the eCommerce checkout, we'll want to override change_order_status.php and add some code that runs when the order status is "authorized":

case CoreCommerceOrder::STATUS_AUTHORIZED:
     $email = $order->getOrderEmail();
     $mh = Loader::helper('mail');
     $mh->to($email, "Customer");
     $mh->setSubject("Who let the dogs out?");
     $mh->setBody("Woof. Your order number is " . $order->getOrderID() . ".");
     try {
     } catch (Exception $e) {
          Log::addEntry('Error sending receipt email for order #' . $order->getOrderID() . ': ' . $e->getMessage());

This will load a mail template named order_placed.php from your mail overrides directory and send it. Exceptions (errors) will be logged.

More documentation on sending mail is available in our Developer's Guide.