PrestaShop stock not adding up: why it does not match and how to fix it

PrestaShop stock not adding up

If the stock in your PrestaShop does not match what is in the warehouse, it is almost never a PrestaShop bug. It is that PrestaShop keeps three different stock figures for every product, and someone, a person, an import or the ERP, is writing to the wrong one, or with the wrong method. The result is products that sell with no stock, or products sitting on your shelf that the shop shows as out of stock.

Below you have what each figure means, how to find the products that do not add up with a query, why they drift and how to fix it without making it worse.

The three stock figures

For every product, and every combination, PrestaShop stores three quantities (stock in PrestaShop 8):

Figure What it is Where you see it
Available What is left to sell. It is the one the customer sees The product page and the stock list
Physical What is really on the shelf The list in Catalog > Stock
Reserved What has been sold but has not left the warehouse yet The same list. It cannot be edited by hand

Normally physical = available + reserved. And this is what happens with an order, according to the PrestaShop documentation:

Moment Available Physical Reserved
Product created with 50 units 50 50 0
The customer adds 3 to the cart 50 50 0
Order created, payment pending 47 50 3
Payment accepted 47 50 3
Order shipped or delivered 47 47 0

Two things surprise almost everyone: the cart reserves nothing, and physical stock does not drop when the order is paid, but when it is shipped. If you compare the warehouse count with the available figure, you will always be short by the units of orders still waiting to go out.

Available, physical and reserved stock in PrestaShop over the course of an order
The cart reserves nothing and physical stock drops on shipping, not on payment.

How to find which products do not add up

In Advanced Parameters > Database > SQL Manager, create a query with this. Replace ps_ with your table prefix if it is different (you can see it in the manager itself, in the list of tables), and en with your shop’s main language:

SELECT sa.id_product, sa.id_product_attribute, pl.name,
 sa.quantity AS available, sa.physical_quantity AS physical,
 sa.reserved_quantity AS reserved
FROM ps_stock_available sa
JOIN ps_product_lang pl ON pl.id_product = sa.id_product
 AND pl.id_lang = (SELECT id_lang FROM ps_lang WHERE iso_code = 'en')
WHERE sa.physical_quantity <> sa.quantity + sa.reserved_quantity
 OR sa.quantity < 0
ORDER BY sa.quantity ASC

It returns the products whose three figures do not match each other and those with negative available stock. If id_product_attribute is not 0, the mismatch is in a specific combination (a size, a colour), not in the product.

Which orders are holding reserved stock

And this one tells you which orders older than a month are still holding stock. It uses the same rule PrestaShop uses to calculate the reservation: unshipped orders that are still valid or that are not in error or cancelled, and the quantity ordered minus the quantity refunded (StockManager, PrestaShop 8.2):

SELECT o.id_order, o.date_add, osl.name AS status,
 SUM(od.product_quantity - od.product_quantity_refunded) AS reserved_units
FROM ps_orders o
JOIN ps_order_detail od ON od.id_order = o.id_order
JOIN ps_order_state os ON os.id_order_state = o.current_state
JOIN ps_order_state_lang osl ON osl.id_order_state = o.current_state
 AND osl.id_lang = (SELECT id_lang FROM ps_lang WHERE iso_code = 'en')
WHERE os.shipped = 0
 AND (o.valid = 1 OR o.current_state NOT IN
 (SELECT value FROM ps_configuration WHERE name IN ('PS_OS_ERROR', 'PS_OS_CANCELED')))
 AND o.date_add < DATE_SUB(CURDATE(), INTERVAL 30 DAY)
GROUP BY o.id_order, o.date_add, osl.name
HAVING reserved_units > 0
ORDER BY o.date_add

Both queries are read-only: they change nothing. Delete them from the manager when you are done. We have tested them on a real shop running PrestaShop 8.2.

Before going on, check one thing. In Shop Parameters > Product Settings, see whether stock management is enabled. If it is disabled, PrestaShop does not track stock: the figures stay as they were and nothing below applies. And if you allow ordering out-of-stock products, negative available stock is not an error: those are units sold on backorder.

Why it drifts

Six reasons why PrestaShop stock does not add up
Hardly any of them is a PrestaShop bug: it is how stock gets written.

1. The quantity is edited on the product page while orders are coming in. PrestaShop’s own documentation gives the example: you open the product page showing 47 units, a sale comes in while you have it open, you save 50 because new stock has arrived, and the sale has been wiped from stock. By saving an absolute figure you overwrite whatever happened in between (stock in PrestaShop 8).

2. The ERP, the supplier or an import writes the whole figure. It is the same problem, at scale. If every night a file arrives saying “there are 20” and 3 were sold between the warehouse snapshot and the import, the shop offers 20 again. And if it also writes the physical or reserved figures directly to the database, it is worse: PrestaShop treats them as read-only and recalculates them.

3. Forgotten orders in a status that reserves stock. Bank transfers that were never paid, test orders, paid orders that were never marked as shipped. Until they are shipped or cancelled, their stock stays reserved: the product is on your shelf and the shop counts it as sold (stock in PrestaShop 8).

And one that almost nobody knows: the “Refunded” status does not release the reservation. PrestaShop subtracts what has been refunded, but it counts as refunded what is recorded with a refund inside the order, not the status change (StockManager, PrestaShop 8.2). If you returned the money through the payment gateway and only changed the status to “Refunded”, for PrestaShop those units are still set aside.

Combinations, packs and multistore

4. Combinations. Each combination has its own stock. If the inventory is kept by product and the shop by size, it will never add up.

5. Packs. PrestaShop lets selling a pack deduct the pack, the products in it or both, in Shop Parameters > Product Settings. If it is set to “both” and the pack also has its own stock, you deduct twice.

6. Multistore. With several shops, stock can belong to each one or be shared by group. If one shop sells from a shared warehouse with its own stock, each one deducts its own and none of them adds up.

How to fix it

First of all, back up the database. Stock is fixed with small changes, but if something goes wrong you need to be able to go back to where you started.

Cancel the orders that are not going out

With the second query in front of you, go through the old orders one by one. Those that will not be paid or shipped, move to Canceled: their stock stops counting as reserved. Those that left the warehouse and nobody marked, move to Shipped. And for refunded ones, record the refund inside the order, not just the status. Do not delete any: a cancelled order leaves a record of what happened, a deleted one does not.

Adjust stock with movements, not with the whole figure

In Catalog > Stock you adjust by adding or subtracting units, not by typing the total. Each adjustment is kept in the movement history with the date, the employee and the reason (stock in PrestaShop 8). If 10 units arrive, add 10. Do not type 57.

Adjusting PrestaShop stock with movements instead of typing the total
Typing the total wipes out the sales in between. Adding a movement does not.

Fix the sync with the ERP or the supplier

Have it send changes (10 in, 3 out) instead of the total, or, if it can only send the total, have the warehouse snapshot and the import happen at the same moment and at times with no orders. And it should never write to the physical and reserved figures: only to the available one.

Review the pack and combination settings

A single way of deducting packs, and inventory kept at the same level as the shop: if you sell by size, you count by size.

Do a stock count and correct it with movements

With all of the above done, a physical count of the products from the first query, and the difference adjusted as a movement. Then run the query again: it should come back empty or nearly empty.

What changes when it adds up

What stops happening when PrestaShop stock adds up
Fewer sales with no stock, fewer false out-of-stocks and stock alerts you can trust.

You stop selling what you do not have, which is the worst call a shop can get: refunding the money and apologising. And you stop showing products as out of stock while they sit on the shelf, which is a lost sale nobody sees. When the available figure can be trusted, you can switch on low stock alerts and stop counting by hand.

What breaks if you get it wrong

  • Editing the stock tables directly in the database. PrestaShop calculates the physical and reserved figures. If you change them by hand, they get recalculated and your change disappears, or it stays and throws everything else off.
  • Deleting orders to free up stock. You lose the history and the invoicing. They are cancelled.
  • Correcting by typing the total on the product page while the shop is selling. That is exactly how it drifted.
  • Fixing the stock without fixing the import. Tonight the ERP writes over it again.
  • Allowing out-of-stock orders “so as not to lose sales” without telling the customer. If you sell on backorder, the product page should say so.

If the mismatch started after importing products or combinations, the problem may be in the import: we cover it in importing products into PrestaShop without duplicates (in Spanish).

When you cannot do this yourself

The queries, cancelling old orders and adjusting with movements you can do yourself from the back office. What needs someone technical is the connection with the ERP or the supplier: making it send changes instead of totals, at the right time and without touching the tables it should not. That is what we do in our PrestaShop integrations (in Spanish), and in maintenance we check every month that stock still adds up.

Is this happening to you right now?

Leave us the URL and what you are seeing. A technician will look at it today and tell you what it is before touching anything.

We reply within 24 working hours.

Frequently asked questions

Why does PrestaShop stock not match the real stock?

The usual causes are orders that deduct stock and never ship, adjustments made by changing the figure instead of with movements, ERP or supplier syncs that overwrite each other, and badly configured packs or combinations.

What is the difference between physical, reserved and available stock in PrestaShop?

Physical is what is in the warehouse, reserved is what is committed to orders that have not gone out yet, and available is what can be sold. Many mismatches come from mixing up these three figures.

How do I correct stock in PrestaShop without losing the history?

With stock movements that add or subtract the difference, instead of typing the final figure. That way it records what changed, when and why, and you can trace it if it drifts again.

Can the ERP throw PrestaShop stock off?

Yes, if the sync overwrites stock without accounting for the orders placed between two updates, or if both systems change the same figure. You need to decide which one is in charge and which way each piece of data flows.