9. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2022-09-08 08:48:54 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

9.1 Files compared

#LocationFileLast Modified
1/Volumes/Data 1/Ampps/www/Porto v4.0.2/Theme Files/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterCategory.php2022-04-22 07:34:10 +0000
2Theme Files/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterCategory.php2022-04-22 07:34:10 +0000

9.2 Comparison summary

DescriptionBetween
Files 1 and 2
Text BlocksLines
Unchanged1868
Changed00
Inserted00
Removed00

9.3 Comparison options

WhitespaceConsecutive whitespace is treated as a single space
Character caseDifferences in character case are significant
Line endingsDifferences in line endings (CR and LF characters) are ignored
CR/LF charactersNot shown in the comparison detail
Active line-pairing rules

9.4 Active regular expressions

No regular expressions were active.

9.5 Comparison detail

1 <?php 1 <?php
2 /** 2 /**
3  * Mageplaza 3  * Mageplaza
4  * 4  *
5  * NOTICE OF LICENSE 5  * NOTICE OF LICENSE
6  * 6  *
7  * This source file is subject to the Mageplaza.com license that is 7  * This source file is subject to the Mageplaza.com license that is
8  * available through the world-wide-web at this URL: 8  * available through the world-wide-web at this URL:
9  * https://www.mageplaza.com/LICENSE.txt 9  * https://www.mageplaza.com/LICENSE.txt
10  * 10  *
11  * DISCLAIMER 11  * DISCLAIMER
12  * 12  *
13  * Do not edit or add to this file if you wish to upgrade this extension to newer 13  * Do not edit or add to this file if you wish to upgrade this extension to newer
14  * version in the future. 14  * version in the future.
15  * 15  *
16  * @category    Mageplaza 16  * @category    Mageplaza
17  * @package     Mageplaza_LayeredNavigation 17  * @package     Mageplaza_LayeredNavigation
18  * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/) 18  * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
19  * @license     https://www.mageplaza.com/LICENSE.txt 19  * @license     https://www.mageplaza.com/LICENSE.txt
20  */ 20  */
21  21 
22 namespace Mageplaza\LayeredNavigation\Model\Layer\Filter; 22 namespace Mageplaza\LayeredNavigation\Model\Layer\Filter;
23  23 
24 use Magento\Catalog\Api\CategoryManagementInterface; 24 use Magento\Catalog\Api\CategoryManagementInterface;
25 use Magento\Catalog\Api\Data\CategoryTreeInterface; 25 use Magento\Catalog\Api\Data\CategoryTreeInterface;
26 use Magento\Catalog\Api\ProductAttributeRepositoryInterface; 26 use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
27 use Magento\Catalog\Model\Layer as LayerCatalog; 27 use Magento\Catalog\Model\Layer as LayerCatalog;
28 use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory; 28 use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory;
29 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; 29 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder;
30 use Magento\Catalog\Model\Layer\Filter\ItemFactory; 30 use Magento\Catalog\Model\Layer\Filter\ItemFactory;
31 use Magento\Catalog\Model\ResourceModel\Eav\Attribute; 31 use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
32 use Magento\CatalogSearch\Model\Layer\Filter\Category as AbstractFilter; 32 use Magento\CatalogSearch\Model\Layer\Filter\Category as AbstractFilter;
33 use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection; 33 use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
34 use Magento\Framework\App\RequestInterface; 34 use Magento\Framework\App\RequestInterface;
35 use Magento\Framework\Escaper; 35 use Magento\Framework\Escaper;
36 use Magento\Framework\Exception\LocalizedException; 36 use Magento\Framework\Exception\LocalizedException;
37 use Magento\Framework\Exception\NoSuchEntityException; 37 use Magento\Framework\Exception\NoSuchEntityException;
38 use Magento\Framework\Exception\StateException; 38 use Magento\Framework\Exception\StateException;
39 use Magento\Store\Model\StoreManagerInterface; 39 use Magento\Store\Model\StoreManagerInterface;
40 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; 40 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper;
41 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\CategoriesLevel; 41 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\CategoriesLevel;
42 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\RenderCategoryTree; 42 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\RenderCategoryTree;
43  43 
44 /** 44 /**
45  * Class Category 45  * Class Category
46  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter 46  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter
47  */ 47  */
48 class Category extends AbstractFilter 48 class Category extends AbstractFilter
49 { 49 {
50     /** @var LayerHelper */ 50     /** @var LayerHelper */
51     protected $_moduleHelper; 51     protected $_moduleHelper;
52  52 
53     /** @var bool Is Filterable Flag */ 53     /** @var bool Is Filterable Flag */
54     protected $_isFilter = false; 54     protected $_isFilter = false;
55  55 
56     /** @var Escaper */ 56     /** @var Escaper */
57     private $escaper; 57     private $escaper;
58  58 
59     /** @var  LayerCatalog\Filter\DataProvider\Category */ 59     /** @var  LayerCatalog\Filter\DataProvider\Category */
60     private $dataProvider; 60     private $dataProvider;
61     /** 61     /**
62      * @var ProductAttributeRepositoryInterface 62      * @var ProductAttributeRepositoryInterface
63      */ 63      */
64     protected $attributeRepository; 64     protected $attributeRepository;
65     /** 65     /**
66      * @var CategoryManagementInterface 66      * @var CategoryManagementInterface
67      */ 67      */
68     protected $categoryManagement; 68     protected $categoryManagement;
69  69 
70     /** 70     /**
71      * @var Attribute 71      * @var Attribute
72      */ 72      */
73     protected $attributeData; 73     protected $attributeData;
74  74 
75     protected $isFullCategoryTree = false; 75     protected $isFullCategoryTree = false;
76     /** 76     /**
77      * @var Item\DataBuilder 77      * @var Item\DataBuilder
78      */ 78      */
79     protected $layerDataBuilder; 79     protected $layerDataBuilder;
80     /** 80     /**
81      * @var CategoryItemFactory 81      * @var CategoryItemFactory
82      */ 82      */
83     protected $categoryItemFactory; 83     protected $categoryItemFactory;
84  84 
85     /** 85     /**
86      * Category constructor. 86      * Category constructor.
87      * 87      *
88      * @param ItemFactory $filterItemFactory 88      * @param ItemFactory $filterItemFactory
89      * @param StoreManagerInterface $storeManager 89      * @param StoreManagerInterface $storeManager
90      * @param LayerCatalog $layer 90      * @param LayerCatalog $layer
91      * @param DataBuilder $itemDataBuilder 91      * @param DataBuilder $itemDataBuilder
92      * @param Escaper $escaper 92      * @param Escaper $escaper
93      * @param CategoryFactory $dataProviderFactory 93      * @param CategoryFactory $dataProviderFactory
94      * @param LayerHelper $moduleHelper 94      * @param LayerHelper $moduleHelper
95      * @param ProductAttributeRepositoryInterface $attributeRepository 95      * @param ProductAttributeRepositoryInterface $attributeRepository
96      * @param CategoryManagementInterface $categoryManagement 96      * @param CategoryManagementInterface $categoryManagement
97      * @param Item\DataBuilder $layerDataBuilder 97      * @param Item\DataBuilder $layerDataBuilder
98      * @param CategoryItemFactory $categoryItemFactory 98      * @param CategoryItemFactory $categoryItemFactory
99      * @param array $data 99      * @param array $data
100      * 100      *
101      * @throws LocalizedException 101      * @throws LocalizedException
102      */ 102      */
103     public function __construct( 103     public function __construct(
104         ItemFactory $filterItemFactory, 104         ItemFactory $filterItemFactory,
105         StoreManagerInterface $storeManager, 105         StoreManagerInterface $storeManager,
106         LayerCatalog $layer, 106         LayerCatalog $layer,
107         DataBuilder $itemDataBuilder, 107         DataBuilder $itemDataBuilder,
108         Escaper $escaper, 108         Escaper $escaper,
109         CategoryFactory $dataProviderFactory, 109         CategoryFactory $dataProviderFactory,
110         LayerHelper $moduleHelper, 110         LayerHelper $moduleHelper,
111         ProductAttributeRepositoryInterface $attributeRepository, 111         ProductAttributeRepositoryInterface $attributeRepository,
112         CategoryManagementInterface $categoryManagement, 112         CategoryManagementInterface $categoryManagement,
113         Item\DataBuilder $layerDataBuilder, 113         Item\DataBuilder $layerDataBuilder,
114         CategoryItemFactory $categoryItemFactory, 114         CategoryItemFactory $categoryItemFactory,
115         array $data = [] 115         array $data = []
116     ) { 116     ) {
117         parent::__construct( 117         parent::__construct(
118             $filterItemFactory, 118             $filterItemFactory,
119             $storeManager, 119             $storeManager,
120             $layer, 120             $layer,
121             $itemDataBuilder, 121             $itemDataBuilder,
122             $escaper, 122             $escaper,
123             $dataProviderFactory, 123             $dataProviderFactory,
124             $data 124             $data
125         ); 125         );
126  126 
127         $this->escaper             = $escaper; 127         $this->escaper             = $escaper;
128         $this->_moduleHelper       = $moduleHelper; 128         $this->_moduleHelper       = $moduleHelper;
129         $this->dataProvider        = $dataProviderFactory->create(['layer' => $this->getLayer()]); 129         $this->dataProvider        = $dataProviderFactory->create(['layer' => $this->getLayer()]);
130         $this->attributeRepository = $attributeRepository; 130         $this->attributeRepository = $attributeRepository;
131         $this->categoryManagement  = $categoryManagement; 131         $this->categoryManagement  = $categoryManagement;
132         $this->layerDataBuilder    = $layerDataBuilder; 132         $this->layerDataBuilder    = $layerDataBuilder;
133         $this->categoryItemFactory = $categoryItemFactory; 133         $this->categoryItemFactory = $categoryItemFactory;
134     } 134     }
135  135 
136     /** 136     /**
137      * @inheritdoc 137      * @inheritdoc
138      */ 138      */
139     public function apply(RequestInterface $request) 139     public function apply(RequestInterface $request)
140     { 140     {
141         if (!$this->_moduleHelper->isEnabled()) { 141         if (!$this->_moduleHelper->isEnabled()) {
142             return parent::apply($request); 142             return parent::apply($request);
143         } 143         }
144  144 
145         $categoryId = $request->getParam($this->_requestVar); 145         $categoryId = $request->getParam($this->_requestVar);
146         if (empty($categoryId) && $this->isRenderCategoryTree() && $this->isFullCategoryTree){ 146         if (empty($categoryId) && $this->isRenderCategoryTree() && $this->isFullCategoryTree){
147             $request->setParam($this->_requestVar,$this->dataProvider->getCategory()->getId()); 147             $request->setParam($this->_requestVar,$this->dataProvider->getCategory()->getId());
148             $categoryId = $request->getParam($this->_requestVar); 148             $categoryId = $request->getParam($this->_requestVar);
149         } 149         }
150         if (empty($categoryId)) { 150         if (empty($categoryId)) {
151             return $this; 151             return $this;
152         } 152         }
153  153 
154         $categoryIds = []; 154         $categoryIds = [];
155         $categoryId = explode(',', $categoryId); $categoryId = array_unique($categoryId); 155         $categoryId = explode(',', $categoryId); $categoryId = array_unique($categoryId);
156         foreach ($categoryId as $id) { 156         foreach ($categoryId as $id) {
157             $this->dataProvider->setCategoryId($id); 157             $this->dataProvider->setCategoryId($id);
158             if ($this->dataProvider->isValid()) { 158             if ($this->dataProvider->isValid()) {
159                 $category = $this->dataProvider->getCategory(); 159                 $category = $this->dataProvider->getCategory();
160                 if ($this->isRenderCategoryTree()) { 160                 if ($this->isRenderCategoryTree()) {
161                     $categoryIds[] = $id; 161                     $categoryIds[] = $id;
162                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id)); 162                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id));
163                 } elseif ($request->getParam('id') !== $id) { 163                 } elseif ($request->getParam('id') !== $id) {
164                     $categoryIds[] = $id; 164                     $categoryIds[] = $id;
165                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id)); 165                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id));
166                 } 166                 }
167             } 167             }
168         } 168         }
169  169 
170         if (!empty($categoryIds)) { 170         if (!empty($categoryIds)) {
171             $this->_isFilter = true; 171             $this->_isFilter = true;
172             if ($this->isRenderCategoryTree() && $this->isFullCategoryTree) { 172             if ($this->isRenderCategoryTree() && $this->isFullCategoryTree) {
173                 $this->getLayer()->getProductCollection()->resetCategoryIds($this->getCurrentCategoryId()) 173                 $this->getLayer()->getProductCollection()->resetCategoryIds($this->getCurrentCategoryId())
174                     ->resetCategoryFilter($this->getCurrentCategoryId())->addLayerCategoryFilter($categoryIds); 174                     ->resetCategoryFilter($this->getCurrentCategoryId())->addLayerCategoryFilter($categoryIds);
175             } else { 175             } else {
176                 $this->getLayer()->getProductCollection()->addLayerCategoryFilter($categoryIds); 176                 $this->getLayer()->getProductCollection()->addLayerCategoryFilter($categoryIds);
177             } 177             }
178         } 178         }
179  179 
180         if ($parentCategoryId = $request->getParam('id')) { 180         if ($parentCategoryId = $request->getParam('id')) {
181             $this->dataProvider->setCategoryId($parentCategoryId); 181             $this->dataProvider->setCategoryId($parentCategoryId);
182         } 182         }
183  183 
184         return $this; 184         return $this;
185     } 185     }
186  186 
187     /** 187     /**
188      * @inheritDoc 188      * @inheritDoc
189      */ 189      */
190     protected function _initItems() 190     protected function _initItems()
191     { 191     {
192         if ($this->isRenderCategoryTree()) { 192         if ($this->isRenderCategoryTree()) {
193             $data = $this->getCategoryAdditionData(); 193             $data = $this->getCategoryAdditionData();
194             /** @var CategoryItem $itemCollection */ 194             /** @var CategoryItem $itemCollection */
195             $itemCollection = $this->categoryItemFactory->create(); 195             $itemCollection = $this->categoryItemFactory->create();
196             if ($data && $data['count']) { 196             if ($data && $data['count']) {
197                 $itemCollection->setStartPath($data['startPath']); 197                 $itemCollection->setStartPath($data['startPath']);
198                 $itemCollection->setCount($data['count']); 198                 $itemCollection->setCount($data['count']);
199                 foreach ($data['items'] as $parentId => $items) { 199                 foreach ($data['items'] as $parentId => $items) {
200                     foreach ($items as $item) { 200                     foreach ($items as $item) {
201                         $itemCollection->addItem( 201                         $itemCollection->addItem(
202                             $item['parent_id'], 202                             $item['parent_id'],
203                             $this->_createItem($item['label'], $item['value'], $item['count']) 203                             $this->_createItem($item['label'], $item['value'], $item['count'])
204                         ); 204                         );
205                     } 205                     }
206                 } 206                 }
207             } 207             }
208  208 
209             $this->_items = $itemCollection; 209             $this->_items = $itemCollection;
210  210 
211             return $this; 211             return $this;
212         } 212         }
213  213 
214         return parent::_initItems(); 214         return parent::_initItems();
215     } 215     }
216  216 
217     /** 217     /**
218      * @return array 218      * @return array
219      * @throws StateException 219      * @throws StateException
220      */ 220      */
221     protected function _getItemsData() 221     protected function _getItemsData()
222     { 222     {
223         if (!$this->_moduleHelper->isEnabled()) { 223         if (!$this->_moduleHelper->isEnabled()) {
224             return parent::_getItemsData(); 224             return parent::_getItemsData();
225         } 225         }
226  226 
227         /** @var Collection $productCollection */ 227         /** @var Collection $productCollection */
228         $productCollection = $this->getLayer()->getProductCollection(); 228         $productCollection = $this->getLayer()->getProductCollection();
229  229 
230         if ($this->_isFilter) { 230         if ($this->_isFilter) {
231             $productCollection = $productCollection->getCollectionClone() 231             $productCollection = $productCollection->getCollectionClone()
232                 ->removeAttributeSearch('category_ids'); 232                 ->removeAttributeSearch('category_ids');
233         } 233         }
234  234 
235         $optionsFacetedData = $productCollection->getFacetedData('category'); 235         $optionsFacetedData = $productCollection->getFacetedData('category');
236         $category           = $this->dataProvider->getCategory(); 236         $category           = $this->dataProvider->getCategory();
237         $categories         = $category->getChildrenCategories(); 237         $categories         = $category->getChildrenCategories();
238  238 
239         $collectionSize = $productCollection->getSize(); 239         $collectionSize = $productCollection->getSize();
240  240 
241         if ($category->getIsActive()) { 241         if ($category->getIsActive()) {
242             foreach ($categories as $childCategory) { 242             foreach ($categories as $childCategory) {
243                 $count = isset($optionsFacetedData[$childCategory->getId()]) 243                 $count = isset($optionsFacetedData[$childCategory->getId()])
244                     ? $optionsFacetedData[$childCategory->getId()]['count'] : 0; 244                     ? $optionsFacetedData[$childCategory->getId()]['count'] : 0;
245                 if ($childCategory->getIsActive() 245                 if ($childCategory->getIsActive()
246                     && $this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $collectionSize) 246                     && $this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $collectionSize)
247                 ) { 247                 ) {
248                     $this->itemDataBuilder->addItemData( 248                     $this->itemDataBuilder->addItemData(
249                         $this->escaper->escapeHtml($childCategory->getName()), 249                         $this->escaper->escapeHtml($childCategory->getName()),
250                         $childCategory->getId(), 250                         $childCategory->getId(),
251                         $count 251                         $count
252                     ); 252                     );
253                 } 253                 }
254             } 254             }
255         } 255         }
256  256 
257         return $this->itemDataBuilder->build(); 257         return $this->itemDataBuilder->build();
258     } 258     }
259  259 
260     /** 260     /**
261      * @return array 261      * @return array
262      * @throws LocalizedException 262      * @throws LocalizedException
263      * @throws NoSuchEntityException 263      * @throws NoSuchEntityException
264      */ 264      */
265     protected function getCategoryAdditionData() 265     protected function getCategoryAdditionData()
266     { 266     {
267         $attributeModel     = $this->getCategoryAttributeModel(); 267         $attributeModel     = $this->getCategoryAttributeModel();
268         $renderCategoryTree = $attributeModel->getData('render_category_tree'); 268         $renderCategoryTree = $attributeModel->getData('render_category_tree');
269         $itemsData          = []; 269         $itemsData          = [];
270         $startPath          = ''; 270         $startPath          = '';
271  271 
272         try { 272         try {
273             $optionsFacetedData = $this->getFacetedData(); 273             $optionsFacetedData = $this->getFacetedData();
274             if (empty($optionsFacetedData)) { 274             if (empty($optionsFacetedData)) {
275                 $categoryId                      = $this->dataProvider->getCategory()->getId(); 275                 $categoryId                      = $this->dataProvider->getCategory()->getId();
276                 $optionsFacetedData[$categoryId] = [ 276                 $optionsFacetedData[$categoryId] = [
277                     'value' => $categoryId, 277                     'value' => $categoryId,
278                     'count' => $this->getLayer()->getProductCollection()->getSize() 278                     'count' => $this->getLayer()->getProductCollection()->getSize()
279                 ]; 279                 ];
280             } 280             }
281         } catch (StateException $e) { 281         } catch (StateException $e) {
282             return []; 282             return [];
283         } 283         }
284  284 
285         try { 285         try {
286             $depth            = $renderCategoryTree !== RenderCategoryTree::FULL_CATEGORY 286             $depth            = $renderCategoryTree !== RenderCategoryTree::FULL_CATEGORY
287                 ? $attributeModel->getData('category_tree_depth') 287                 ? $attributeModel->getData('category_tree_depth')
288                 : null; 288                 : null;
289             $categoryTreeList = $this->categoryManagement->getTree($this->getCurrentCategoryId(), $depth); 289             $categoryTreeList = $this->categoryManagement->getTree($this->getCurrentCategoryId(), $depth);
290         } catch (NoSuchEntityException $e) { 290         } catch (NoSuchEntityException $e) {
291             $categoryTreeList = []; 291             $categoryTreeList = [];
292         } 292         }
293  293 
294         if ($categoryTreeList) { 294         if ($categoryTreeList) {
295             if ($renderCategoryTree === RenderCategoryTree::CUSTOM 295             if ($renderCategoryTree === RenderCategoryTree::CUSTOM
296                 && $attributeModel->getData('categories_level') === CategoriesLevel::CURRENT_CATEGORY 296                 && $attributeModel->getData('categories_level') === CategoriesLevel::CURRENT_CATEGORY
297             ) { 297             ) {
298                 $startPath = $categoryTreeList->getParentId(); 298                 $startPath = $categoryTreeList->getParentId();
299                 $count     = isset($optionsFacetedData[$categoryTreeList->getId()]) 299                 $count     = isset($optionsFacetedData[$categoryTreeList->getId()])
300                     ? $optionsFacetedData[$categoryTreeList->getId()]['count'] : 0; 300                     ? $optionsFacetedData[$categoryTreeList->getId()]['count'] : 0;
301  301 
302                 $this->layerDataBuilder->addItemData( 302                 $this->layerDataBuilder->addItemData(
303                     $this->escaper->escapeHtml($categoryTreeList->getName()), 303                     $this->escaper->escapeHtml($categoryTreeList->getName()),
304                     $categoryTreeList->getId(), 304                     $categoryTreeList->getId(),
305                     $categoryTreeList->getParentId(), 305                     $categoryTreeList->getParentId(),
306                     $categoryTreeList->getPosition(), 306                     $categoryTreeList->getPosition(),
307                     $categoryTreeList->getLevel(), 307                     $categoryTreeList->getLevel(),
308                     $count 308                     $count
309                 ); 309                 );
310             } else { 310             } else {
311                 $startPath = $categoryTreeList->getId(); 311                 $startPath = $categoryTreeList->getId();
312             } 312             }
313             $this->getCategoryTree($categoryTreeList, $optionsFacetedData); 313             $this->getCategoryTree($categoryTreeList, $optionsFacetedData);
314         } 314         }
315         $itemsData['startPath'] = $startPath; 315         $itemsData['startPath'] = $startPath;
316         $itemsData['count']     = $this->layerDataBuilder->getCount(); 316         $itemsData['count']     = $this->layerDataBuilder->getCount();
317         $itemsData['items']     = $this->layerDataBuilder->build(); 317         $itemsData['items']     = $this->layerDataBuilder->build();
318  318 
319         return $itemsData; 319         return $itemsData;
320     } 320     }
321  321 
322     /** 322     /**
323      * @return bool 323      * @return bool
324      * @throws NoSuchEntityException 324      * @throws NoSuchEntityException
325      */ 325      */
326     public function isRenderCategoryTree() 326     public function isRenderCategoryTree()
327     { 327     {
328         $attributeModel     = $this->getCategoryAttributeModel(); 328         $attributeModel     = $this->getCategoryAttributeModel();
329         $renderCategoryTree = $attributeModel->getData('render_category_tree'); 329         $renderCategoryTree = $attributeModel->getData('render_category_tree');
330  330 
331         if ($renderCategoryTree === RenderCategoryTree::FULL_CATEGORY) { 331         if ($renderCategoryTree === RenderCategoryTree::FULL_CATEGORY) {
332             $this->isFullCategoryTree = true; 332             $this->isFullCategoryTree = true;
333         } elseif ($renderCategoryTree === RenderCategoryTree::CUSTOM 333         } elseif ($renderCategoryTree === RenderCategoryTree::CUSTOM
334             && $attributeModel->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY) { 334             && $attributeModel->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY) {
335             $this->isFullCategoryTree = true; 335             $this->isFullCategoryTree = true;
336         } 336         }
337  337 
338         return $renderCategoryTree && $renderCategoryTree !== RenderCategoryTree::NO; 338         return $renderCategoryTree && $renderCategoryTree !== RenderCategoryTree::NO;
339     } 339     }
340  340 
341     /** 341     /**
342      * @param CategoryTreeInterface $tree 342      * @param CategoryTreeInterface $tree
343      * @param array $optionsFacetedData 343      * @param array $optionsFacetedData
344      */ 344      */
345     public function getCategoryTree($tree, $optionsFacetedData) 345     public function getCategoryTree($tree, $optionsFacetedData)
346     { 346     {
347         if (!$tree) { 347         if (!$tree) {
348             return; 348             return;
349         } 349         }
350  350 
351         foreach ($tree->getChildrenData() as $item) { 351         foreach ($tree->getChildrenData() as $item) {
352             $count = isset($optionsFacetedData[$item->getId()]) 352             $count = isset($optionsFacetedData[$item->getId()])
353                 ? $optionsFacetedData[$item->getId()]['count'] : 0; 353                 ? $optionsFacetedData[$item->getId()]['count'] : 0;
354  354 
355             if ($item->getIsActive() === '1') { 355             if ($item->getIsActive() === '1') {
356                 $child = $item->getChildrenData(); 356                 $child = $item->getChildrenData();
357                 if ($item->getLevel() !== '1') { 357                 if ($item->getLevel() !== '1') {
358                     $this->layerDataBuilder->addItemData( 358                     $this->layerDataBuilder->addItemData(
359                         $this->escaper->escapeHtml($item->getName()), 359                         $this->escaper->escapeHtml($item->getName()),
360                         $item->getId(), 360                         $item->getId(),
361                         $item->getParentId(), 361                         $item->getParentId(),
362                         $item->getPosition(), 362                         $item->getPosition(),
363                         $item->getLevel(), 363                         $item->getLevel(),
364                         $count 364                         $count
365                     ); 365                     );
366                 } 366                 }
367  367 
368                 if ($child) { 368                 if ($child) {
369                     $this->getCategoryTree($item, $optionsFacetedData); 369                     $this->getCategoryTree($item, $optionsFacetedData);
370                 } 370                 }
371             } 371             }
372         } 372         }
373     } 373     }
374  374 
375     /** 375     /**
376      * @return int|null 376      * @return int|null
377      * @throws LocalizedException 377      * @throws LocalizedException
378      * @throws NoSuchEntityException 378      * @throws NoSuchEntityException
379      */ 379      */
380     protected function getCurrentCategoryId() 380     protected function getCurrentCategoryId()
381     { 381     {
382         if ($this->isFullCategoryTree) { 382         if ($this->isFullCategoryTree) {
383             $categoryId = $this->_storeManager->getStore()->getRootCategoryId(); 383             $categoryId = $this->_storeManager->getStore()->getRootCategoryId();
384         } else { 384         } else {
385             $categoryId = $this->getCategoryAttributeModel()->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY 385             $categoryId = $this->getCategoryAttributeModel()->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY
386                 ? $this->_storeManager->getStore()->getRootCategoryId() 386                 ? $this->_storeManager->getStore()->getRootCategoryId()
387                 : $this->dataProvider->getCategory()->getId(); 387                 : $this->dataProvider->getCategory()->getId();
388         } 388         }
389  389 
390         return $categoryId; 390         return $categoryId;
391     } 391     }
392  392 
393     /** 393     /**
394      * @return array 394      * @return array
395      * @throws LocalizedException 395      * @throws LocalizedException
396      * @throws NoSuchEntityException 396      * @throws NoSuchEntityException
397      * @throws StateException 397      * @throws StateException
398      */ 398      */
399     protected function getFacetedData() 399     protected function getFacetedData()
400     { 400     {
401         /** @var Collection $productCollection */ 401         /** @var Collection $productCollection */
402         $productCollection = $this->getLayer()->getProductCollection(); 402         $productCollection = $this->getLayer()->getProductCollection();
403  403 
404         if ($this->_isFilter) { 404         if ($this->_isFilter) {
405             $productCollection = $productCollection->getCollectionClone() 405             $productCollection = $productCollection->getCollectionClone()
406                 ->removeAttributeSearch('category_ids'); 406                 ->removeAttributeSearch('category_ids');
407         } else { 407         } else {
408             $productCollection = $productCollection->getCollectionClone() 408             $productCollection = $productCollection->getCollectionClone()
409                 ->setCategoryFilter($this->getCurrentCategoryId()); 409                 ->setCategoryFilter($this->getCurrentCategoryId());
410         } 410         }
411  411 
412         return $productCollection->getFacetedData('category'); 412         return $productCollection->getFacetedData('category');
413     } 413     }
414  414 
415     /** 415     /**
416      * @return Attribute 416      * @return Attribute
417      * @throws NoSuchEntityException 417      * @throws NoSuchEntityException
418      */ 418      */
419     public function getCategoryAttributeModel() 419     public function getCategoryAttributeModel()
420     { 420     {
421         if (!$this->attributeData) { 421         if (!$this->attributeData) {
422             /** @var Attribute $attribute */ 422             /** @var Attribute $attribute */
423             $this->attributeData = $this->attributeRepository->get('category_ids'); 423             $this->attributeData = $this->attributeRepository->get('category_ids');
424             if ($this->attributeData->getId() && $data = $this->attributeData->getAdditionalData()) { 424             if ($this->attributeData->getId() && $data = $this->attributeData->getAdditionalData()) {
425                 $additionalData = $this->_moduleHelper->unserialize($data); 425                 $additionalData = $this->_moduleHelper->unserialize($data);
426                 if (is_array($additionalData)) { 426                 if (is_array($additionalData)) {
427                     $this->attributeData->addData($additionalData); 427                     $this->attributeData->addData($additionalData);
428                 } 428                 }
429             } 429             }
430         } 430         }
431  431 
432         return $this->attributeData; 432         return $this->attributeData;
433     } 433     }
434 } 434 }