John Magnolia
John Magnolia

Reputation: 16793

Opencart event data missing identifier

Using opencart 3 and trying to make use of the events but I'm unable to find the identifier.

E.g trying to extend the returns form added an event:

$this->model_setting_event->addEvent('mail_account_return_after', 'catalog/model/account/return/addReturn/after', 'extension/module/return/returnAdd');

Controller:

class ControllerExtensionModuleReturn extends Controller {

    public function returnAdd(&$route, &$args, &$output) {
        print_r($args);
        exit;

$args is missing the main return_id identifier:

Array
(
    [0] => Array
        (
            [firstname] => Foo
            [lastname] => Bar
            [email] => [email protected]
            [telephone] => 01234556789
            [order_id] => 29
            [date_ordered] => 2017-06-29
            [product] => Canon EOS 5D
            [model] => Product 3
            [quantity] => 1
            [return_reason_id] => 4
            [opened] => 0
            [comment] => Test comment
        )

)

Tried with $this->db->getLastId() but this returns 0. Tested with other events and appears to be missing the main identifiers.

Where does opencart set what data is passed to the before/after events?

Upvotes: 2

Views: 134

Answers (2)

You Old Fool
You Old Fool

Reputation: 22941

If I'm not mistaken you should be able to access the auto increment return_id in $output, which holds the output of method addReturn(), i.e., $this->db->getLastId();.

As to why calling getLastId() a second time from within your event doesn't work, that's a good question. I would assume there may be some other query happening in between - though by default I don't think there should be. Is it possible there is another trigger running a query before your event gets triggered?

Upvotes: 1

Scott C Wilson
Scott C Wilson

Reputation: 20026

Look in system/engine/loader.php at for the strings before and after. There are methods that do view, controller, configuration and language.

Upvotes: 1

Related Questions