I'm a newbie, new to magento 2. Please guide me here: I want to search fulltext product sku and product id in grid order. I have now added the product sku and product id to the grid, the filter is also running, but I don't know how to search the fulltext for these two fields (specifically, search on the "Search by keyword" box). Anyone have any direction, please guide me.
<?php /** * Copyright © MageWorx. All rights reserved. * See LICENSE.txt for license details. */ namespace KhoiNguyenh\Order\Plugin; use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as OrderGridCollection; /** * Class AddDataToOrdersGrid */ class KhoiNguyenhAddDataToOrderGrid { /** * @var \Psr\Log\LoggerInterface */ private $logger; /** * AddDataToOrdersGrid constructor. * * @param \Psr\Log\LoggerInterface $customLogger * @param array $data */ public function __construct( \Psr\Log\LoggerInterface $customLogger, array $data = [] ) { $this->logger = $customLogger; } /** * @param \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $subject * @param OrderGridCollection $collection * @param $requestName * @return mixed */ public function afterGetReport($subject, $collection, $requestName) { if ($requestName !== 'sales_order_grid_data_source') { return $collection; } if ($collection->getMainTable() === $collection->getResource()->getTable('sales_order_grid')) { try { // Add product's name column $this->addProductsDataColumn($collection); } catch (\Zend_Db_Select_Exception $selectException) { // Do nothing in that case $this->logger->log(100, $selectException); } } return $collection; } /** * Adds products number column to the orders grid collection * * @param OrderGridCollection $collection * @return OrderGridCollection */ private function addProductsDataColumn(OrderGridCollection $collection): OrderGridCollection { // Get original table name $orderItemsTableName = $collection->getResource()->getTable('sales_order_item'); // Create new select instance $itemsTableSelectGrouped = $collection->getConnection()->select(); // Add table with columns which must be selected (skip useless columns) $itemsTableSelectGrouped->from( $orderItemsTableName, [ 'product_id' => new \Zend_Db_Expr('GROUP_CONCAT(DISTINCT product_id SEPARATOR \',\')'), 'product_sku' => new \Zend_Db_Expr('GROUP_CONCAT(DISTINCT sku SEPARATOR \',\')'), 'order_id' => 'order_id' ] ); // Group our select to make one column for one order $itemsTableSelectGrouped->group('order_id'); // Add our sub-select to main collection with only one column: name $collection->getSelect() ->joinLeft( ['soi' => $itemsTableSelectGrouped], 'soi.order_id = main_table.entity_id', ['product_id', 'product_sku'] ); return $collection; } } 