2

I'm using opencart version 2.1.0.1 and trying to use the new script notification system. Please note that I have simply installed the original version. Nothing extra added or modified.

Following the tutorial found here: http://isenselabs.com/posts/opencart2-event-system-tutorial I managed to create a new module and install it successfully. I can confirm from the database that it has registered the events that I want to trigger.

To give you a better picture I have created these files:

  • admin/controller/module/testo.php
  • admin/view/template/module.testo.tpl
  • admin/language/english/module/testo.php
  • catalog/controller/module/testo.php

Now although the admin events are triggered with no problem the Catalog (fronted) Order Events never fire.

On admin/controller/module/testo.php function install I have the following call:

$this->model_extension_event->addEvent('testo', 'post.order.add', 'module/testo/on_order_add');

And according to the tutorial the function to fire should be in catalog/controller/model/testo.php

public function on_order_add($order_id) { .... }

The function simply writes the order_id to a text file, nothing tricky there.

So when I complete an order the function never runs. I have tried most Order Notification Hooks with no luck.

Am I missing something? Is there something I'm not understanding? Please help since there is absolutely no documentation and I'm on a dead end (for the time)

DigitCart
  • 2,980
  • 2
  • 18
  • 28
ion
  • 1,033
  • 2
  • 16
  • 46

2 Answers2

1

You are calling it incorrectly, your catalog file path must be

catalog/controller/module/testo.php

not

catalog/controller/model/testo.php

because your trigger is

$this->model_extension_event->addEvent('testo', 'post.order.add', 'module/testo/on_order_add');

it's meaning -> Opencart will search catalog/controller/module/testo.php file and will call it's on_order_add() function when 'post.order.add' trigger will execute (because trigger in catalog side it will use catalog/* or else it will use admin/*), 'testo' is just name part noting important.

In your case it's searching correctly but you don't have any file on this path because you added file to

catalog/controller/model/testo.php

so change your folder structure -> model to module or change your trigger from module to model.

Nikhil Chaudhary
  • 478
  • 4
  • 16
  • You are right but I just noted that model was a typo .. I have the file inside /module folder. So the problem is something else! I will edit the post. thanks – ion Nov 24 '15 at 09:00
0

Are you sure writing to text file is working?

because i also tried to get post.order.add event on my Opencart 2.0.3.1, and its working fine.

try writing to log file

<?php

class ControllerModuleTesto extends Controller
{
    public function on_order_add($order_id)  
    {
        $this->log->write("Order Id " . $order_id . " was created."); 
    }
}
?>

and check logs at backend->Tools->Error Logs

Sahil Doshi
  • 1,073
  • 10
  • 23