-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search API : vitual categories support.
- Loading branch information
Aurélien FOUCRET
committed
Jan 22, 2018
1 parent
b940892
commit 48fc94b
Showing
4 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
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
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
95 changes: 95 additions & 0 deletions
95
src/module-elasticsuite-virtual-category/Plugin/Search/RequestMapperPlugin.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,95 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer | ||
* versions in the future. | ||
* | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteVirtualCategory | ||
* @author Aurelien FOUCRET <[email protected]> | ||
* @copyright 2018 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteVirtualCategory\Plugin\Search; | ||
|
||
use Smile\ElasticsuiteCore\Model\Search\RequestMapper; | ||
use Smile\ElasticsuiteCore\Api\Search\Request\ContainerConfigurationInterface; | ||
use Magento\Framework\Api\Search\SearchCriteriaInterface; | ||
|
||
/** | ||
* Extenstion of the category form UI data provider. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteVirtualCategory | ||
* @author Aurelien FOUCRET <[email protected]> | ||
*/ | ||
class RequestMapperPlugin | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $productSearchContainers = [ | ||
'quick_search_container', | ||
'catalog_view_container', | ||
]; | ||
|
||
/** | ||
* @var \Magento\Catalog\Api\CategoryRepositoryInterface | ||
*/ | ||
private $categoryRepository; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository Category repository. | ||
*/ | ||
public function __construct(\Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository) | ||
{ | ||
$this->categoryRepository = $categoryRepository; | ||
} | ||
|
||
/** | ||
* Post process catalog filters (virtual categories handling). | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
* | ||
* @param RequestMapper $subject Request mapper. | ||
* @param array $result Original filters. | ||
* @param ContainerConfigurationInterface $containerConfiguration Container configuration. | ||
* @param SearchCriteriaInterface $searchCriteria Search criteria. | ||
* | ||
* @return array[] | ||
*/ | ||
public function afterGetFilters( | ||
RequestMapper $subject, | ||
$result, | ||
ContainerConfigurationInterface $containerConfiguration, | ||
SearchCriteriaInterface $searchCriteria | ||
) { | ||
if ($this->isEnabled($containerConfiguration) && isset($result['category.category_id'])) { | ||
$categoryId = current(array_values($result['category.category_id'])); | ||
$storeId = $containerConfiguration->getStoreId(); | ||
|
||
$category = $this->categoryRepository->get($categoryId, $storeId); | ||
$result[] = $category->getVirtualRule()->getCategorySearchQuery($category); | ||
unset($result['category.category_id']); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Indicates if the plugin should be used or not. | ||
* | ||
* @param ContainerConfigurationInterface $containerConfiguration Container configuration. | ||
* | ||
* @return boolean | ||
*/ | ||
private function isEnabled(ContainerConfigurationInterface $containerConfiguration) | ||
{ | ||
return in_array($containerConfiguration->getName(), $this->productSearchContainers); | ||
} | ||
} |
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