tuyennn / magento2-outofstockatlast

Magento 2.4.x module Sort Out Of Stock Product At last the product list
GNU General Public License v3.0
55 stars 12 forks source link

Not working with big collections. #56

Closed ArthurMenegoli closed 2 months ago

ArthurMenegoli commented 2 months ago

Preconditions (*)

  1. Magento 2.4.6
  2. PHP 8.2
  3. Elasticsearch 7.17.21

Steps to reproduce (*)

  1. Have at least 30 products on a category.
  2. Independent of pagination size

Expected result (*)

  1. Expected to put out of stock products in the last positions, just like it does in category pages with less than 10 products.

Actual result (*)

  1. When the number of products in the collection rises, the functionality no longer works and products maintain their original postion on listing.

Hi. We have a great interest in the functionality of this module, and it works perfectly fine for our clients on category pages where the product collection size is fewer than 10 products. But as soon as new products are added, the sorting no longer works. I have tried disabling other third-party modules, changing the theme to Luma, and even updating the Magento version. But nothing seems to help.

Is this a known bug or an intended feature? Or am I just missing something? Why would the module work that way for us? Can you shed some light on how to solve this or what might be causing this behavior?

Thank you for your time. Arthur Menegoli Cammino Digital

tuyennn commented 2 months ago

Thank you for the report, I believe while the number of products rising in some ways doesn't affect anything to the algorithm. Just make sure your indexing is working properly on your side.

ArthurMenegoli commented 1 month ago

For anyone wondering.. we found the indexing issue.

Elasticsearch 7 was correctly configured and the indexer was correctly reindexing. But for some reason, the Magento installation on our stores did not correctly create the inventory_stock_1 view on database. It might be because of our installation script or maybe incompatible libs. We don't know yet.

But that caused the module to determinate "is_salable" of all products as 0, so the sorting attribute of "out_of_stock" was indeed sorted by desc, but since all products had the same value, the sort ended up being irrelevant.

We fixed the view table inventory_stock_1 via this script: CREATE OR REPLACE ALGORITHM = UNDEFINED VIEWinventory_stock_1AS select distinctlegacy_stock_status.product_idASproduct_id, legacy_stock_status.website_idASwebsite_id, legacy_stock_status.stock_idASstock_id, legacy_stock_status.qtyASquantity, legacy_stock_status.stock_statusASis_salable, product.skuASsku from (cataloginventory_stock_status`legacy_stock_status join catalog_product_entity product on ((legacy_stock_status.product_id = product.entity_id)));`

After that, reindexing was able to correctly assume products "is_salable", fixing the sort.

Thank you tuyenn for pointing out the indexing issue, helped on our debugging.

tuyennn commented 1 month ago

Duplicate with https://github.com/tuyennn/magento2-outofstockatlast/issues/55 and related to https://github.com/magento/magento2/issues/19542