Keeping stock levels in sync between online shop and ERP
Overselling and phantom stock rarely come from a single bug. Usually three questions have been left open: which system owns the stock figure, which number is transferred, and what happens to orders placed between two syncs?
What you will learn
What matters
A stock sync is reliable once three things are settled. One system owns the stock figure; the other only displays it. What is transferred is available stock, not on-hand stock. And orders placed between the moment a stock snapshot is taken and the moment it reaches the shop are deducted rather than overwritten. On top of that come checks that report a discrepancy before a customer finds it.
Two terms first. Overselling means the shop sells more than can actually be delivered. Phantom stock is stock that one system shows but the warehouse does not hold. Both often share a cause: two systems that disagree about the current state.
One system owns it, the other displays it
In most businesses the ERP (enterprise resource planning) or inventory management system owns the stock figure. That is where goods receipts are posted, stocktakes recorded, returns inspected and deliveries booked out. The shop, on the other hand, owns orders: it is the first to know that a customer has bought something.
This gives a clear division. Only the ERP books physical movements; the shop reports orders and cancellations to it. If someone changes a stock figure by hand in the shop, the next sync overwrites it – rightly so. Why this decision has to come before any connection is shown by the example in Connecting Excel, e-mail and business software.
If you sell through several channels, such as your shop and a marketplace, the system of record has to be the one where orders from all channels meet. Otherwise every channel sells the same last item.
Which number is actually transferred?
“Stock” often means different things in conversation. For a sync they must be kept apart:
| Term | Meaning | Who knows it |
|---|---|---|
| On-hand stock | What is physically on the shelf. | ERP |
| Reserved | Ordered but not yet shipped. | The ERP for orders it knows about, the shop for orders not yet transferred |
| Safety stock | A quantity deliberately not sold online, for example for a physical store or breakage. | A business decision |
| Available stock | On-hand stock minus reservations minus safety stock. | The result of a calculation both sides need |
Delta or full sync
In a full sync the ERP sends the current figure for every product. In a delta sync it sends only changes, such as “product 4711: plus twelve from goods receipt”. Each has a typical weakness:
In our assessment, the combination works best: changes flow as deltas during the day, and a full sync during a quiet hour resets the figures and reports every discrepancy it corrects. Those reports are valuable – they show where the delta route has gaps. So that a change delivered twice is not booked twice, each one needs a unique identifier; see Preventing duplicate processing. Whether the transfer runs by file or API is a separate decision: CSV import or API integration.
The gap between snapshot and arrival
Every stock snapshot has a point in time. Between the moment the ERP calculates it and the moment the shop applies it, time passes – seconds with an API, half an hour with a nightly export. Orders placed in that gap are unknown to the snapshot. If the shop overwrites its figure with it, they are forgotten.
Three measures close the gap:
Conflicts still occur, for instance when a return counts as refunded in the shop but has not yet been inspected in the warehouse. The rule from the first section decides: stock rises only when the ERP books the goods back in. Where such steps run with a delay in the background, Background jobs and queues helps.
A hypothetical example
Three oversold orders on Monday morning
A retailer syncs every night at 2 am. The ERP produces its stock export at 1.30 am; shop orders are transferred every hour on the hour. On Sunday evening a promotion is running. Between 1 am and 2 am orders arrive that are neither in the 1.30 export nor transferred by then. At 2 am the sync overwrites the shop figure with the older, higher number. On Monday morning there are three orders for an item that is no longer there.
The fix does not rebuild anything from scratch. The order export runs immediately before the stock export, the stock export carries its timestamp, and the shop deducts later orders when applying it. The nightly full sync stays – but it now reports which products it corrected.
Control totals and monitoring
A sync that silently goes wrong is worse than one that fails loudly. These checks make discrepancies visible:
Each of these checks needs a recipient: a person who reads the alert and knows what to do. How to log errors so that they get noticed is covered in Error handling and logging.
Checklist before building
- Decide which system owns on-hand stock and which owns orders.
- Write down the formula for available stock: which reservations, which safety stock.
- Establish what the stock field in the shop system means.
- Delta, full sync or both – and at what intervals.
- Fix the order of order and stock transfers and how timestamps are handled.
- Name the checks and who receives the alerts.
One example of capture with handheld scanners and storage assignment in retail is our mobile data capture project. We build connections between shop and ERP as part of our API integration work, and for Shopware also through Shopware development.
Common misconceptions
Further sources
- Shopware Documentation – Stock Manipulation API (ADR) meaning of the stock and availableStock fields
- Shopware Documentation – Stock stock handling on order, cancellation and refund
About the author
Fabian Lücker is managing partner of PHP Schmiede KG in Rheine and has worked in software development since 2007. He is responsible for development and design, and writes here about decisions that come up in real projects.
Stock figures that do not match?
Describe how stock and orders currently move between your shop and your ERP. We will show where the gap is and how it can be closed.