From 0dfe0f0980a8be7f5ab62d5572126a0a8802ea21 Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Wed, 23 Jan 2019 13:38:28 +0200 Subject: [PATCH] Sorting by Websites not working in product grid in backoffice #20511 --- .../Ui/Component/Listing/Columns/Websites.php | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Websites.php b/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Websites.php index 5af0d71dc246c..f67585c6401f8 100644 --- a/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Websites.php +++ b/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Websites.php @@ -1,4 +1,4 @@ -storeManager = $storeManager; + $this->_resourceHelper = $resourceHelper; } /** @@ -83,4 +97,46 @@ public function prepare() $this->_data['config']['componentDisabled'] = true; } } + + /** + * Apply sorting + * + * @return void + */ + protected function applySorting() + { + $sorting = $this->getContext()->getRequestParam('sorting'); + $isSortable = $this->getData('config/sortable'); + if ($isSortable !== false + && !empty($sorting['field']) + && !empty($sorting['direction']) + && $sorting['field'] === $this->getName() + ) { + $collection = $this->getContext()->getDataProvider()->getCollection(); + $collection + ->joinField( + 'websites_ids', + 'catalog_product_website', + 'website_id', + 'product_id=entity_id', + null, + 'left' + ) + ->joinTable( + 'store_website', + 'website_id = websites_ids', + ['name'], + null, + 'left' + ) + ->groupByAttribute('entity_id'); + $this->_resourceHelper->addGroupConcatColumn( + $collection->getSelect(), + self::WEBSITE_NAMES, + 'name' + ); + + $collection->getSelect()->order(self::WEBSITE_NAMES . ' ' . $sorting['direction']); + } + } }