-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1215 from rbayet/fix_1213_category_rss_feed
Fixes #1213 Fulltext collection for category RSS
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/module-elasticsuite-catalog/Plugin/Rss/CategoryPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters