Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable attribute options are not sorted #7441

Closed
mcjwsk opened this issue Nov 15, 2016 · 39 comments
Closed

Configurable attribute options are not sorted #7441

mcjwsk opened this issue Nov 15, 2016 · 39 comments
Labels
bug report Component: Catalog Fixed in 2.1.x The issue has been fixed in 2.1 release line Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@mcjwsk
Copy link
Contributor

mcjwsk commented Nov 15, 2016

Configurable attribute options are not sorted on the product page.

Preconditions

  1. Magento CE 2.1.2

Steps to reproduce

  1. Create a configurable attribute and add two options at least.
  2. Create a configurable product for these options.
  3. Go to the product page and see the configurable attribute select (options).
  4. Change attribute options sort order and flush all caches.
  5. Go to the product page and see the configurable attribute select (options) looks like before.

Expected result

  1. Configurable options HAVE been reordered.

Actual result

  1. Configurable options HAVE NOT been reordered.

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.

@veloraven
Copy link
Contributor

@dmaciej thank you for your feedback.
Please, identify exact version of Magento you are running.

@mcjwsk
Copy link
Contributor Author

mcjwsk commented Nov 16, 2016

@veloraven updated

@schasiepen
Copy link

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.

@jagdishram
Copy link

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);

}`

@slopukhov slopukhov self-assigned this Nov 28, 2016
@slopukhov slopukhov added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Nov 28, 2016
@slopukhov
Copy link
Contributor

@dmaciej thank you for your feedback.
Internal issue created: MAGETWO-61484

@slopukhov slopukhov removed their assignment Nov 28, 2016
@dmatthew
Copy link

dmatthew commented Feb 8, 2017

@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?

@harimayco
Copy link

harimayco commented Jun 15, 2017

is there any update about this issue?
I'm also having this issue with latest magento 2.1.7.

@lbassin
Copy link

lbassin commented Aug 7, 2017

@slopukhov Any update about this issue ?

@ruudboon
Copy link

Any updates regarding this issue?

@magento-engcom-team magento-engcom-team added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Catalog Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed labels Sep 11, 2017
@orlangur
Copy link
Contributor

@dmatthew this GitHub issue will be updated unless the bug is fixed in scope of another internal ticket. For now the process is:

  • check if issue still present in develop
  • prepare a PR to develop if yes

071ba86#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.

@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Oct 3, 2017
@magento-engcom-team
Copy link
Contributor

@DariuszMaciejewski, thank you for your report.
We've created internal ticket(s) MAGETWO-61484 to track progress on the issue.

@magento-engcom-team magento-engcom-team added 2.2.x Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release labels Oct 11, 2017
@ghost
Copy link

ghost commented Dec 23, 2017

@duffner it's a less than ideal workaround, but works great upon a second save! Thanks!

@duffner
Copy link

duffner commented Dec 23, 2017

@alen12345 and @BigTonni, glad it helps!

@magento-engcom-team, is there any update on this?

@wardcapp
Copy link
Contributor

wardcapp commented Jan 2, 2018

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.

wardcapp added a commit to wardcapp/magento2 that referenced this issue Jan 2, 2018
See github issue magento#7441, internal ticket MAGETWO-61484 and PR magento#12420.
wardcapp added a commit to wardcapp/magento2 that referenced this issue Jan 2, 2018
When fetching configurable options using the configurable product
option select builder, the sort_order of each option should be taken
into account as well, making sure the desired sorting is passed to the
frontend.

See github issue magento#7441, internal ticket MAGETWO-61484 and PR#12420 for more on this.
@magento-team
Copy link
Contributor

Hi @DariuszMaciejewski. Thank you for your report.
The issue has been fixed in #12963 by @wardcapp in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming patch release.

@magento-team magento-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Jan 5, 2018
wardcapp added a commit to wardcapp/magento2 that referenced this issue Jan 5, 2018
When fetching configurable options using the configurable product
option select builder, the sort_order of each option should be taken
into account as well, making sure the desired sorting is passed to the
frontend.

See github issue magento#7441, internal ticket MAGETWO-61484 and PR#12420 for more on this.
@thaddeusmt
Copy link

thaddeusmt commented Jan 9, 2018

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.

magento_configurable_swatch_sort_order.txt

@magento-team magento-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Jan 9, 2018
@magento-team
Copy link
Contributor

Hi @DariuszMaciejewski. Thank you for your report.
The issue has been fixed in #13011 by @wardcapp in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming patch release.

@magento-team
Copy link
Contributor

Hi @DariuszMaciejewski. Thank you for your report.
The issue has been fixed in #12962 by @wardcapp in 2.1-develop branch
Related commit(s):

The fix will be available with the upcoming patch release.

@magento-team magento-team added the Fixed in 2.1.x The issue has been fixed in 2.1 release line label Jan 10, 2018
@splendidinternet
Copy link

@magento-team

sorting bug will be fixed with 2.2.5 or do we have to wait for 2.3 ?

@orlangur
Copy link
Contributor

@splendidinternet from commit mentioned in #7441 (comment) you can that it is already fixed in 2.2.4.

@jfain189
Copy link

jfain189 commented Jul 3, 2018

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?

@pczerkas
Copy link

pczerkas commented Jul 4, 2018

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?

@jfain189
Copy link

jfain189 commented Jul 5, 2018

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.

@mattkrupnik
Copy link
Contributor

Someone has any solution for Magento 2.2.5?

@asadyar
Copy link

asadyar commented Oct 1, 2018

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?

@AbdulKadir-Agoliya
Copy link

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(),
];

@KSaho
Copy link

KSaho commented Nov 22, 2018

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?

@aluckyar
Copy link

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

@likemusic
Copy link
Contributor

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

@amenk
Copy link
Contributor

amenk commented Jul 13, 2022

Turns out we had the same problem like @aluckyar - what's a bit confusing is that the admin sorted display and the frontend sorted display differs, if sort_order = 0 for all the field (in our case we use a 3rd party importer which does not seem to write the sort_order field).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Fixed in 2.1.x The issue has been fixed in 2.1 release line Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests