-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFilter.php
72 lines (55 loc) · 1.98 KB
/
Filter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace MageSuite\SeoLinkMasking\Helper;
class Filter extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
* @var \MageSuite\SeoLinkMasking\Helper\Configuration
*/
protected $configuration;
/**
* @var \Magento\Framework\App\RequestInterface
*/
protected $request;
/**
* @var \MageSuite\SeoLinkMasking\Service\FilterableAttributesProvider
*/
protected $filterableAttributesProvider;
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\MageSuite\SeoLinkMasking\Helper\Configuration $configuration,
\Magento\Framework\App\RequestInterface $request,
\MageSuite\SeoLinkMasking\Service\FilterableAttributesProvider $filterableAttributesProvider
) {
parent::__construct($context);
$this->configuration = $configuration;
$this->request = $request;
$this->filterableAttributesProvider = $filterableAttributesProvider;
}
public function isFilterSelected($category)
{
$filters = $this->request->getQueryValue();
if (empty($filters)) {
return false;
}
$filterableAttributes = $this->filterableAttributesProvider->getList($category);
if (empty($filterableAttributes)) {
return false;
}
$difference = array_diff_key($filters, $filterableAttributes);
return count($difference) < count($filters);
}
public function isFilterMasked($category, $attributeId)
{
if ($this->configuration->onlyOneFilterDemasked() && $this->isFilterSelected($category)) {
return true;
}
$seoLinkMasking = $category->getSeoLinkMasking();
if (empty($seoLinkMasking)) {
return $this->configuration->getDefaultMaskingState();
}
if (isset($seoLinkMasking[$attributeId])) {
return $seoLinkMasking[$attributeId];
}
return $this->configuration->getDefaultMaskingState();
}
}