1

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;

});

asked May 20, 2018 at 22:40
1
  • it's code not working it please help me how to specific attribute option filter by alphabetically' Commented May 28, 2019 at 8:53

1 Answer 1

1

It looks like it works on the newest Magento 2.2.4

Sort order can be applied manually in the backend.

Edit attribute => Properties=> Sort using drag & drop

Easy way.

answered May 23, 2018 at 21:58
9
  • it's code not working it please help me how to specific attribute option filter by alphabetically use in programatically Commented May 28, 2019 at 8:53
  • Do you use any extra module for layered navigation? Remember to clean cache after changing sort. Commented May 28, 2019 at 9:09
  • Actuall i have to use one module for layer navigation but in frontend side for brand attribute option left side not sorting alphabetically.so i need to show atoz Commented May 28, 2019 at 9:35
  • So this module is now enabled or not? Commented May 28, 2019 at 9:48
  • Yes this module enable but my question is how to sort in left side brand section inside option label alphabetically order Commented May 28, 2019 at 9:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.