/** * @return array */ protected function _getItemsData() { $this->_requestVar = str_replace('bx_products_', '', $this->bxFacets->getFacetParameterName($this->fieldName)); if (!$this->bxDataHelper->isHierarchical($this->fieldName)) { $attributeModel = $this->_config->getAttribute('catalog_product', substr($this->fieldName, 9))->getSource(); $order = $this->bxDataHelper->getFieldSortOrder($this->fieldName); if ($order == 2) { $values = $attributeModel->getAllOptions(); $responseValues = $this->bxDataHelper->useValuesAsKeys($this->bxFacets->getFacetValues($this->fieldName)); $selectedValues = $this->bxDataHelper->useValuesAsKeys($this->bxFacets->getSelectedValues($this->fieldName)); foreach ($values as $value) { $label = is_array($value) ? $value['label'] : $value; if (isset($responseValues[$label])) { $facetValue = $responseValues[$label]; $selected = isset($selectedValues[$facetValue]) ? true : false; $paramValue = $this->is_bx_attribute ? $this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue) : $attributeModel->getOptionId($this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue)); $this->itemDataBuilder->addItemData($this->tagFilter->filter($this->bxFacets->getFacetValueLabel($this->fieldName, $facetValue)), $selected ? 0 : $paramValue, $this->bxFacets->getFacetValueCount($this->fieldName, $facetValue), $selected, 'flat'); } } } else { $selectedValues = $this->bxDataHelper->useValuesAsKeys($this->bxFacets->getSelectedValues($this->fieldName)); $responseValues = $this->bxFacets->getFacetValues($this->fieldName); foreach ($responseValues as $facetValue) { $selected = isset($selectedValues[$facetValue]) ? true : false; $paramValue = $this->is_bx_attribute ? $this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue) : $attributeModel->getOptionId($this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue)); $this->itemDataBuilder->addItemData($this->tagFilter->filter($this->bxFacets->getFacetValueLabel($this->fieldName, $facetValue)), $selected ? 0 : $paramValue, $this->bxFacets->getFacetValueCount($this->fieldName, $facetValue), $selected, 'flat'); } } } else { $count = 1; $facetValues = array(); $parentCategories = $this->bxFacets->getParentCategories(); $parentCount = count($parentCategories); $value = false; foreach ($parentCategories as $key => $parentCategory) { if ($count == 1) { $count++; $homeLabel = __("All Categories"); $this->itemDataBuilder->addItemData($this->tagFilter->filter($homeLabel), 2, $this->bxFacets->getParentCategoriesHitCount($key), $value, 'home parent'); continue; } if ($parentCount == $count++) { $value = true; } $this->itemDataBuilder->addItemData($this->tagFilter->filter($parentCategory), $key, $this->bxFacets->getParentCategoriesHitCount($key), $value, 'parent'); } $sortOrder = $this->bxDataHelper->getFieldSortOrder($this->fieldName); if ($sortOrder == 2) { $facetLabels = $this->bxFacets->getCategoriesKeyLabels(); $childId = explode('/', end($facetLabels))[0]; $childParentId = $this->categoryFactory->create()->load($childId)->getParentId(); end($parentCategories); $parentId = key($parentCategories); $id = $parentId == null ? 2 : ($parentId == $childParentId ? $parentId : $childParentId); $cat = $this->categoryFactory->create()->load($id); foreach ($cat->getChildrenCategories() as $category) { if (isset($facetLabels[$category->getName()])) { $facetValues[] = $facetLabels[$category->getName()]; } } } if ($facetValues == null) { $facetValues = $this->bxFacets->getCategories(); } foreach ($facetValues as $facetValue) { $id = $this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue); if ($sortOrder == 2 || $this->categoryHelper->canShow($this->categoryFactory->create()->load($id))) { $this->itemDataBuilder->addItemData($this->tagFilter->filter($this->bxFacets->getFacetValueLabel($this->fieldName, $facetValue)), $id, $this->bxFacets->getFacetValueCount($this->fieldName, $facetValue), false, $value ? 'children' : 'home'); } } } return $this->itemDataBuilder->build(); }