@EvaF Thanks, but it doesn't work. The catalog page shows "No products found".
I've noticed 2 typos in your query (SELET instead of SELECT on the first line, and idproduct instead of id_product on the last one), but still doesn't work.
Additional info, but probably irrelevant: I tried to simulate your query and run it directly in phpMyAdmin like this:
SELECT * FROM ps_product_shop JOIN ( SELECT aps.id_product, concat( aps.warehouse + 100000, asa.quantity + 100000 ) as warehousequantity FROM ps_product_shop aps INNER JOIN ps_stock_available asa ON aps.id_product = asa.id_product ) ws WHERE ps_product_shop.id_product = ws.id_product ORDER BY warehousequantity DESC
- I've added SELECT * FROM ps_product_shop to the beginning
- I've replaced p.id_product with ps_product_shop.id_product in WHERE clause
- I've added ORDER BY warehousequantity DESC to the end
And it produces the correct results. I must be doing something wrong in MySQL.php then.