2

我想在用户登录 opencart-3.0.2.0 后设置会话

我是opencart的新手,我刚刚在相应的文件夹中创建了这两个文件。我需要做任何其他事情来触发事件。

我指的是这个链接来触发opencart中的事件:https ://isenselabs.com/posts/opencart2-event-system-tutorial

我在谷歌上搜索了很多仍然没有找到结果。

我用来在 opencart 中触发事件的代码。

路径:管理员/控制器/模块/mymodule.php

代码 :

    public function install() {
        $this->load->model('extension/event');
        $this->model_extension_event->addEvent('mymodule', 'pre.admin.store.delete', 'module/mymodule/on_store_delete');
        $this->model_extension_event->addEvent('mymodule', 'post.customer.login', 'module/mymodule/post_customer_login_customtoken');
        $this->model_extension_event->addEvent('mymodule', 'post.customer.logout', 'module/mymodule/post_customer_logout_function');
    }

    public function uninstall() {
        $this->load->model('extension/event');
        $this->model_extension_event->deleteEvent('mymodule');
    }

    public function on_store_delete($store_id) {
        $this->load->model('setting/store');
        $store_info = $this->model_setting_store->getStore($store_id);
        $admin_mail = $this->config->get('config_email');
        mail($admin_mail, "A store has been deleted", "The store " . $store_info['url'] . " was deleted.");
    }
}

路径:目录/控制器/模块/mymodule.php

代码 :

<?php
class ControllerModuleMyModule extends Controller {
    public function post_customer_login_customtoken() {
        $str = 'abcdefghigklmnopqrstuvwxyz';
        $shuffled = str_shuffle($str);
        $this->session->data['custom_token'] = $shuffled;
    }

    public function post_customer_logout_function(){
        $this->log->write("post_customer_logout_function");
        unset($this->session->data['custom_token']);
    }
}
4

1 回答 1

3

该教程适用于 OpenCart 2.0 - 2.1,在 OpenCart 2.2 及更高版本中事件系统已更改。

对于 OpenCart 3.0.2.0 而不是:

$this->load->model('extension/event');
// and
$this->model_extension_event->addEvent

利用:

$this->load->model('setting/event');
// and
$this->model_setting_event->addEvent

代替:

'post.customer.login'

利用:

'catalog/controller/account/login/after'

代替:

deleteEvent

利用:

deleteEventByCode

所以它必须是:

admin\controller\extension\module\mymodule.php

public function install(){
    $this->load->model('setting/event');
    $this->model_setting_event->addEvent('mymodule', 'catalog/controller/account/login/after', 'extension/module/mymodule/after_customer_login_customtoken');
}
public function uninstall(){
    $this->load->model('setting/event');
    $this->model_setting_event->deleteEventByCode('mymodule');
}


catalog\controller\extension\module\mymodule.php

class ControllerExtensionModuleMyModule extends Controller {
    public function after_customer_login_customtoken(){
        $this->log->write('test');
    }
}
于 2017-11-21T07:16:22.053 回答