Prestashop 1.6 创建模块以显示载波过滤器 [英] Prestashop 1.6 Create Module to Display Carrier Filter

查看:65
本文介绍了Prestashop 1.6 创建模块以显示载波过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的基于 Prestashop 的站点当前正在覆盖 AdminOrdersController.php,我已将它放在覆盖文件夹中.

My Prestashop-based site is currently having an override for AdminOrdersController.php, I have placed it in override folder.

从下面提供的链接中,添加一个现在在 Prestashop 1.6 中不可用的 Carrier 过滤器非常好.我已经尝试过该解决方案,它运行良好.

From the link provided below, it is perfectly working fine to add a Carrier filter which is not available in Prestashop 1.6 now. I have tried the solution and it is working perfectly.

参考:在订单页面添加运营商过滤器.

不幸的是,对于生产站点,我无法访问核心文件,因此无法实现.因此,我需要创建一个自定义模块.请注意,我已经对 AdminOrdersController.php 进行了覆盖.我想点击此覆盖并插入过滤器.

Unfortunately, for production site, I have no access to core files and unable to implement as such. Thus, I will need to create a custom module. Do take note that I already have an override in place for AdminOrdersController.php. I would like to tap on this override and insert the filter.

我设法创建了一个模块并尝试在 mymodule/override/controller/admin/AdminOrdersController.php 中使用运营商过滤器功能放置覆盖(使用 URL 中提供的代码).

I have managed to create a module and tried placing an override (with the code provided in the URL) in mymodule/override/controller/admin/AdminOrdersController.php with the carrier filter feature.

没有任何变化/效果,我很困惑.我需要生成或复制任何 .tpl 文件吗?

There has been no changes/effect, I am baffled. Do I need to generate or copy any .tpl file?

非常感谢任何指导.

谢谢.

推荐答案

虽然链接问题中的答案工作正常,但单独使用模块也可以实现同样的事情(不需要覆盖).

While the answer in the linked question works fine the same thing can be achieved with a module alone (no overrides needed).

管理控制器有一个用于列表字段修改的钩子.有两个名称相同,但它们的 params 数组中有不同的数据.

Admin controllers have a hook for list fields modifications. There are two with the same name however they have different data in their params array.

actionControllernameListingFieldsModifier在过滤器应用于列表之前执行.

actionControllernameListingFieldsModifier executes before a filter is applied to list.

actionControllernameListingFieldsModifier在从数据库中提取数据并呈现列表之前执行.

actionControllernameListingFieldsModifier executes before data is pulled from DB and list is rendered.

因此您可以在模块文件中将字段添加到现有的控制器列表定义中:

So you can add fields to existing controller list definition like this in your module file:

public function hookActionAdminOrdersListingFieldsModifier($params) {
    if (isset($params['select'])) {
        $params['select'] .= ', cr.name';
        $params['join'] .= ' LEFT JOIN `'._DB_PREFIX_.'carrier` cr ON (cr.`id_carrier` = a.`id_carrier`)';
    }
    $params['fields']['carrier'] = array(
        'title' => $this->l('Carrier'),
        'align' => 'text-center',
        'filter_key' => 'cr!name'
    );
}

因为数组数据是通过引用传递到 $params 数组中的,所以您可以在钩子中修改它们,并将更改保留回控制器.这将在列表末尾附加运营商列.

Because array data is being passed into $params array by reference you can modify them in your hook and changes persist back to controller. This will append carrier column at the end of list.

尝试通过模块钩子解决问题是 prestashop 的最佳实践,并且只有当真的没有办法用钩子来解决问题时,才用覆盖来解决.

It is prestashop best practice to try and solve problems through module hooks and only if there is really no way to do it with hooks, then do it with overrides.

这篇关于Prestashop 1.6 创建模块以显示载波过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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