Notifly in OpenCart
OpenCart is an online store where every event means money. An order, a
registration, a product running out — all of this is worth getting as a push
instantly, instead of checking email once an hour. We connect through the
OpenCart event system (the event table) and a small OCMOD modifier.
We reuse the shared notifly_send() helper — the same one as for the other
CMSes. Put it in the file system/library/notifly.php and include
it from config.php so it is available everywhere.
New order
Section titled “New order”The most important event. We catch the moment an order is first assigned a status
(addOrderHistory) through the event
catalog/model/checkout/order/addHistory/after.
Register the handler in the event table (via the admin Extensions → Events
or SQL) for the path catalog/model/checkout/order/addHistory/after, pointing to
your file:
<?phpclass ModelExtensionNotiflyOrder extends Model { public function alert(&$route, &$args, &$output) { [$order_id, $status_id] = $args;
// React only to the first transition to "placed" (1 by default). if ((int)$status_id !== 1) { return; }
$this->load->model('checkout/order'); $order = $this->model_checkout_order->getOrder($order_id); if (!$order) { return; }
$products = $this->model_checkout_order->getOrderProducts($order_id); $lines = []; foreach ($products as $p) { $lines[] = "• {$p['name']} × {$p['quantity']}"; }
notifly_send( "🛒 Заказ #{$order_id} — {$order['total']} {$order['currency_code']}", "Покупатель: {$order['firstname']} {$order['lastname']}\n" . "Телефон: {$order['telephone']}\n" . "Оплата: {$order['payment_method']}\n\n" . "Состав:\n" . implode("\n", $lines) . "\n\n" . "Админка: index.php?route=sale/order.info&order_id={$order_id}", 9 // orders — a loud priority ); }}Low-stock warning
Section titled “Low-stock warning”After an order is placed, product stock decreases. Let’s check the order’s products and warn if something dropped below the threshold. We extend the same handler:
$this->load->model('catalog/product');foreach ($products as $p) { $product = $this->model_catalog_product->getProduct($p['product_id']); if (!$product) { continue; } if ((int)$product['quantity'] <= 3) { notifly_send( "📦 Мало на складе: {$product['name']}", "Осталось: {$product['quantity']} шт.\n" . "SKU: {$product['sku']}\n" . "Пополнить: index.php?route=catalog/product.form&product_id={$p['product_id']}", 6 ); }}New customer registration
Section titled “New customer registration”The event catalog/model/account/customer/addCustomer/after fires after an
account is created:
<?phpclass ModelExtensionNotiflyCustomer extends Model { public function alert(&$route, &$args, &$output) { $data = $args[0]; notifly_send( "👤 Новый покупатель: {$data['firstname']} {$data['lastname']}", "Email: {$data['email']}\n" . "Телефон: " . ($data['telephone'] ?? '—'), 4 ); }}Registering events via OCMOD
Section titled “Registering events via OCMOD”To avoid writing handlers by hand, package them as an OCMOD modifier that adds
rows to the event table on install:
<?xml version="1.0" encoding="utf-8"?><modification> <name>Notifly Alerts</name> <version>1.0</version> <author>Notifly</author> <!-- The events themselves are registered by the module's install script --> <file path="system/startup.php"> <operation> <search><![CDATA[// Registry]]></search> <add position="before"><![CDATA[require_once(DIR_SYSTEM . 'library/notifly.php');]]></add> </operation> </file></modification>And add the events themselves in the module’s install script
(admin/controller/extension/module/notifly.php, the install() method):
$this->load->model('setting/event');$this->model_setting_event->addEvent([ 'code' => 'notifly_order', 'trigger'=> 'catalog/model/checkout/order/addHistory/after', 'action' => 'extension/notifly/order.alert', 'status' => 1, 'sort_order' => 0,]);$this->model_setting_event->addEvent([ 'code' => 'notifly_customer', 'trigger'=> 'catalog/model/account/customer/addCustomer/after', 'action' => 'extension/notifly/customer.alert', 'status' => 1, 'sort_order' => 0,]);Throttling
Section titled “Throttling”During imports or bulk status updates, don’t flood the channel. Use OpenCart’s built-in cache:
$key = 'notifly_' . md5($title);if ($this->cache->get($key)) { return;}$this->cache->set($key, 1);Benefits
Section titled “Benefits”- An order is visible within seconds. You can confirm the order while the customer is still online.
- Stock under control. A low-stock push — never miss an “out of stock”.
- No need for a paid notification module from the OpenCart marketplace.
What to improve next
Section titled “What to improve next”- Separate Notifly channels: “orders”, “stock”, “customers”.
- Order priority by amount: large totals — priority 10.
- A deep link to the order via extras.