Here is my event install code:
Code: Select all
$data = [
'code' => 'better_invoice',
'description' => 'Better Invoice Event',
'trigger' => 'admin/view/sale/order_invoice/before',
'action' => 'extension/better_invoice/controller/invoice_event.onInvoiceGenerate',
'sort_order' => 1,
'status' => 1
];
$this->model_setting_event->addEvent($data);
the code:
Code: Select all
namespace Opencart\Admin\Controller\Extension\BetterInvoice;
class InvoiceEvent extends \Opencart\System\Engine\Controller {
public function onInvoiceGenerate(string &$route, array &$data, mixed &$output) {
$this->load->model('tool/log');
$this->model_tool_log->write('onInvoiceGenerate event triggered');
//die('test');
// Fetch the order ID from the $args
$order_id = $data[0];
// Load your custom invoice model here
//$this->load->model('extension/better_invoice/invoice');
//$output = $this->model_extension_better_invoice_invoice->generateCustomInvoice($order_id);
$this->response->setOutput('Custom Invoice Output');
}
}
Could someone also give me a brief rundown on the different events for this? for example I know there is a before/after and right now im doing the event on admin/view/ but think i can also do it on controller, can I replace the invoice twig itself only? how can I add more variables to the controller but retain all other functionality?
Any help will be much appreciated because this has been a whole day battle, and getting nowhere at the moment!