Configurable attribute options are not sorted on the product page.
The issue is related to the method ConfigurableAttributeData::getAttributeOptionsData()
in the file app/code/Magento/ConfigurableProduct/Model/ConfigurableAttributeData.php
.
I think you should load options sort order here and sort the output array.
@dmaciej thank you for your feedback.
Please, identify exact version of Magento you are running.
@veloraven updated
2.1.1 CE / CentOS 6.7 / PHP 7
See the same behavior with configurable products with 2 options: the second option is always sorted by label and not by sort order.
For the solution please visit on the link: http://magento.stackexchange.com/questions/141899/configurable-product-attribute-sort-order-in-dropdown-2-12/146858#146858
OR
As I checked this issue and found that while fetching the attribute options, there is no sorting filter added in the query by default in Magento 2.1.2, So to fix this issue need to add the below code to add the ORDER By in function getAttributeOptions on line no 282 in file: vendor/magento/module-configurable-product/Model/ResourceModel/Product/Type/Configurable.php Now, it's working fine for me.
->joinInner(
['attribute_opt' => $this->getTable('eav_attribute_option')],
'attribute_opt.option_id = entity_value.value',
[]
)->order(
'attribute_opt.sort_order ASC'
);
If unable to edit the code then please replace this getAttributeOptions function with code as below:
`public function getAttributeOptions($superAttribute, $productId)
{
$scope = $this->getScopeResolver()->getScope();
$select = $this->getConnection()->select()->from(
['super_attribute' => $this->getTable('catalog_product_super_attribute')],
[
'sku' => 'entity.sku',
'product_id' => 'product_entity.entity_id',
'attribute_code' => 'attribute.attribute_code',
'value_index' => 'entity_value.value',
'option_title' => $this->getConnection()->getIfNullSql(
'option_value.value',
'default_option_value.value'
),
'default_title' => 'default_option_value.value',
]
)->joinInner(
['product_entity' => $this->getTable('catalog_product_entity')],
"product_entity.{$this->getProductEntityLinkField()} = super_attribute.product_id",
[]
)->joinInner(
['product_link' => $this->getTable('catalog_product_super_link')],
'product_link.parent_id = super_attribute.product_id',
[]
)->joinInner(
['attribute' => $this->getTable('eav_attribute')],
'attribute.attribute_id = super_attribute.attribute_id',
[]
)->joinInner(
['entity' => $this->getTable('catalog_product_entity')],
'entity.entity_id = product_link.product_id',
[]
)->joinInner(
['entity_value' => $superAttribute->getBackendTable()],
implode(
' AND ',
[
'entity_value.attribute_id = super_attribute.attribute_id',
'entity_value.store_id = 0',
"entity_value.{$this->getProductEntityLinkField()} = "
. "entity.{$this->getProductEntityLinkField()}",
]
),
[]
)->joinLeft(
['option_value' => $this->getTable('eav_attribute_option_value')],
implode(
' AND ',
[
'option_value.option_id = entity_value.value',
'option_value.store_id = ' . $scope->getId(),
]
),
[]
)->joinLeft(
['default_option_value' => $this->getTable('eav_attribute_option_value')],
implode(
' AND ',
[
'default_option_value.option_id = entity_value.value',
'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID,
]
),
[]
)->where(
'super_attribute.product_id = ?',
$productId
)->where(
'attribute.attribute_id = ?',
$superAttribute->getAttributeId()
)->joinInner(
['attribute_opt' => $this->getTable('eav_attribute_option')],
'attribute_opt.option_id = entity_value.value',
[]
)->order(
'attribute_opt.sort_order ASC'
);
return $this->getConnection()->fetchAll($select);
}`
@dmaciej thank you for your feedback.
Internal issue created: MAGETWO-61484
@slopukhov Is there a way for the Magento community to see the progress on an internal issue? If I decide to work on a fix for this issue, how do I know Magento has not already fixed this issue elsewhere but has not updated this ticket?
is there any update about this issue?
I'm also having this issue with latest magento 2.1.7.
@slopukhov Any update about this issue ?
Any updates regarding this issue?
@dmatthew this GitHub issue will be updated unless the bug is fixed in scope of another internal ticket. For now the process is:
develop
develop
if yeshttps://github.com/magento/magento2/commit/071ba86109da628eebbdecd85cae31c8f5a8e930#diff-64f271ca81aa683e5df1a23c862458d8 looks like an attempt to fix this issue on client side, but as it is a part of 2.1.x
stable releases somehow it did not do the trick.
@DariuszMaciejewski, thank you for your report.
We've created internal ticket(s) MAGETWO-61484 to track progress on the issue.
I can confirm this issues still exists in 2.1.9, Whats interesting, it seems to ignore the actual sort_order value that exists in eav_attribute_option table. I have an attribute (manufacturer) that has ~800 items in its list, and 3/4 of the way down the list restarts at A through Z for a list of items that was imported later on. I suspected the sort_order was wrong on this second group, however it seems to be correct (I exported both eav_attribute_option and eav_attribute_option_value tables, joined the data by option_id, and interestingly enough, the optionID AND sort_order are in perfect alphabetical order, however in the back-end attribute editor, its all messed up, as well as in the front-end.
Ive tried the suggested fix, however I hate modifying the core files, so I've tried rolling my own patch, but seem to be failing at getting it to work (no errors, compiles, but seems to do nothing).
I'm working on it #SQUASHTOBERFEST
No time this October, sry :)
FYI, we successfully using previously mentioned solution with
$select->joinInner(
['attribute_opt' => $subject->getTable('eav_attribute_option')],
'attribute_opt.option_id = entity_value.value',
[]
)->order(
'attribute_opt.sort_order ASC'
);
in around plugin for \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::getAttributeOptions
.
@orlangur If I remember my try to upgrade to Magento 2.2, this solution do not work in Magento 2.2, the class has been refactored.
But as you said, it works on 2.1.x
@franckgarnier21 good to know, we are using it on 2.1.x
.
Still having this same issue in Magento 2.2.1
I'd like to provide a little additional information / Less than ideal workaround - After some initial digging into this issue, and debugging core logic, it appears this is called on product save and I'll provide steps below.
It appears that if after step 5 in the original reproduction steps if you go to the Configurable product page -> Edit Configuration -> Click next -next - next and without changing anything - The configurable product model is reloaded and it correctly applies this new attribute sort order to the single configurable product referenced and if you subsequently save the product it will work as expected.
Magento 2.1.9 code and reference.
Any updates regarding this issue?
Thank you, duffner!
It's an amazing solution! It works.
@duffner it's a less than ideal workaround, but works great upon a second save! Thanks!
@alen12345 and @BigTonni, glad it helps!
@magento-engcom-team, is there any update on this?
In case others using Magento 2.1.x would bump into this, here's a patch-file including the solution developed by @jagdishram:
0001-Patch-config-product-attribute-sort-order.patch.zip
The patch (tested on a Magento 2.1.5 installation), after extracting it, can be applied easily using the composer plugin cweagans/composer-patches.
_Updated the patch file to include required changes to related unit tests as well._
Hi @DariuszMaciejewski. Thank you for your report.
The issue has been fixed in magento/magento2#12963 by @wardcapp in 2.2-develop branch
Related commit(s):
The fix will be available with the upcoming patch release.
Not fixed in 2.2.2 it looks like. I've asked for a patch from support. But I made a simple patch based on the commit 9794d38 referenced above too, and it seems to work well. I'll attached it as a TXT file. You should be able to run git apply
in the root to apply this on 2.2.2.
Hi @DariuszMaciejewski. Thank you for your report.
The issue has been fixed in magento/magento2#13011 by @wardcapp in 2.3-develop branch
Related commit(s):
The fix will be available with the upcoming patch release.
Hi @DariuszMaciejewski. Thank you for your report.
The issue has been fixed in magento/magento2#12962 by @wardcapp in 2.1-develop branch
Related commit(s):
The fix will be available with the upcoming patch release.
@magento-team
sorting bug will be fixed with 2.2.5 or do we have to wait for 2.3 ?
@splendidinternet from commit mentioned in https://github.com/magento/magento2/issues/7441#issuecomment-355542437 you can that it is already fixed in 2.2.4.
I checked the code for my 2.2.5 installation, the changes mentioned in comment #7441 are there but I still don't have control over the order of my configurable values. Anyone else having this issue?
This is caching issue (2.2.4+). If var/cache is cleared after reordering attribute option values in the backend, then the changes are in effect on the frontend.
Maybe automatic tests should take a caching layer into account?
I figured it out. You have to change your website to developer mode then switch it back to production. Once I did that I was able to control the configurable values.
Someone has any solution for Magento 2.2.5?
Experiencing the same issue in Magento 2.2.5, All solution mentioned above is not working for Magento 2.2.5, They suggested code changes are added in Magento 2.2.5 files but sort order is still not fixed.
Any news on this issue, is it fixed in Magento 2.2.6 release?
Open File \Magento\ConfigurableProduct\Model\ConfigurableAttributeData.php
Update Function getAttributesData()
Replace : Around line no :35
$attributes[$attributeId] = [
'id' => $attributeId,
'code' => $productAttribute->getAttributeCode(),
'label' => $productAttribute->getStoreLabel($product->getStoreId()),
'options' => $attributeOptionsData,
'position' => $attribute->getPosition(),
];
With
$attributes[$attributeId] = [
'id' => $attributeId,
'code' => $productAttribute->getAttributeCode(),
'label' => $productAttribute->getStoreLabel($product->getStoreId()),
'options' => $attributeOptionsData,
'position' => $productAttribute->getPosition(),
];
I have been having this issue (Magento 2.2.6, these attributes were created back in Mage 2.0.*) myself and none of the fixes in this thread worked because of a single issue:
mysql> select * from eav_attribute_option where attribute_id=146;
+-----------+--------------+------------+
| option_id | attribute_id | sort_order |
+-----------+--------------+------------+
| 7 | 146 | 0 |
| 8 | 146 | 0 |
| 9 | 146 | 0 |
| 10 | 146 | 0 |
| 11 | 146 | 0 |
| 12 | 146 | 0 |
| 13 | 146 | 0 |
| 14 | 146 | 0 |
| 15 | 146 | 0 |
| 16 | 146 | 0 |
| 17 | 146 | 0 |
| 18 | 146 | 0 |
| 19 | 146 | 0 |
| 20 | 146 | 0 |
| 21 | 146 | 0 |
| 22 | 146 | 0 |
| 23 | 146 | 0 |
| 24 | 146 | 0 |
| 25 | 146 | 0 |
| 26 | 146 | 0 |
| 27 | 146 | 0 |
| 28 | 146 | 0 |
+-----------+--------------+------------+
I will manually assign each one with a sort order. I wonder if this could have been done with the Mage REST API?
I have been having this issue (Magento 2.2.6, these attributes were created back in Mage 2.0.*) myself and none of the fixes in this thread worked because of a single issue:
mysql> select * from eav_attribute_option where attribute_id=146; +-----------+--------------+------------+ | option_id | attribute_id | sort_order | +-----------+--------------+------------+ | 7 | 146 | 0 | | 8 | 146 | 0 | | 9 | 146 | 0 | | 10 | 146 | 0 | | 11 | 146 | 0 | | 12 | 146 | 0 | | 13 | 146 | 0 | | 14 | 146 | 0 | | 15 | 146 | 0 | | 16 | 146 | 0 | | 17 | 146 | 0 | | 18 | 146 | 0 | | 19 | 146 | 0 | | 20 | 146 | 0 | | 21 | 146 | 0 | | 22 | 146 | 0 | | 23 | 146 | 0 | | 24 | 146 | 0 | | 25 | 146 | 0 | | 26 | 146 | 0 | | 27 | 146 | 0 | | 28 | 146 | 0 | +-----------+--------------+------------+
I will manually assign each one with a sort order. I wonder if this could have been done with the Mage REST API?
In the Magento version 2.2.6 the order can be modified from the Admin, in the Manage Options (Values of Your Attribute) tab of the attribute
If you have some trubles with attributes on configurable products try to flash cache and run indexer:
php bin/magento ca:fl
php bin/magento indexer:reindex
Most helpful comment
@slopukhov Is there a way for the Magento community to see the progress on an internal issue? If I decide to work on a fix for this issue, how do I know Magento has not already fixed this issue elsewhere but has not updated this ticket?