Post by gabba0000 » Thu Jun 03, 2021 4:22 pm

Opencart Version 3.0.3.2

Hi I have been working with Opencart events for inserting into a custom table when an order has been placed. I am new to Opencart and cannot figure out why it is not working. It is inserting into oc_event and appearing on the Opencart events page but nothing is happening when the order has been placed. For the purpose of learning, i have named it "eventtest"

In admin/controller/extension/module:

Code: Select all


 public function install()
        {
                $this->load->model('extension/module/eventtest');
                $this->load->model('setting/setting');
                $this->model_extension_module_eventtest->install();
                $this->load->model("setting/event");
                $this->model_setting_event->addEvent('eventTest', 'catalog/model/checkout/order/addOrder/after', 'extension/module/eventtest_add_new_order/orderHistoryAdded');
        }

In catalog/controller/extension/module:

Code: Select all


class ControllerExtensionModuleEventTestAddNewOrder extends Controller {

    public function orderHistoryAdded(&$eventRoute, &$data) {

            $this->load->model('extension/module/eventtest_add_new_order');
            $this->model_extension_module_eventtest_add_new_order->update();

        }

}

In catalog/model/extension/module:

Code: Select all

class ModelExtensionModuleEventTestAddNewOrder extends Model {

    public function update()
    {
          $this->db->query("INSERT INTO `" . DB_PREFIX . "event_test` (name) VALUES ('test')");
    }

}

Newbie

Posts

Joined
Mon Nov 30, 2020 1:03 am

Post by straightlight » Thu Jun 03, 2021 6:14 pm

You're using a /after event but your catalog/controller/extension/module controller file uses /before triggers in the parameters. In this case, you need to add:

Code: Select all

, &$output
as the last parameter as per: https://github.com/opencart/opencart/wiki/Events-System - this section:
Which is the best way to test the outputs with an after event?
explains it. Then, to test your outputs in your method. You could also use the debug events to test your triggers.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by gabba0000 » Wed Jun 09, 2021 11:07 pm

Thanks that fixed my problem!

Newbie

Posts

Joined
Mon Nov 30, 2020 1:03 am

Post by straightlight » Wed Jun 09, 2021 11:26 pm

gabba0000 wrote:
Wed Jun 09, 2021 11:07 pm
Thanks that fixed my problem!
Now that the issue has been solved, please add: [SOLVED] at the beginning of the subject line on your first post.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 133 guests