magento2: Unable to sort categories on front end by Quantity
Preconditions (*)
- Magento 2.4-develop, 2.3.2-p2
- PHP 7.2
- MariaDB 10.3
One thing that is missing is the fact that we have 2.3 Inventory modules disabled https://github.com/magento/magento2/issues/26124#issuecomment-572229769
Steps to reproduce (*)
- Update “Quantity” product attribute to be used in frontend sorting

- Reindex and flush cache
- Go into a category and try sorting by Quantity
Expected result (*)
Category page with products sorted by Quantity
Actual result (*)
“There has been an error” message and log number and this in logs

[2019-12-19 01:24:41] main.INFO: SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price`, `stock_status_index`.`stock_status` AS `is_salable` FROM `mg2e_catalog_product_entity` AS `e`
INNER JOIN `mg2e_catalog_category_product_index_store1` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id=47
INNER JOIN `mg2e_catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
LEFT JOIN `mg2e_cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1
INNER JOIN `mg2e_search_tmp_5dfad1594fde33_96411848` AS `search_result` ON e.entity_id = search_result.entity_id
LEFT JOIN `cataloginventory_stock_item` AS `stock_item_table` ON e.entity_id=stock_item_table.product_id ORDER BY `stock_item_table`.`qty` DESC
LIMIT 20 [] []
[2019-12-19 01:24:41] main.CRITICAL: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'jri_magento.cataloginventory_stock_item' doesn't exist, query was: SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price`, `stock_status_index`.`stock_status` AS `is_salable` FROM `mg2e_catalog_product_entity` AS `e`
INNER JOIN `mg2e_catalog_category_product_index_store1` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id=47
INNER JOIN `mg2e_catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
LEFT JOIN `mg2e_cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1
INNER JOIN `mg2e_search_tmp_5dfad1594fde33_96411848` AS `search_result` ON e.entity_id = search_result.entity_id
LEFT JOIN `cataloginventory_stock_item` AS `stock_item_table` ON e.entity_id=stock_item_table.product_id ORDER BY `stock_item_table`.`qty` DESC
LIMIT 20 [] []
[2019-12-19 01:24:41] main.ERROR: You cannot define a correlation name 'stock_item_table' more than once [] []
As you can see the cataloginventory_stock_item table somehow doesn’t have table prefix as do other tables 😦
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 20 (9 by maintainers)
You are still sorting by product name not quantity. I was talking about this toggle (Used in Storefront Sorting):
When toggle enabled gives this upon sorting category by Quantity
and error in logs is one i mentions in original post