0

Sales order view page, we have added some custom columns, but filters are not working. Please, check below screen-shot.

enter image description here

    <?php

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Custom\Sales\Model\ResourceModel\Order\Grid;

use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as OriginalCollection;

/**

 * Order grid extended collection
 */
class Collection extends OriginalCollection {

    protected function _initSelect() {

        parent::_initSelect();

        $this->getSelect()->joinLeft(
                ['sales_order_item' => $this->getTable('sales_order_item')], //2nd table name by which you want to join mail table
                'main_table.entity_id = sales_order_item.order_id',
                ['CONCAT(sales_order_item.name,"(",sales_order_item.sku,")") as pname']
        );
        $this->getSelect()->joinLeft(
                ['sales_order' => $this->getTable('sales_order')],
                'main_table.entity_id = sales_order.entity_id', ['user_id']
        )->group('main_table.entity_id');
    }

}

List of column

sku,user_id,status,warehouse_id,customer_id,increment_id,base_grand_total,grand_total,store_id

What could be reason behind it?

Thanks in advance

  • Could you please post your collection? – Pramod Kharade Jan 20 '18 at 16:29
  • Okay. I will post collection. but collection already overrided into custom module. – user60445 Jan 20 '18 at 16:31
  • Could you please, add all custom column names ? – Pramod Kharade Jan 20 '18 at 16:36
1

Issue is due to ambiguity of column so we need to apply filter with alias name

    <?php

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Custom\Sales\Model\ResourceModel\Order\Grid;

use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as OriginalCollection;

/**

 * Order grid extended collection
 */
class Collection extends OriginalCollection {

    protected function _initSelect() {
        $this->addFilterToMap('pname', 'sales_order_item.sku');
        $this->addFilterToMap('user_id', 'sales_order.user_id');
        $this->addFilterToMap('status', 'main_table.status');
        $this->addFilterToMap('warehouse_id', 'main_table.warehouse_id');
        $this->addFilterToMap('customer_id', 'main_table.customer_id');
        $this->addFilterToMap('increment_id', 'main_table.increment_id');
        $this->addFilterToMap('base_grand_total', 'main_table.base_grand_total');
        $this->addFilterToMap('grand_total', 'main_table.grand_total');
        $this->addFilterToMap('store_id', 'main_table.store_id');
        parent::_initSelect();

        $this->getSelect()->joinLeft(
                ['sales_order_item' => $this->getTable('sales_order_item')], //2nd table name by which you want to join mail table
                'main_table.entity_id = sales_order_item.order_id',
                ['CONCAT(sales_order_item.name,"(",sales_order_item.sku,")") as pname']
        );
        $this->getSelect()->joinLeft(
                ['sales_order' => $this->getTable('sales_order')],
                'main_table.entity_id = sales_order.entity_id', ['user_id']
        )->group('main_table.entity_id');
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy