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;
});
-
it's code not working it please help me how to specific attribute option filter by alphabetically'Rv Singh– Rv Singh2019年05月28日 08:53:20 +00:00Commented May 28, 2019 at 8:53
1 Answer 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.
-
it's code not working it please help me how to specific attribute option filter by alphabetically use in programaticallyRv Singh– Rv Singh2019年05月28日 08:53:36 +00:00Commented May 28, 2019 at 8:53
-
Do you use any extra module for layered navigation? Remember to clean cache after changing sort.BartZalas– BartZalas2019年05月28日 09:09:48 +00:00Commented 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 atozRv Singh– Rv Singh2019年05月28日 09:35:00 +00:00Commented May 28, 2019 at 9:35
-
So this module is now enabled or not?BartZalas– BartZalas2019年05月28日 09:48:49 +00:00Commented 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 orderRv Singh– Rv Singh2019年05月28日 09:54:34 +00:00Commented May 28, 2019 at 9:54
Explore related questions
See similar questions with these tags.