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

Category Sort (position, name, price) behavior has changed in M2.4.5 #36045

Open
1 of 5 tasks
n2diving-dgx opened this issue Aug 28, 2022 · 15 comments · May be fixed by #36047
Open
1 of 5 tasks

Category Sort (position, name, price) behavior has changed in M2.4.5 #36045

n2diving-dgx opened this issue Aug 28, 2022 · 15 comments · May be fixed by #36047
Labels
Area: Product Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: ready for confirmation Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: PR in progress Reported on 2.4.5 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@n2diving-dgx
Copy link

n2diving-dgx commented Aug 28, 2022

Preconditions and environment

Category Sort (position, name, price) behavior has changed in M2.4.5

The sorted order of products appearing in catalog category pages is controlled by the Sort By setting selected by the user from a drop down appearing in the upper right corner of the category page.

Previously the out-of-stock status of a product had no effect on the sort order, but as of update to M2.4.5 this appears to be working differently, out-of-stock items are not sorting in to the correct order regardless of setting. Instead, starting with M2.4.5 the out-of-stock items are always listed at the end.

Steps to reproduce

This can be reproduced in a clean installition of M2.4.5 with the Luma data as follows...

(1) perform clean installtion of M2.4.5 with the Luma store data
(2) In frontend website navigate to Home > Gear > Watches, and observe that the position of Luma Analog Watch is appropriate and correct in the order of products displayed for all Sort By selections.
(3) In admin backend Catalog > Product > Luma Analog Watch > Advanced Inventory, uncheck Use Config Settings and change Out-of-Stock Threshold value to be greater than current Qty, in this case value = 101, alternately change the current QTY value to zero (either method will cause same results) then Done and Save.
(4) in admin backend Stores > Configuration > Catalog > Inventory, uncheck Use System Value and change Display Out Of Stock Products value to Yes, then Save Config
(5) in admin backend Cache Management, Flush Magento Cache
(6) In frontend Home > Gear > Watches observe that the position of Luma Analog Watch is ALWAYS at the end of products displayed regardless of Sort By selection

Expected result

Sort order of products displayed in catalog pages is not affected by their stock status.

Actual result

Instead, starting with M2.4.5 the out-of-stock items are always listed at the end. Previously the out-of-stock status of a product had no effect on the sort order, but as of update to M2.4.5 this is working differently, out-of-stock items are not sorting in to the correct order regardless of setting.

Additional information

There are plenty of 3rd party trivial extensions and patches that do this, but the M.2.4.5 Release Notes do not document this significant change in the sort behavior that greatly impacts the presentation order of products in categories on our website and our customers ability to find them. There does not appear to be an admin method or setting to change this new behavior, at least not one I can find or that is documented in the M2.4.5 Release Notes.

Additional Information

In frontend website navigate to Home > Gear > Watches, and observe that the position of Luma Analog Watch is appropriate and correct in the order of products displayed for all Sort By selections.

dj

dj 2

dj 3

in admin backend Stores > Configuration > Catalog > Inventory, uncheck Use System Value and change Display Out Of Stock Products value to Yes, then Save Config.

29

In frontend Home > Gear > Watches observe that the position of Luma Analog Watch is ALWAYS at the end of products displayed regardless of Sort By selection

30

31

32

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”.
@m2-assistant
Copy link

m2-assistant bot commented Aug 28, 2022

Hi @n2diving-dgx. 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.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

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

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-assistant
Copy link

m2-assistant bot commented Aug 29, 2022

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

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

@engcom-Hotel engcom-Hotel added the Reported on 2.4.5 Indicates original Magento version for the Issue report. label Aug 29, 2022
@engcom-Bravo
Copy link
Contributor

@magento give me 2.4.5 instance

@magento-deployment-service
Copy link

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

@magento-deployment-service
Copy link

@engcom-Bravo
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

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

@magento-deployment-service
Copy link

@engcom-Bravo
Copy link
Contributor

engcom-Bravo commented Aug 29, 2022

Hi @n2diving-dgx,

Precondition:
• Magento 2.4-develop && 2.4.5
• PHP 8.1

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop branch and 2.4.5 project-community-edition as well the issue is reproducible.

Kindly refer the screenshots.

1.In frontend website navigate to Home > Gear > Watches, and observe that the position of Luma Analog Watch is appropriate and correct in the order of products displayed for all Sort By selections.

dj

dj 2

dj 3

  1. In admin backend Catalog > Product > Luma Analog Watch > Advanced Inventory, uncheck Use Config Settings and change Out-of-Stock Threshold value to be greater than current Qty, in this case value = 101, alternately change the current QTY value to zero (either method will cause same results) then Done and Save.

28

3.in admin backend Stores > Configuration > Catalog > Inventory, uncheck Use System Value and change Display Out Of Stock Products value to Yes, then Save Config.

29

4.In frontend Home > Gear > Watches observe that the position of Luma Analog Watch is ALWAYS at the end of products displayed regardless of Sort By selection

30

31

32

Products (out-of-stock items) are always listed at the end.

Hence Confirming this issue.

Thanks.

@engcom-Bravo engcom-Bravo added Area: Product Component: Catalog Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Aug 29, 2022
@github-jira-sync-bot
Copy link

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

@m2-assistant
Copy link

m2-assistant bot commented Aug 30, 2022

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

@engcom-Bravo engcom-Bravo added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Issue: ready for confirmation labels Aug 30, 2022
@pmonosolo
Copy link

Try this fix:
magento/inventory#3360

@codebase-md
Copy link

codebase-md commented Sep 8, 2022

Hi there,

this is happening due to a change in function \Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier::apply(). In line 108 the function getProductIdsBySaleability() checks setting cataloginventory/options/show_out_of_stock and if enabled and a category id is given(in other words you are on a category page) it calls the function categoryProductByCustomSortOrder($categoryId)(line 190) which resets the entire collections select statement and adds on line 213 a sort order for is_salable with hardcoded direction DESC. Additionally we found out that this function introduces another issue. It prevents custom sort orders to be applied due to the reset of the select statement. I created a patch which fixes this behavior(allows custom sorting an removes sorting by stock status):

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 1662619604901)
@@ -210,20 +210,14 @@
         $storeId = $this->collection->getStoreId();
         $searchCriteria = $this->searchResult->getSearchCriteria();
         $sortOrders = $searchCriteria->getSortOrders() ?? [];
-        $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 can't promise that it's the best solution but it solved the problem for now. Feedback welcome.

@pmonosolo
Copy link

$storeId = $this->collection->getStoreId();
$searchCriteria = $this->searchResult->getSearchCriteria();
$sortOrders = $searchCriteria->getSortOrders() ?? [];

  •    $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'
    

This does not work for me unfortunately - the toolbar still shows the full catalog:

image

It means that the whole catalog is being outputted regardless of the search query.

@codebase-md
Copy link

@pmonosolo

$storeId = $this->collection->getStoreId();
$searchCriteria = $this->searchResult->getSearchCriteria();
$sortOrders = $searchCriteria->getSortOrders() ?? [];

  •    $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'
    

This does not work for me unfortunately - the toolbar still shows the full catalog:

image

It means that the whole catalog is being outputted regardless of the search query.

I'm sorry to hear that. But this patch is not intended to fix problems with the amount of products shown in your catalog. It is intended to fix the issue in regards to sort orders and position at which out of stock products are shown.

You might have a different issue here since I'm not able to reproduce the behavior described by you.

@engcom-Hotel engcom-Hotel moved this to Pull Request In Progress in High Priority Backlog Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Product Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: ready for confirmation Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: PR in progress Reported on 2.4.5 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
Status: Pull Request In Progress
Development

Successfully merging a pull request may close this issue.

6 participants