magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Product name wise sorting not working

Open sunilit42 opened this issue 1 year ago • 16 comments

Preconditions and environment

  • lastest magento
  • add product
  • create category and assign that product
  • consider page limit per page 12

Steps to reproduce

  • Category and that related product
  • open that category page
  • elasticsearch configure
  • click on sort by product name
  • find that first product that category into backend add store wise name entry
  • open that category page
  • you will page limit 12 but it is showing 11 if you do store wise entry

Expected result

  • it should be show all 12 products

Actual result

  • it is showing 11 products

Additional information

No response

Release note

No response

Triage and priority

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [ ] 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”.

sunilit42 avatar Sep 02 '22 11:09 sunilit42

Hi @sunilit42. 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 Sep 02 '22 11:09 m2-assistant[bot]

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

sunilit42 avatar Sep 02 '22 11:09 sunilit42

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

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

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:

  • [ ] 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 Sep 05 '22 11:09 m2-assistant[bot]

@magento give me 2.4-develop instance

engcom-November avatar Sep 20 '22 03:09 engcom-November

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

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

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.

engcom-November avatar Sep 20 '22 04:09 engcom-November

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

sunilit42 avatar Sep 20 '22 05:09 sunilit42

@magento I am working on this

mirianfalconi avatar Sep 22 '22 18:09 mirianfalconi

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.

m2-assistant[bot] avatar Sep 22 '22 18:09 m2-assistant[bot]

@magento add to contributors team

mirianfalconi avatar Sep 22 '22 18:09 mirianfalconi

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

m2-assistant[bot] avatar Sep 22 '22 18:09 m2-assistant[bot]

@magento add to contributors team

mirianfalconi avatar Sep 22 '22 19:09 mirianfalconi

@magento I am working on this

mirianfalconi avatar Sep 22 '22 19:09 mirianfalconi

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 avatar Sep 28 '22 04:09 engcom-November

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

engcom-November avatar Sep 29 '22 05:09 engcom-November

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

github-jira-sync-bot avatar Sep 29 '22 05:09 github-jira-sync-bot

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

m2-assistant[bot] avatar Sep 29 '22 05:09 m2-assistant[bot]

@magento I am working on this

sunilit42 avatar Sep 29 '22 14:09 sunilit42

@magento I am working on this

mirianfalconi avatar Oct 11 '22 02:10 mirianfalconi

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.

zaximus84 avatar Nov 14 '22 19:11 zaximus84