magento2
magento2 copied to clipboard
Unable to sort catalog by Custom Attribute of type Dropdown
Preconditions and environment
- 2.4.5
- Sample data
Steps to reproduce
Create test product attribute with type dropdown
Assign values first, second, third, fourth
Set "Used for sorting in product listing" to Yes
Add product attribute to attribute set "Bag"
Configure the following products to have test attribute values
Joust 24-MB01 - fourth Fusion 24-MB02 - third Crown Summit 24-MB03 - second Strive 24-MB04 - first Wayfarer 24-MB05 - fourth Rival Field 24-MB06 - third
Remove all other products that have attribute set of "Bag" to leave the above 6 items.
Clear cache
Go to frontend and browse to the Bag category. Sort by test
Expected result
The products should be ordered by test attribute.
Strive (first) should be first Crown Summit (second) should be next Fusion (third) should be next Rival Field (third) should be next Joust (fourth) should be next Wayfarer (fourth) should be next
Actual result
Additional information
No response
Release note
Products can now be sorted on the Product Listing pages by custom attribute of Dropdown type.
Triage and priority
- [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- [X] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Hi @gwharton. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
- Summary of the issue
- Information on your environment
- Steps to reproduce
- Expected and actual results
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
- Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
Hi @engcom-Delta. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
-
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
Details
If the issue has a valid description, the labelIssue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until labelIssue: Format is valid
appears. -
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add
Issue: Clear Description
label to the issue by yourself. -
[ ] 3. Add
Component: XXXXX
label(s) to the ticket, indicating the components it may be related to. -
[ ] 4. Verify that the issue is reproducible on
2.4-develop
branchDetails
- Add the comment@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-develop
branch, please, add the labelReproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here! -
[ ] 5. Add label
Issue: Confirmed
once verification is complete. -
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hi @gwharton , Thank you for raising an issue , We tried to reproduce the issue on Magento 2.4.5 instance , we could not find out manage options at Stores-->Attributes-->Product. Please review the steps provided.
I have updated the steps to reproduce with more detailed layout of required steps to reproduce.
@magento give me 2.4-develop instance
Hi @gwharton. Thank you for your request. I'm working on Magento instance for you.
Hi @gwharton, here is your Magento Instance: https://89ee2a9d58500ec83f044e4cd4637101.instances.magento-community.engineering Admin access: https://89ee2a9d58500ec83f044e4cd4637101.instances.magento-community.engineering/admin_5b54 Login: 45427b0a Password: 601251524e7e
Confirmed on 2.4-develop instance.
Hi @gwharton ,
Thank you for providing inputs and we tried to reproduce the issue on Magento 2.4 develop , issue is reproducible. Actually products are getting sorted by its position instead of custom sort option.
Hence , issue has been confirmed.
Please find below screenshots for reference.
on backend setup:

On frontend
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-6427 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Delta. Thank you for verifying the issue.
Issue Available: @engcom-Delta, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
Hi @Rusllana. Thank you for your request. I'm working on Magento instance for you.
Hi @Rusllana, here is your Magento Instance: https://89ee2a9d58500ec83f044e4cd4637101.instances.magento-community.engineering Admin access: https://89ee2a9d58500ec83f044e4cd4637101.instances.magento-community.engineering/admin_12df Login: 9bdfe052 Password: 018da7767c2a
@magento give me 2.4-develop instance
Hi @NetStorm84. Thank you for your request. I'm working on Magento instance for you.
Hi @NetStorm84, here is your Magento Instance: https://89ee2a9d58500ec83f044e4cd4637101.instances.magento-community.engineering Admin access: https://89ee2a9d58500ec83f044e4cd4637101.instances.magento-community.engineering/admin_3f75 Login: 32e1a5a7 Password: 3a61b04927c7
Hello everybody,
I ran into the same problem. I think the root of this evil lies in \Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier::categoryProductByCustomSortOrder
. Here a completly new select statement is build which erases former table joins. Due to this circumstance custom sorting is not possible on category pages. Preconditions are that you are on a category page and you have enabled cataloginventory/options/show_out_of_stock
.
I created a patch which fixes this behavior but can't promise it's a correct solution. Feedback is welcome:
Index: vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php b/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php
--- a/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php
+++ b/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php (date 1662547508268)
@@ -213,17 +213,12 @@
$sortOrders = array_merge(['is_salable' => \Magento\Framework\DB\Select::SQL_DESC], $sortOrders);
$connection = $this->collection->getConnection();
- $query = clone $connection->select()
+ $query = clone $this->collection->getSelect()
->reset(\Magento\Framework\DB\Select::ORDER)
->reset(\Magento\Framework\DB\Select::LIMIT_COUNT)
- ->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET)
- ->reset(\Magento\Framework\DB\Select::COLUMNS);
- $query->from(
- ['e' => $this->collection->getTable('catalog_product_entity')],
- ['e.entity_id']
- );
+ ->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
+
$this->stockStatusApplier->setSearchResultApplier(true);
- $query = $this->stockStatusFilter->execute($query, 'e', 'stockItem');
$query->join(
['cat_index' => $this->collection->getTable('catalog_category_product_index_store' . $storeId)],
'cat_index.product_id = e.entity_id'
I don't know why it is need create a collection for filtering and sorting using mysql. It should be action in elasticsearch (include move out stock product to bottom of list). I created a PR for this idea https://github.com/magento/magento2/pull/36102
Still present on EE 2.4.5-p4 Setting OOO products to no display is a really bad SEO practice.