Sort product attribute options by the position property in Magento
By Piotr Hankiewicz
January 11, 2016
Recently I was working with Magento 1.9.1, trying to get a list of dropdown attribute options sorted by the position property. However there is a known bug in Magento 1.9.1, where the position property is not respected.
I looked for a patch to fix this issue, however there was no official patch, and none of the available community fixes were good enough. So again, I needed to fix it by myself.
Tip! If you know how to apply a patch file it is here. If not, please continue.
We need to overwrite some Magento core code unfortunately. The good thing is that there is a cool way of doing this in Magento so we don’t need to overwrite the files directly, we need to create a local copy.
Copy app/code/Core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php file to app/code/local/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php. You need to create the whole directory structure. If you use Unix system it is simple as: (running from Magento root)
mkdir -p app/code/local/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/ cp app/code/Core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php app/code/local/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php
Fill a local file with a content from this source: https://gist.github.com/peter-hank/c917394ea9f1171ddeb8
After these changes it will work as expected and attribute options will be sorted by a position set.
This fix should work for any Magento 1.9.* version.