Not without custom code. There is a block class for the filter display, Mage_Catalog_Block_Layer_State
, but the filter data comes from the model Mage_Catalog_Model_Layer_State
, which is populated by Mage_Catalog_Model_Layer
and cannot be influenced from the block.
If your alternative sort order can be expressed with an SQL order clause, you could override Mage_Catalog_Model_Layer::_prepareAttributeCollection()
and change the sort order of the collection depending on the current category. It's set to $collection->setOrder('position', 'ASC')
before this method is called. But rewriting the layout model is better avoided.
A better option without rewrites is to create a custom block that extends Mage_Catalog_Block_Layer_State
:
class Stack_Catalog_Block_Layer_State extends Mage_Catalog_Block_Layer_State
{
public function getActiveFilters()
{
$filters = parent::getActiveFilters();
// $filters is an array of Mage_Catalog_Model_Layer_Filter_Item objects
// sort it with usort() to your needs
return $filters;
}
}
And another one that extends Mage_Catalog_Block_Layer_View
because this is where the state block is created:
class Stack_Catalog_Block_Layer_View extends Mage_Catalog_Block_Layer_View
{
protected function _initBlocks()
{
parent::_initBlocks();
$this->_stateBlockName = 'stack_catalog/layer_state';
}
}
Then replace the layer block in your categories custom layout update:
<reference name="left">
<block type="stack_catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
It's adding a new block, but using the same name catalog.leftnav
of the original block, so it will be replaced. This is because you cannot change the type of an existing block.
I will not give you the final solution but I will direct you to a place where you change the default behaviour.
So, if the attribute does not have a custom source it uses default source class which is \Magento\Eav\Model\Entity\Attribute\Source\Table
. All of the attribute options are returned in a function getAllOptions($withEmpty, $defaultValues)
. If you check it, you will find that in this function an attributeOptionCollection
is created on which a function setPositionOrder($dir, $sortAlpha)
is called. In this function we have hardcoded sort order of the options collection - $this->setOrder('main_table.sort_order', $dir);
I can give you quick 2 options to make it work as you want it:
- make a before plugin on
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::setPositionOrder
and change the $sortAlpha
variable to true
- I am not sure how the sorting will behave, but it should be alphabeticaly
- make and around/after plugin on
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::setPositionOrder
and change the sorting the way you want
There are of course more options, you can also make plugins for \Magento\Eav\Model\Entity\Attribute\Source\Table::getAllOptions
as well as you can override it (which I do not reccomend). Let me know which option you selected and good luck!
Best Answer
Do you mean this tab? You want to reorder, for example 'Pattern' to be first in the list? If so, you could override Magento_Catalog::product/view/attributes.phtml in your theme, and add custom logic inside the foreach statement. Maybe add all attributes to a new array but in the order you need, and after that loop through them and output on the frontend