Skip to content

Commit

Permalink
Do not apply the currentcategory filter in admin.
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud committed Feb 7, 2025
1 parent eae3cd3 commit 20078e0
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Smile\ElasticsuiteCatalog\Model\Product\Search\Request\Container\Filter;

use Magento\Catalog\Model\Config\LayerCategoryConfig;
use Magento\Framework\App\State;
use Smile\ElasticsuiteCore\Api\Search\ContextInterface;
use Smile\ElasticsuiteCore\Api\Search\Request\Container\FilterInterface;
use Smile\ElasticsuiteVirtualCategory\Model\Category\Filter\Provider;
Expand Down Expand Up @@ -42,21 +43,29 @@ class CurrentCategory implements FilterInterface
*/
private $filterProvider;

/**
* @var \Magento\Framework\App\State
*/
private $appState;

/**
* Current Category filter constructor.
*
* @param ContextInterface $searchContext Current search context.
* @param LayerCategoryConfig $layerCategoryConfig Category LayerConfig
* @param Provider $filterProvider Category Filter provider.
* @param State $appState Application state.
*/
public function __construct(
ContextInterface $searchContext,
LayerCategoryConfig $layerCategoryConfig,
Provider $filterProvider
Provider $filterProvider,
State $appState
) {
$this->searchContext = $searchContext;
$this->layerCategoryConfig = $layerCategoryConfig;
$this->filterProvider = $filterProvider;
$this->appState = $appState;
}

/**
Expand All @@ -66,7 +75,11 @@ public function getFilterQuery()
{
$query = null;

if (false === $this->isDisplayCategoryFilter() && $this->searchContext->getCurrentCategory()) {
if ($this->isAdminArea()) {
return null;
}

if (false === $this->isDisplayCategoryFilter() && $this->searchContext->getCurrentCategory()) {
$query = $this->filterProvider->getQueryFilter($this->searchContext->getCurrentCategory());
}

Expand All @@ -82,4 +95,18 @@ private function isDisplayCategoryFilter()
{
return $this->layerCategoryConfig->isCategoryFilterVisibleInLayerNavigation();
}

/**
* Check if we are in the admin area
*
* @return bool
*/
private function isAdminArea()
{
try {
return $this->appState->getAreaCode() === \Magento\Framework\App\Area::AREA_ADMINHTML;
} catch (\Magento\Framework\Exception\LocalizedException $exception) {
return false;
}
}
}

0 comments on commit 20078e0

Please sign in to comment.