Prestashop 1.6 Create Module to Display Carrier Filter

╄→尐↘猪︶ㄣ 提交于 2019-12-04 19:15:45

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

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 executes before a filter is applied to list.

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'
    );
}

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.

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.

Did you delete /cache/class_index.php ? You have to if you want your override to take effect. If it still does not work, maybe you can process with the hook called in the AdminOrderControllers method with your new module.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!