Skip to content

Commit 871321f

Browse files
author
Oleksandr Iegorov
committed
MC-29026: GraphQL returns filters with some data if you making request to not existing or empty category
1 parent cbca71e commit 871321f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Layer/DataProvider/Filters.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Catalog\Model\Layer\Filter\AbstractFilter;
1111
use Magento\CatalogGraphQl\Model\Resolver\Layer\FiltersProvider;
12+
use Magento\Catalog\Model\Layer\Filter\Item;
1213

1314
/**
1415
* Layered navigation filters data provider.
@@ -49,7 +50,7 @@ public function getData(string $layerType, array $attributesToFilter = null) : a
4950
'filter_items_count' => $filter->getItemsCount(),
5051
'request_var' => $filter->getRequestVar(),
5152
];
52-
/** @var \Magento\Catalog\Model\Layer\Filter\Item $filterItem */
53+
/** @var Item $filterItem */
5354
foreach ($filter->getItems() as $filterItem) {
5455
$filterGroup['filter_items'][] = [
5556
'label' => (string)$filterItem->getLabel(),
@@ -63,15 +64,22 @@ public function getData(string $layerType, array $attributesToFilter = null) : a
6364
return $filtersData;
6465
}
6566

67+
/**
68+
* Check for adding filter to the list
69+
*
70+
* @param AbstractFilter $filter
71+
* @param array $attributesToFilter
72+
* @return bool
73+
*/
6674
private function isNeedToAddFilter(AbstractFilter $filter, array $attributesToFilter): bool
6775
{
6876
if ($attributesToFilter === null) {
6977
$result = (bool)$filter->getItemsCount();
7078
} else {
71-
try {
79+
if ($filter->hasAttributeModel()) {
7280
$filterAttribute = $filter->getAttributeModel();
7381
$result = in_array($filterAttribute->getAttributeCode(), $attributesToFilter);
74-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
82+
} else {
7583
$result = false;
7684
}
7785
}

app/code/Magento/SwatchesGraphQl/Plugin/Filters/DataProviderPlugin.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ public function __construct(
5353
* @param Filters $subject
5454
* @param \Closure $proceed
5555
* @param string $layerType
56-
* @param array $attributesToFilter
56+
* @param array|null $attributesToFilter
5757
* @return array
58+
* @throws \Magento\Framework\Exception\LocalizedException
5859
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5960
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
61+
* phpcs:disable Generic.Metrics.NestingLevel
6062
*/
6163
public function aroundGetData(
6264
Filters $subject,
@@ -97,4 +99,5 @@ public function aroundGetData(
9799

98100
return $filtersData;
99101
}
102+
//phpcs:enable
100103
}

0 commit comments

Comments
 (0)