Events
Introduction to Simpler Checkout Events
The Simpler Checkout module provides specific events that developers can use to extend its functionality. These events allow you to hook into key points of the checkout process, enabling you to perform custom actions such as processing data, integrating with third-party systems, or updating your store’s behavior dynamically.
By leveraging these events, you can ensure seamless integration and maintainability while adding custom features to your OpenCart store.
Event: Get Invoice Data After Order Submission
Description
This event allows developers to capture the invoice data after an order has been successfully submitted. The data can then be processed, stored, or sent to external systems as needed.
Use Case Example
For instance, after an order is completed, you may want to retrieve the invoice details and store them in a custom database table or send them to an external accounting system.
Implementation
Listening to the Event
To listen for the order submission event and capture the data, you can register a listener during your module’s installation process. Below is an example:
// File: admin/controller/extension/module/mytestmodule.php
class ControllerExtensionModuleMyTestModule extends Controller {
public function install() {
$this->load->model('setting/event');
$this->model_setting_event->addEvent(
'mytestmodule_invoice_listener',
'catalog/controller/extension/module/simpler/v1/submit/after',
'extension/module/mytestmodule/captureInvoice'
);
}
}
- Event Name:
mytestmodule_invoice_listener
- Trigger Point:
catalog/controller/extension/module/simpler/v1/submit/after
- Callback:
extension/module/mytestmodule/captureInvoice
Handling the Event
The captureInvoice
method is executed when the event is triggered. Here is an example implementation:
// File: catalog/controller/extension/module/mytestmodule.php
class ControllerExtensionModuleMyTestModule extends Controller {
public function captureInvoice($route, $args, $output) {
// Ensure the necessary data exists
if (isset($output['order_request']) && isset($output['order_request']['invoice'])) {
// Access the invoice data
$invoiceData = $output['order_request']['invoice'];
// Perform your custom logic with the invoice data
// Example: Save to a custom table, log, or send to an API
}
}
}