integer-net / solr-magento1

Free Solr Module for Magento 1 for greatly improved search results
GNU Lesser General Public License v3.0
48 stars 12 forks source link

Category filter sort order #11

Open tim-bezhashvyly opened 7 years ago

tim-bezhashvyly commented 7 years ago

Not sure if it is intentional but category filter here will be ordered by Magento category sort order and not facet counts.

If not a solution could be the following:

$childrenCategories = iterator_to_array($this->_getCurrentChildrenCategories());

foreach ($categoryFacets as $childCategoryId => $count) {
    if (isset($childrenCategories[$childCategoryId])) {

        $item = new Varien_Object();
        $item->setCount($count);
        $optionLabel = $childrenCategories[$childCategoryId]->getName();
        $item->setLabel($this->_getCheckboxHtml('cat', $childCategoryId) . ' ' . $optionLabel);
        $item->setUrl($this->_getUrl($childCategoryId));
        $item->setIsChecked($this->_isSelected('cat', $childCategoryId));
        $item->setType('category');
        $item->setOptionId($childCategoryId);

        Mage::dispatchEvent('integernet_solr_filter_item_create', array(
            'item' => $item,
            'solr_result' => $this->_getSolrResult(),
            'type' => 'category',
            'entity_id' => $childCategoryId,
            'entity' => $childrenCategories[$childCategoryId],
        ));

        if (!$item->getIsDisabled()) {
            $this->_categoryFilterItems[$optionLabel] = $item;
        }
    }
}
avstudnitz commented 7 years ago

@schmengler @sriesterer Your Opinion? Should category filters be sorted by number of results or by Magento sort order?

schmengler commented 7 years ago

IMHO, category sort order makes sense, but I understand that some would prefer sort by count - so if we change that, it should be configurable.