session - Opencart 3.0.2.0 中无法触发事件(post.customer.login 和 post.customer.logout)

标签 session opencart opencart-module opencart-3 opencart-events

我想在opencart-3.0.2.0中设置用户登录后的 session

我是 opencart 的新手,我刚刚仅在相应的文件夹中创建了这两个文件。我还需要执行其他操作来触发事件。

我引用此链接来触发 opencart 中的事件:https://isenselabs.com/posts/opencart2-event-system-tutorial

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

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

路径:admin/controller/module/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.");
    }
}

路径:catalog/controller/module/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']);
    }
}

最佳答案

该教程适用于 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');
    }
}

关于session - Opencart 3.0.2.0 中无法触发事件(post.customer.login 和 post.customer.logout),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47406879/

相关文章:

打开购物车 "You do not have permission to access this page, please refer to your system administrator"

php - 在 opencart 的产品页面中显示尺寸

php - 如何从框架外部访问OpenCart功能?

php - PHP 5.3 和 session 文件夹的问题

curl 调用后未保存 PHP session

jsp - session.invalidate() 在 Websphere Application Server 中不起作用

php - opencart 权限被拒绝

php - 如何在Opencart中动态添加JavaScript?

php - 如何在结帐页面中删除送货地址和送货方式-opencart2

python - 如何使用 apache 网络服务器管理与 mod_wsgi 的 session ?