Skip to content

Commit

Permalink
Merge pull request #1215 from rbayet/fix_1213_category_rss_feed
Browse files Browse the repository at this point in the history
Fixes #1213 Fulltext collection for category RSS
  • Loading branch information
romainruaud authored Dec 5, 2018
2 parents 582e6df + 2f9892f commit df1cb18
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/module-elasticsuite-catalog/Plugin/Rss/CategoryPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Richard BAYET <richard.bayet@smile.fr>
* @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;
}
}
8 changes: 8 additions & 0 deletions src/module-elasticsuite-catalog/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@
</arguments>
</type>

<!-- Ensure category RSS feed dataprovider is using fulltext collection, to prevent error when it sends it through the Layer -->
<type name="Magento\Catalog\Model\Rss\Category">
<arguments>
<argument name="collectionFactory" xsi:type="object">Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory</argument>
</arguments>
<plugin name="apply_category_filter" type="Smile\ElasticsuiteCatalog\Plugin\Rss\CategoryPlugin"/>
</type>

<type name="Magento\CatalogSearch\Controller\Result\Index">
<plugin name="redirect_if_one_result" type="Smile\ElasticsuiteCatalog\Plugin\CatalogSearch\ResultPlugin"/>
</type>
Expand Down

0 comments on commit df1cb18

Please sign in to comment.