magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Unable to sort catalog by Custom Attribute of type Dropdown

Open gwharton opened this issue 2 years ago • 2 comments

Preconditions and environment

  • 2.4.5
  • Sample data

Steps to reproduce

Create test product attribute with type dropdown Assign values first, second, third, fourth image 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.

image

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

image

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”.

gwharton avatar Aug 12 '22 08:08 gwharton

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.


: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

m2-assistant[bot] avatar Aug 12 '22 08:08 m2-assistant[bot]

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

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: 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 branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced 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.

m2-assistant[bot] avatar Aug 12 '22 09:08 m2-assistant[bot]

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.

new_prod1 NewProduct_2

engcom-Delta avatar Aug 16 '22 16:08 engcom-Delta

I have updated the steps to reproduce with more detailed layout of required steps to reproduce.

gwharton avatar Aug 17 '22 09:08 gwharton

@magento give me 2.4-develop instance

gwharton avatar Aug 17 '22 09:08 gwharton

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. image

gwharton avatar Aug 17 '22 09:08 gwharton

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:

Screenshot 2022-08-19 at 3 31 36 PM

On frontend Screenshot 2022-08-19 at 3 26 47 PM

engcom-Delta avatar Aug 19 '22 10:08 engcom-Delta

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-6427 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Aug 19 '22 10:08 github-jira-sync-bot

: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.

m2-assistant[bot] avatar Aug 19 '22 10:08 m2-assistant[bot]

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

NetStorm84 avatar Aug 25 '22 13:08 NetStorm84

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'

codebase-md avatar Sep 07 '22 11:09 codebase-md

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

rogerdz avatar Oct 04 '22 16:10 rogerdz

Still present on EE 2.4.5-p4 Setting OOO products to no display is a really bad SEO practice.

jmonrove avatar Aug 29 '23 22:08 jmonrove