1

As you know, in Opencart we can run an action before or after an trigger, my question is what way to passing data and arguments from trigger to action, in another say i want to use Trigger's arguments and variables into action method.

my question is about opencart 2.3.0.2

Hamid Abbasi
  • 346
  • 2
  • 14

3 Answers3

0

It's a great question, but there doesn't seem to be a decent way of doing this. I asked a similar question and the only suggestion I got was stashing the data in a file (which isn't a great idea for a web app). I think your only option here is going to be to stick the data in the user's session.

Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83
  • 1
    Thanks for your comment @scott, realy use of session and file is an uncompleted solution and this fact that opencart didn't consider any solution for this, is an big problem, because when we want use event, we want work on the fly without use OCmod or VQmod, so use of session or file meaning we go back to ocmod and this make useless opencart's events... – Hamid Abbasi Aug 06 '17 at 05:58
0

option A: session data

in event caller file add:

$this->session->data['myDataHere'] = array('key1' => 'some_data');

in event target file add:

$myDataHere = isset($this->session->data['myDataHere']) ? $this->session->data['myDataHere'] : false;


option B: opencart's event system

you could try using the event parameters

example for passing newsletter preference for registered customer to a custom controller

SQL:

INSERT INTO
    `oc_event`
SET
    `code`       = 'any_event_name_here',
    `trigger`    = 'catalog/model/account/customer/editNewsletter/after',
    `action`     = 'dir/file/myFunction',
    `status`     = 1,
    `sort_order` = 0

controller file (public_html/catalog/controller/dir/file.php)

<?php
class ControllerDirFile extends Controller {
    public function myFunction($route = '', $args = '') {
        if( $args != '' ) {
            echo '<pre>';
            print_r($args);
        }
    }
}

Opencart Events System

Creating Opencart events from controller or model file

George-Paul B.
  • 544
  • 4
  • 7
-1

May be use of query strings such $_GET variables are a solutions, it's possible we use of $_GET variable before end page rendering, it's mean your query strings are still available after trigger method, for example you can load Order details after end trigger by pass $_GET['order_number'] to model and then you can load any other information by returned data.

This can work, but all events don't have query_strings in their requests...

Hamid Abbasi
  • 346
  • 2
  • 14