My theme is child of magento blank. On default magento 2 layered navigation sort labels of attribute in layered navigation by Count number of products that exist with this attribute.
I need to change this alphabetically sort order.
Example: Colours: Red (10) Blue (3) Yellow (2) Change to: Blue (3) Red (10) Yellow (2)
Where should I look? In module_layered_navigation? or Magento\Framework\Data\OptionSourceInterface? or somwhere else?
I found this in vendor/magento/module-catalog/Model/Layer/Filter/AbstractFilter.php
* Create filter item object
*
* @param string $label
* @param mixed $value
* @param int $count
* @return \Magento\Catalog\Model\Layer\Filter\Item
*/
protected function _createItem($label, $value, $count = 0)
{
return $this->_filterItemFactory->create()
->setFilter($this)
->setLabel($label)
->setValue($value)
->setCount($count);
}
Maybe I could add somewhere usort:
usort($this, function($a, $b) {
if($a['order']==$b['order']) return 0;
return $a['order'] < $b['order']?1:-1;
});