php 在管理订单列表中添加运营商列prestashop 1.7.7.5

emeijp43  于 2022-12-17  发布在  PHP
关注(0)|答案(2)|浏览(156)

我在prestashop www.example.com下1.7.7.5,我想在BO订单列表中添加一列以显示运营商名称,我已成功添加带有hookActionOrderGridDefinitionModifier的列,但在ArdminOrdersController中添加运营商名称字段时遇到问题。
我测试了一个覆盖,但是没有成功,什么都没有改变,如果我直接修改/controllers/admin中的AdminOrdersController.php,我也尝试使用hookActionAdminOrdersListingFieldsModifier,但没有成功。
覆盖是此任务中的文件:Add carrier column to orders table in Prestashop back-office
我已尝试清除“性能”选项卡中的缓存,并清除var/cache中的dev和prod文件夹
字段修饰符的钩子:

public function hookActionAdminOrdersListingFieldsModifier($params)
{
    if (isset($params['select'])) {
        $params['select'] .= 'carr.name as `carriername`';
    }

    if (isset($params['join'])) {
        $params['join'] .= 'LEFT JOIN `'._DB_PREFIX_.'order_carrier` oc ON (a.`id_order` = oc.`id_order`)
                            LEFT JOIN `'._DB_PREFIX_.'carrier` carr ON (oc.`id_carrier` = carr.`id_carrier`)';
    }

    $params['fields']['carriername'] = [
        'title' => $this->trans('Carrier', array(), 'Admin.Global'),
        'type' => 'text',
        'align' => 'text-center',
        'class' => 'fixed-width-xl',
        'filter_key' => 'carrier!name',
        'filter_type' => 'text',
        'order_key' => 'carrier!name',
    ];
}

我添加载波列的钩子:

public function hookActionOrderGridDefinitionModifier(array $params)
{

    /** @var GridDefinitionInterface $definition */
    $definition = $params['definition'];

    /** @var FilterCollection $filters */
    $filters = $definition->getFilters();

    /** @var ColumnCollection */
    $columns = $definition->getColumns();

    $columns
        ->addAfter('country_name',
            (new DataColumn('carrier'))
                ->setName($this->trans('Carrier', array(), 'Admin.Global'))
                ->setOptions([
                    'field' => 'carriername',
                ])
        );

}
fhity93d

fhity93d1#

我直接更改了Prestashop 1.7.8.1源代码,因为钩子不工作,所以这是一个变通方案。
src/Core/Grid/Definition/Factory/OrderGridDefinitionFactory.php

protected function getColumns()
{
     $columns = (new ColumnCollection())
        .....
        ->add((new DataColumn('carrier'))
        ->setName($this->trans('Carrier', [], 'Admin.Global'))
        ->setOptions([
            'field' => 'carrier_name',
        ])

src/Core/Grid/Query/OrderQueryBuilder.php

private function getBaseQueryBuilder(array $filters)
{
    $qb = $this->connection
        ->createQueryBuilder()
        ->from($this->dbPrefix . 'orders', 'o')
        ->leftJoin('o', $this->dbPrefix . 'customer', 'cu', 'o.id_customer = cu.id_customer')
        ->leftJoin('o', $this->dbPrefix . 'carrier', 'ca', 'o.id_carrier = ca.id_carrier')

public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria)
{
    $qb = $this
        ->getBaseQueryBuilder($searchCriteria->getFilters())
        ->addSelect($this->getCustomerField() . ' AS `customer`')
        ->addSelect('o.id_order, o.id_carrier, o.reference, o.total_paid_tax_incl, os.paid, osl.name AS osname')
        ->addSelect('o.id_currency, cur.iso_code')
        ->addSelect('o.current_state, o.id_customer')
        ->addSelect('cu.`id_customer` IS NULL as `deleted_customer`')
        ->addSelect('os.color, o.payment, s.name AS shop_name')
        ->addSelect('o.date_add, cu.company, cl.name AS country_name, o.invoice_number, o.delivery_number')
        ->addSelect('o.id_carrier, ca.name as carrier_name')

然后,转到您的管理员订单页面see

似乎需要稍后为载波添加滤波器功能。

好吧,希望以上能给你带来灵感,圣诞快乐。

ycl3bljg

ycl3bljg2#

差不多了.... -也许你应该改一下这部分:

...
'filter_key' => 'carrier!name',
'filter_type' => 'text',
'order_key' => 'carrier!name',
...

通过以下方式:

'filter_key' => 'carr!name',
'filter_type' => 'text',
'order_key' => 'carr!name',

在我的情况下(PrestaShop v. 1.7.6.9),我应用了额外的代码直接/脏在/controllers/admin/AdminOrdersController.php从行号102开始,如下所示:

$this->_select .= '
   ,
   carr.name as `carriername`
';

$this->_join .= '
   LEFT JOIN `'._DB_PREFIX_.'order_carrier` oc ON (a.`id_order` = oc.`id_order`)
   LEFT JOIN `'._DB_PREFIX_.'carrier` carr ON (oc.`id_carrier` = carr.`id_carrier`)
';

$this->fields_list = array_merge($this->fields_list, array(
    'carriername' => array(
        'title' => $this->trans('Carrier', array(), 'Admin.Global'),
        'filter_key' => 'carr!name',
        'type' => 'text',
        'align' => 'text-center',
        'class' => 'fixed-width-xl',
        'filter_key' => 'carr!name',
        'filter_type' => 'text',
        'order_key' => 'carr!name',
    ),
));

因此,我们在订单列表/ Presta管理订单列表中有承运人列:

相关问题