Skip to content

Commit 0e797bb

Browse files
authored
Create IsEntityFiltered.php
1 parent e24b5bf commit 0e797bb

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

ViewModel/IsEntityFiltered.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* NOTICE OF LICENSE
4+
*
5+
* This source file is subject to the Open Software License (OSL 3.0)
6+
* that is bundled with this package in the file LICENSE.txt.
7+
* It is also available through the world-wide-web at this URL:
8+
* https://opensource.org/licenses/OSL-3.0
9+
*
10+
* @category Amadeco
11+
* @package Amadeco_SmileCustomEntityLayeredNavigation
12+
* @copyright Copyright (c) Amadeco (https://www.amadeco.fr) - Ilan Parmentier
13+
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Amadeco\SmileCustomEntityLayeredNavigation\ViewModel;
18+
19+
use Magento\Framework\View\Element\Block\ArgumentInterface;
20+
use Magento\Framework\App\RequestInterface;
21+
use Magento\Catalog\Model\Layer;
22+
use Magento\Catalog\Model\Layer\Resolver;
23+
use Amadeco\SmileCustomEntityLayeredNavigation\Block\SetList as EntitiesPager;
24+
use Amadeco\SmileCustomEntityLayeredNavigation\Model\Layer as EntitiesLayer;
25+
use Amadeco\SmileCustomEntityLayeredNavigation\Model\Set\SetList\Toolbar as ToolbarModel;
26+
use Magento\Theme\Block\Html\Pager as ProductsPager;
27+
28+
class IsEntityFiltered implements ArgumentInterface
29+
{
30+
private Layer $catalogLayer;
31+
32+
/**
33+
* @param RequestInterface $request
34+
* @param Resolver $layerResolver
35+
* @param ProductsPager $productsPager
36+
* @param EntitiesPager $entitiesPager
37+
* @param EntitiesLayer $entitiesLayer
38+
*/
39+
public function __construct(
40+
private RequestInterface $request,
41+
private Resolver $layerResolver,
42+
private ProductsPager $productsPager,
43+
private EntitiesPager $entitiesPager,
44+
private EntitiesLayer $entitiesLayer
45+
) {
46+
$this->request = $request;
47+
$this->catalogLayer = $layerResolver->get();
48+
$this->productsPager = $productsPager;
49+
$this->entitiesPager = $entitiesPager;
50+
$this->entitiesLayer = $entitiesLayer;
51+
}
52+
53+
/**
54+
* Check whether the current entity is filtered
55+
*
56+
* @return bool
57+
*/
58+
public function isFiltered(): bool
59+
{
60+
$params = [
61+
ToolbarModel::PAGE_PARAM_NAME,
62+
ToolbarModel::ORDER_PARAM_NAME,
63+
ToolbarModel::DIRECTION_PARAM_NAME,
64+
ToolbarModel::MODE_PARAM_NAME,
65+
ToolbarModel::LIMIT_PARAM_NAME
66+
];
67+
68+
$requestParams = array_keys($this->request->getParams());
69+
$found = array_intersect($params, $requestParams);
70+
71+
return (
72+
count($found) > 0 ||
73+
count($this->catalogLayer->getState()->getFilters()) > 0 ||
74+
count($this->entitiesLayer->getState()->getFilters()) > 0
75+
);
76+
}
77+
}

0 commit comments

Comments
 (0)