Prestashop - 覆盖现有 prestashop 模块中的功能

发布于 2024-11-09 14:53:12 字数 234 浏览 0 评论 0原文

我想更改现有的 prestashop 模块,而不复制它并创建新的模块。我知道可以在 prestashop 中覆盖 .tpl 文件,但是是否可以对 php 类做同样的事情?例如,我想更改 blockcart,以便它可以挂在顶部。由于原始版本没有那个钩子,我需要更改 install() 函数!我无法更改原始源(这将是个坏主意,不是吗...)文件我需要通过继承 blockcart 模块来覆盖 install() 函数。是否可以这样做以及在哪里可以找到示例?

I would like to change existing prestashop module without copying it and creating new one. I know that it is possible to override .tpl files in prestashop, but is it possible to do same thing with php classes? For instance I would like to change blockcart so that it can be hooked on top. Since original version doesnt have that hook I need to change install() function! I can`t change original source (it would be bad idea isn't it...) file I need to override install() function by inheriting blockcart module. Is it possible to do so and where I can find example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

围归者 2024-11-16 14:53:12

我使用自己对 FrontController 类的重写,以允许在 tpl 文件中的任意点显示模块输出 - 这意味着该模块不需要支持特定的挂钩。它是通过 smarty 插件实现的,因此您可以使用:

{plugin module='blockcart' hook='rightColumn'}

上面的内容将强制模块输出如果连接到上面插入标签的右列(可以在任何 tpl 文件中的任何位置)将显示的内容。您可以使用此技术从右列“取消挂钩”模块,以便它仅显示在您想要的位置。我已经在生产站点上使用它并取得了巨大成功。

有一系列文章描述了它的工作原理(包含所需的代码):

Prestashop 1.4 插件

I use my own override to the FrontController class to allow the display of module output at arbitrary points in tpl files - this means that the module doesn't need to support a particular hook. It is implemented via a smarty plugin, so you can for example use:

{plugin module='blockcart' hook='rightColumn'}

The above will force the module to output what it would display if hooked to the right column where the above is tag inserted (which can be anywhere in any tpl file). You can "unhook" the module from the right column so that it only displays where you want it to using this technique. I have used it on a production site with great success.

There's a series of articles describing how it works (with the required code) available at:

Prestashop 1.4 Plugins

GRAY°灰色天空 2024-11-16 14:53:12

在 Prestashop 1.4 中您可以覆盖核心类和模块模板
目前,覆盖模块 php 文件是不可能的,但我们正在努力解决这个问题。

In Prestashop 1.4 you can override core classes and module templates
Today this is not possible to override a module php file but we are working on it.

弱骨蛰伏 2024-11-16 14:53:12

在 override\modules\blockcart\blockcart.php 中(如果尚不存在则创建它),

<?php 
    class BlockCartOverride extends BlockCart
    {
        public function hookDisplayTop($params)
        {
            return parent::hookTop($params);
        }
    }
?>

这样您可以覆盖任何模块,使其可在任何默认或自定义挂钩上挂钩。
不要忘记删除cache/class_index.php以使覆盖起作用:)

in override\modules\blockcart\blockcart.php (create it if it does not exist yet)

<?php 
    class BlockCartOverride extends BlockCart
    {
        public function hookDisplayTop($params)
        {
            return parent::hookTop($params);
        }
    }
?>

like this you can override any module to be hookable on any default or custom hook.
don't forget to delete cache/class_index.php for the override to work :)

还不是爱你 2024-11-16 14:53:12

自 PrestaShop 1.6.0.11 版本以来,有一项新功能允许开发人员覆盖模块的实例类。

通过扩展模块的实例类来覆盖它
要覆盖模块的实例类,您必须扩展它,为扩展类提供相同的名称并添加覆盖后缀:

<?php
if (!defined('_PS_VERSION_'))
    exit;
class BlockUserInfoOverride extends BlockUserInfo
{
    public function hookDisplayNav($params)
    {
        return '<div class="header_user_info"><a>Test</a></div>';
        // return $this->display(__FILE__, 'nav.tpl');
    }
}

来源:http://build.prestashop.com/howtos/module/how-to-override-modules/

Since version 1.6.0.11 of PrestaShop, there is a new feature that allows developers to override a module’s instance classes.

Override a module’s instance class by extending it
To override a module’s instance class, you have to extend it, giving the extended class the same name and adding Override suffix:

<?php
if (!defined('_PS_VERSION_'))
    exit;
class BlockUserInfoOverride extends BlockUserInfo
{
    public function hookDisplayNav($params)
    {
        return '<div class="header_user_info"><a>Test</a></div>';
        // return $this->display(__FILE__, 'nav.tpl');
    }
}

Source: http://build.prestashop.com/howtos/module/how-to-override-modules/

街角迷惘 2024-11-16 14:53:12

请记住,在 1.7.x 时代 - 如今 - 您可以覆盖模块主类,但不能覆盖控制器。为了能够覆盖控制器,您必须覆盖核心类(以检测任何可能的覆盖),然后做任何您喜欢的事情。或者,您必须获取原始文件作为备份,并在安装时将修改后的文件放在同一位置,并在卸载时执行相反的过程。

Keep in mind that in 1.7.x era - nowadays - you can override module main classes but not controllers. To be able to override controllers you have to override the core classes (to detect any possible overrides) and then do whatever you like. Alternatively, you have to get the original files as backup and put the modified in the same place on install and the reverse procedure on uninstall.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文