From 2f9892f57f0994242b701b751cd9382732130f86 Mon Sep 17 00:00:00 2001 From: Richard BAYET Date: Mon, 3 Dec 2018 19:17:01 +0100 Subject: [PATCH] Fixes #1213 Category RSS dataprovider support --- .../Plugin/Rss/CategoryPlugin.php | 68 +++++++++++++++++++ .../etc/frontend/di.xml | 8 +++ 2 files changed, 76 insertions(+) create mode 100644 src/module-elasticsuite-catalog/Plugin/Rss/CategoryPlugin.php diff --git a/src/module-elasticsuite-catalog/Plugin/Rss/CategoryPlugin.php b/src/module-elasticsuite-catalog/Plugin/Rss/CategoryPlugin.php new file mode 100644 index 000000000..ef814a6a0 --- /dev/null +++ b/src/module-elasticsuite-catalog/Plugin/Rss/CategoryPlugin.php @@ -0,0 +1,68 @@ + + * @copyright 2018 Smile + * @license Open Software License ("OSL") v. 3.0 + */ +namespace Smile\ElasticsuiteCatalog\Plugin\Rss; + +use Smile\ElasticsuiteCore\Search\Request\QueryInterface; + +/** + * Category RSS data provider plugin + * + * @category Smile + * @package Smile\ElasticsuiteCatalog + */ +class CategoryPlugin +{ + /** + * Apply category filter to the collection + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * + * @param \Magento\Catalog\Model\Rss\Category $dataProvider Data provider. + * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection Product collection. + * @param \Magento\Catalog\Model\Category $category Current category. + * @param int $storeId Store ID. + * + * @return \Magento\Catalog\Model\ResourceModel\Product\Collection + */ + public function afterGetProductCollection( + \Magento\Catalog\Model\Rss\Category $dataProvider, + \Magento\Catalog\Model\ResourceModel\Product\Collection $collection, + \Magento\Catalog\Model\Category $category, + $storeId + ) { + $collection->addFieldToFilter('category_ids', $this->getCategoryFilterParam($category)); + + return $collection; + } + + /** + * Return category filter param + * + * @param \Magento\Catalog\Model\Category $category Category. + * + * @return int|QueryInterface + */ + private function getCategoryFilterParam(\Magento\Catalog\Model\Category $category) + { + $filterParam = $category->getId(); + + if ($category->getVirtualRule()) { // Implicit dependency to Virtual Categories module. + $category->setIsActive(true); + + $filterParam = $category->getVirtualRule()->getCategorySearchQuery($category); + } + + return $filterParam; + } +} diff --git a/src/module-elasticsuite-catalog/etc/frontend/di.xml b/src/module-elasticsuite-catalog/etc/frontend/di.xml index 84b7a7e97..7e578974a 100644 --- a/src/module-elasticsuite-catalog/etc/frontend/di.xml +++ b/src/module-elasticsuite-catalog/etc/frontend/di.xml @@ -173,6 +173,14 @@ + + + + Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory + + + +