magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

Product name wise sorting not working #36076

Open sunilit42 opened 2 years ago

sunilit42 commented 2 years ago

Preconditions and environment

Steps to reproduce

Expected result

Actual result

Additional information

No response

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 years ago

Hi @sunilit42. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

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.


: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

sunilit42 commented 2 years ago

@magento give me 2.4-develop instance - upcoming 2.4.x release

magento-deployment-service[bot] commented 2 years ago

Hi @sunilit42. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @sunilit42, here is your Magento Instance: https://8bd2bc0e66d0bd3b966a084f6762b575.instances.magento-community.engineering Admin access: https://8bd2bc0e66d0bd3b966a084f6762b575.instances.magento-community.engineering/admin_647b Login: 264aafc5 Password: df7a228d1ad9

m2-assistant[bot] commented 2 years ago

Hi @engcom-November. 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:

engcom-November commented 2 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-November. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-November, here is your Magento Instance: https://8bd2bc0e66d0bd3b966a084f6762b575.instances.magento-community.engineering Admin access: https://8bd2bc0e66d0bd3b966a084f6762b575.instances.magento-community.engineering/admin_6c30 Login: 59a569c6 Password: 0b44522f54bf

engcom-November commented 2 years ago

Hi @sunilit42 , Thank you for reporting and collaboration. Verified the issue on Magento 2.4-develop branch but the issue is not reproducible. Sort By Product Name - All 12 products are getting displayed per page and sorting is working on alphabetical order in the category page image Kindly recheck the issue on Magento 2.4-develop branch as it is having latest code base and provide missing steps if any if the issue is still reproducible. Thank you.

sunilit42 commented 2 years ago

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php#L239

Check this line , here is bug

if we enter name store wise name, coding doing sorting based on global name

i found that issue with EE endition and here may be also

mirianfalconi commented 2 years ago

@magento I am working on this

m2-assistant[bot] commented 2 years ago

Hi @mirianfalconi! :wave: Thank you for collaboration. Only members of Community Contributors Team are allowed to be assigned to the issue. Please use @magento add to contributors team command to join Contributors team.

mirianfalconi commented 2 years ago

@magento add to contributors team

m2-assistant[bot] commented 2 years ago

Hi @mirianfalconi! :wave: Thank you for joining. Please accept team invitation :point_right: here :point_left: and add your comment one more time.

mirianfalconi commented 2 years ago

@magento add to contributors team

mirianfalconi commented 2 years ago

@magento I am working on this

engcom-November commented 1 year ago

Verified the issue again on Magento 2.4-develop instance but observed below different issue on Admin - Categories page. Steps performed:

  1. Saved 12 products with different product names in All Store views scope, Default store view scope and other website scope
  2. Clean cache
  3. Verified front end - Category page of main website and other website
  4. sort by Product Name - No issue found Sorting working as expected and 12 products displayed per page.
  5. Verified Admin - Categories page - All Store Views scope - Products in Category - Default view - No issue. Product names displayed as expected Sort by Product Name - Issue: After applying sorting - Product names got changed to default store view product names. Bug logged for the same: https://github.com/magento/magento2/issues/36208 Issue verification is in progress for Enterprise edition.
engcom-November commented 1 year ago

Verified the issue again on Magento 2.4-develop instance and the issue is reproducible for other website store (Other than default website). Hence confirming this issue. Issue: Sorting with Product Name is giving 11 products in 1st page but the page limit is set to 12 image image

github-jira-sync-bot commented 1 year ago

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

m2-assistant[bot] commented 1 year ago

:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

sunilit42 commented 1 year ago

@magento I am working on this

mirianfalconi commented 1 year ago

@magento I am working on this

zaximus84 commented 1 year ago

I ran into this issue as well. To provide additional detail, the problem with the name sort is that it joins the catalog_product_entity_varchar table in a way that can produce multiple rows for the same product in the final query. On my Magento installation we have 3 websites and lots of products have ended up with name values at the default scope and all 3 website scopes.

The final query executed in \Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier::categoryProductByCustomSortOrder expects to return 12 distinct product ids, but due to joining the scoped names, it returns these 12 rows (where what appear to be duplicates are actually different store ids):

entity_id is_salable position name
518 1 123 Product Name
518 1 123 Product Name
518 1 123 Product Name
518 1 123 Product Name
270 1 51 Another Product Name
270 1 51 Another Product Name
270 1 51 Another Product Name
270 1 51 Another Product Name
414 1 105 Different Product Name
414 1 105 Different Product Name
414 1 105 Different Product Name
414 1 105 Different Product Name

As a result, only 518, 270, and 414 are returned, and only those 3 products show on the page. The solution here will be to properly group the query so only 1 row per entity id is returned, though that will be complicated by the need to include the product name for the proper scope for each product.

While not an actual fix for this issue, I worked around it on my installation by completely circumventing the logic with the flawed query. I patched Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier and replaced this:

        $ids = $this->getProductIdsBySaleability();

        if (count($ids) == 0) {
            $items = $this->sliceItems($this->searchResult->getItems(), $this->size, $this->currentPage);
            foreach ($items as $item) {
                $ids[] = (int)$item->getId();
            }
        }

with this:

        $items = $this->sliceItems($this->searchResult->getItems(), $this->size, $this->currentPage);
        foreach ($items as $item) {
            $ids[] = (int)$item->getId();
        }

This removes the logic that's trying to show all in stock products before all the out of stock products, and it instead uses the results from Elasticsearch directly without running the additional query containing the bug.