覆盖 Prestashop 模块更改不可见 [英] Override Prestashop Module Changes not Visible

查看:80
本文介绍了覆盖 Prestashop 模块更改不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试覆盖 Prestashop 中的模块,但更改并未出现.

I am attempting to override a module in Prestashop but the changes are just not appearing.

我已经覆盖了一个模板文件和一个控制器,所以我添加了以下文件:

I have overridden a template file and a controller so I have added the following files:

\override\modules\blockwishlist\views\templates\front\mywishlist.tpl
\override\modules\blockwishlist\controllers\front\mywishlist.php

\override\modules\blockwishlist\views\templates\front\mywishlist.tpl
\override\modules\blockwishlist\controllers\front\mywishlist.php

这些是非常简单的更改,我将另一列添加到包含按钮的表格中.单击按钮时,控制器会生成一个 CSV 文件.

These are very simple changes where I add another column to a table that contains a button. When the button is clicked the controller generates a CSV file.

知道为什么没有显示这些更改吗?

Any idea why these changes are just not being shown?

注意:我已经打开了强制编译"并关闭了缓存.

Note: I have turned on 'Force Compile' and turned of caching.

编辑:是否重新覆盖控制器:

Edit: Re overridding a controller is it:

class BlockWishListMyWishListModuleFrontController extends BlockWishListMyWishListModuleFrontControllerCore // extends ModuleFrontController

class BlockWishListMyWishListModuleFrontControllerOverride extends BlockWishListMyWishListModuleFrontController

推荐答案

好的,我做了一些代码研究(也许存在最简单的方法,不确定),所以:

okay, I did some code research (maybe thre is exists easiest way, not sure), so:

在代码 Dispatcher 类中我们有

in code Dispatcher class we have

// Dispatch module controller for front office
            case self::FC_MODULE :
                $module_name = Validate::isModuleName(Tools::getValue('module')) ? Tools::getValue('module') : '';
                $module = Module::getInstanceByName($module_name);
                $controller_class = 'PageNotFoundController';
                if (Validate::isLoadedObject($module) && $module->active) {
                    $controllers = Dispatcher::getControllers(_PS_MODULE_DIR_.$module_name.'/controllers/front/');
                    if (isset($controllers[strtolower($this->controller)])) {
                        include_once(_PS_MODULE_DIR_.$module_name.'/controllers/front/'.$this->controller.'.php');
                        $controller_class = $module_name.$this->controller.'ModuleFrontController';
                    }
                }
                $params_hook_action_dispatcher = array('controller_type' => self::FC_FRONT, 'controller_class' => $controller_class, 'is_module' => 1);
            break;

我们看到控制器在没有覆盖的情况下加载,但从代码的下面的另一边我们看到钩子执行:

where we see that controllers loaded without overrides, but from other side below in code we see hook execution:

// Loading controller
            $controller = Controller::getController($controller_class);

            // Execute hook dispatcher
            if (isset($params_hook_action_dispatcher)) {
                Hook::exec('actionDispatcher', $params_hook_action_dispatcher);
            }

所以可能的解决方案之一(不覆盖核心类):

so one of possible solution (without overriding core class) :

  1. 如何覆盖模块并希望你有核心版本 >= 1.6.0.11

  1. how to override module and hope you have core version >= 1.6.0.11

blockwishlist.php中的install()方法中添加

this->registerHook('actionDispatcher')

用其他钩子来调节,所以它看起来像 ... !this->registerHook('actionDispatcher') ||... 因为这个钩子默认没有注册,我们不能把模块放在那里.

to condition with other hooks, so it will looks like ... !this->registerHook('actionDispatcher') || ... because this hook not registered by default and we can't just place module there.

  1. create 方法(这里不能美化代码)

  1. create method (can't beautify code here)

公共函数 hookActionDispatcher($params){if ('blockwishlistmywishlistModuleFrontController' == $params['controller_class']) {include_once(_PS_OVERRIDE_DIR_ . 'modules/' . $this->name . '/controllers/front/mywishlist.php');$controller = Controller::getController('BlockWishListMyWishListModuleFrontControllerOverride');}}

你已经有override/modules/blockwishlist/controllers/front/mywishlist.php文件了这个路径

you already have override/modules/blockwishlist/controllers/front/mywishlist.php file by this path

重新安装模块.

有效!

更多关于覆盖文档

这篇关于覆盖 Prestashop 模块更改不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆