Esempio n. 1
0
 /**
  * Get data array for building attribute filter items
  *
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _getItemsData()
 {
     $attribute = $this->getAttributeModel();
     /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
     $productCollection = $this->getLayer()->getProductCollection();
     $optionsFacetedData = $productCollection->getFacetedData($attribute->getAttributeCode());
     if (count($optionsFacetedData) === 0 && $this->getAttributeIsFilterable($attribute) !== static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS) {
         return $this->itemDataBuilder->build();
     }
     $productSize = $productCollection->getSize();
     $options = $attribute->getFrontend()->getSelectOptions();
     foreach ($options as $option) {
         if (empty($option['value'])) {
             continue;
         }
         $value = $option['value'];
         $count = isset($optionsFacetedData[$value]['count']) ? (int) $optionsFacetedData[$value]['count'] : 0;
         // Check filter type
         if ($this->getAttributeIsFilterable($attribute) === static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS && (!$this->isOptionReducesResults($count, $productSize) || $count === 0)) {
             continue;
         }
         $this->itemDataBuilder->addItemData($this->tagFilter->filter($option['label']), $value, $count);
     }
     return $this->itemDataBuilder->build();
 }
Esempio n. 2
0
 /**
  * @SuppressWarnings(PHPMD.CamelCaseMethodName)
  * @SuppressWarnings(PHPMD.ElseExpression)
  *
  * {@inheritDoc}
  */
 protected function _getItemsData()
 {
     /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
     $productCollection = $this->getLayer()->getProductCollection();
     $optionsFacetedData = $productCollection->getFacetedData($this->getFilterField());
     $items = [];
     if (isset($optionsFacetedData['__other_docs'])) {
         $this->hasMoreItems = $optionsFacetedData['__other_docs']['count'] > 0;
         unset($optionsFacetedData['__other_docs']);
     }
     foreach ($optionsFacetedData as $value => $data) {
         $items[$value] = ['label' => $this->tagFilter->filter($value), 'value' => $value, 'count' => $data['count']];
     }
     $items = $this->addOptionsData($items);
     return $items;
 }
Esempio n. 3
0
 /**
  * Get data array for building attribute filter items
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return array
  */
 protected function _getItemsData()
 {
     $attribute = $this->getAttributeModel();
     $this->_requestVar = $attribute->getAttributeCode();
     $options = $attribute->getFrontend()->getSelectOptions();
     $optionsCount = $this->_getResource()->getCount($this);
     foreach ($options as $option) {
         if (is_array($option['value'])) {
             continue;
         }
         if ($this->string->strlen($option['value'])) {
             // Check filter type
             if ($this->getAttributeIsFilterable($attribute) == self::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS) {
                 if (!empty($optionsCount[$option['value']])) {
                     $this->itemDataBuilder->addItemData($this->tagFilter->filter($option['label']), $option['value'], $optionsCount[$option['value']]);
                 }
             } else {
                 $this->itemDataBuilder->addItemData($this->tagFilter->filter($option['label']), $option['value'], isset($optionsCount[$option['value']]) ? $optionsCount[$option['value']] : 0);
             }
         }
     }
     return $this->itemDataBuilder->build();
 }
Esempio n. 4
0
 /**
  * Get data array for building attribute filter items
  *
  * @return array
  */
 protected function _getItemsData()
 {
     $attribute = $this->getAttributeModel();
     $this->_requestVar = $attribute->getAttributeCode();
     $options = $attribute->getFrontend()->getSelectOptions();
     $optionsCount = $this->_getResource()->getCount($this);
     $data = array();
     foreach ($options as $option) {
         if (is_array($option['value'])) {
             continue;
         }
         if ($this->string->strlen($option['value'])) {
             // Check filter type
             if ($this->_getIsFilterableAttribute($attribute) == self::OPTIONS_ONLY_WITH_RESULTS) {
                 if (!empty($optionsCount[$option['value']])) {
                     $data[] = array('label' => $this->tagFilter->filter($option['label']), 'value' => $option['value'], 'count' => $optionsCount[$option['value']]);
                 }
             } else {
                 $data[] = array('label' => $this->tagFilter->filter($option['label']), 'value' => $option['value'], 'count' => isset($optionsCount[$option['value']]) ? $optionsCount[$option['value']] : 0);
             }
         }
     }
     return $data;
 }