why prestashop doesn't show correct sku quantity in product list?
PrestaShop often displays incorrect total stock quantities in the product list due to orphaned records in the ps_stock_available table from deleted or recreated product combinations.
This bug persists across versions like 1.7.x to 8.1.x, where deleting/re-adding combinations leaves behind id_product_attribute rows with non-zero quantities that aren't cleaned up
Common Causes
-
Combination lifecycle issues: Deleting a combination (e.g., to temporarily hide it) doesn't remove its stock record; re-adding creates a new ID, leaving the old one with stock (like a returned order adding to the ghost entry).
-
Order cancellations: Returns restore stock to the original (now-invalid) combination ID, inflating the product list total without updating visible combinations.
-
No auto-recalculation: Product list pulls a cached or summed total from the database without filtering invalid combos.
Prevention
Enable advanced stock management or avoid deleting/recreating combinations—instead, set inactive combos to 0 stock and hide them. For bulk fixes, third-party tools like Store Manager can regenerate totals. Update to the latest PrestaShop if possible, though the core issue remains open.
Or set the qty to 0 before deleting the combination.
fix with sql command in database
** Backup the database first **
1/. Get the product id first
SELECT id_product, reference FROM ps_product WHERE reference LIKE '%RC-JST001%';
2/. Get the id_product_attribute
SELECT sa.id_product_attribute, sa.quantity, pc.id_product_attribute as active_combo
FROM ps_stock_available sa
LEFT JOIN ps_product_attribute_combination pac ON sa.id_product_attribute = pac.id_product_attribute
LEFT JOIN ps_product_attribute pa ON pac.id_product_attribute = pa.id_product_attribute
WHERE sa.id_product = [YOUR_PRODUCT_ID]
AND sa.id_shop = 1
AND sa.id_product_attribute > 0
AND pa.id_product_attribute IS NULL;
3/. Delete Orphan product attribute
DELETE FROM ps_stock_available
WHERE id_product = [YOUR_PRODUCT_ID]
AND id_product_attribute = [ORPHAN_ID]
AND id_shop = 1;
4/. Recalculate Parent Total
UPDATE ps_stock_available
SET quantity = (
SELECT COALESCE(SUM(sa2.quantity), 0)
FROM ps_stock_available sa2
INNER JOIN ps_product_attribute pa ON sa2.id_product_attribute = pa.id_product_attribute
WHERE sa2.id_product = [YOUR_PRODUCT_ID]
AND sa2.id_product_attribute > 0
AND sa2.id_shop = 1
)
WHERE id_product = [YOUR_PRODUCT_ID]
AND id_product_attribute = 0
AND id_shop = 1;