Pavol Rašev
Available for remote contracts from December
Blog

One stock for the shop and the website: syncing PrestaShop with the till, and invoicing it all

Pick one system that owns the stock, send every web order to it the moment it is paid, and compare both stock lists before you switch anything on. In the store I connected, the till was supposed to be the source of truth, and when I compared the two, 1,136 of 2,176 items disagreed. The code was the easy part.

One stock for the shop and the website The till in the shop owns the stock and sends stock levels to the online store. Paid web orders go back to the till as stock deductions. The till issues receipts for shop sales, the store issues invoices for web orders. Before the sync, only 84 of 2,176 items had matching stock in both systems. One stock, shop and website Who owns what when a till and an online store sell from one shelf Till in the shop Dotykačka POS owns the stock Online store PrestaShop 9 owns texts and photos stock levels paid web orders, as stock deductions Receipts shop sales, eKasa Invoices web orders, QR, e-invoice Stock matched before sync 84 / 2,176 items, compare before you switch on pavolrasev.com

On 28 September I placed a test order on the staging copy of Vlnkovo, a yarn shop in Šamorín, Slovakia, that sells online and over the counter. At 12:41 the order showed up in the shop’s till as a stock deduction: one black bag-making mesh, minus one piece. The sync worked. It also meant my test had just taken a real item out of the owner’s live stock, and somebody had to put it back by hand.

The same afternoon I compared the stock of every paired item in both systems. Of 2,176 items, 84 matched. 1,136 did not. Safety eyes, 10 mm: 12 in the online store, −44 in the till.

This article is about that gap. The integration code took weeks. Getting two systems to agree on what is actually on the shelf is the part nobody writes about.

The till, the store, and who owns the stock

The till is Dotykačka, a Czech cloud point-of-sale system you see in a lot of Czech and Slovak shops and cafés. It runs on a tablet at the counter, keeps products and stock in the cloud, and has a REST API (Dotypos API v2) with webhooks. The online store is PrestaShop 9.1. In Slovakia, every sale at the counter also has to go through eKasa, the tax authority’s online cash register system, so shop sales get their receipt at the counter, not from the website.

When two systems sell from one shelf, one of them has to own the stock. Otherwise you get two numbers and an argument. For Vlnkovo the plan was:

What Owned by Direction
Stock levels the till till → store
Web orders the store store → till, as a stock deduction
Product descriptions, photos, categories the store stays in the store
Invoices for web orders the store issued in PrestaShop
Receipts for shop sales the counter (eKasa) issued at the counter

I chose the till as the owner because that is where stock physically changes most often: deliveries arrive in the shop, and most sales happen at the counter. The module I wrote, pr_dotypos, never pushes product data into the till on its own. A product edited carelessly in the website should not overwrite what the shop staff see at the counter.

That decision was right on paper. The comparison on 28 September showed why it could not be switched on yet: the shop had been selling through the till for a long time without receiving deliveries into it. Most items had drifted below zero. If I had turned on “till → store”, the website would have shown nearly the whole catalogue as sold out on launch day.

So the order of steps changed. First the owner does a stock-take in the till (or we load the website’s current stock into it, which the module can do through Dotykačka’s stockups operation; I used it on 5 August for 163 items). Only then does the till become the owner for real.

How the sync works

Stock comes from the till. Dotykačka sends a webhook when stock moves (STOCKLOG) or a product changes (PRODUCT). A webhook can be lost, though, so a scheduled job also asks for everything changed since the last run, filtered by the API’s versionDate. Webhooks give speed, polling gives a safety net. In Vlnkovo the job gets its schedule at launch, together with the till → store direction. The last poll I ran processed 151 products with 3 errors, all logged.

One detail I like: a stock webhook carries the change (“minus 2”), and it is tempting to apply it. I don’t. On every event the module asks the till for the full current quantity of that product and writes it. If an event goes missing, the next one fixes the number instead of building on a wrong one.

Web orders go the other way. Dotykačka’s API does not let an outside system create a till order, so a paid web order goes in as a warehouse sale: POST /warehouses/:id/sales with the products and quantities. When that happens depends on how the customer pays, and the shop chooses it per payment method in the settings. In Vlnkovo, bank transfer and paying in the shop on pickup go across straight away, so the item is held the moment the order exists. A card payment through the payment gateway waits until the payment is confirmed, so an abandoned card payment does not take stock out of the shop.

The sales endpoint has no protection against duplicates. Send the same order twice and the till deducts it twice. The module keeps its own record of every order it has sent and refuses to send a sent order again, whichever hook fires.

Products are paired by ID, stored in a mapping table, never by name. I hoped EAN barcodes would help with the first pairing. They mostly didn’t: the till had an EAN on 853 of 2,289 items, and 1,407 paired items had no EAN in either system. A script filled the 9 that were missing in the store.

The API taught me a few things the hard way. Registering a stock webhook without a warehouse ID fails with _warehouseId cannot be null when payloadEntity is STOCKLOG. The unit for a piece is Piece, and PIECE is rejected. And the till holds items the website must never see, like the coffee sold at the counter, so a full import from the till has to filter them out.

Invoices: two systems, two kinds of document

People often ask for “one invoicing for everything”. In practice there are two documents, and that is fine as long as each comes from one place.

Shop sales get an eKasa receipt at the counter. Web orders get an invoice from the store, generated by a second module, pr_invoice:

  • The invoice is a frozen copy of the order at the moment it is issued. If the order is edited later, the invoice does not quietly change.
  • Each document type has its own number series that restarts every year. By default: invoices 2026000001, credit notes D2026000001, delivery notes DL2026000001. The counter is a single atomic database update, so two orders paid at the same second cannot get the same number. Order numbers are a separate series again (202600008 was the test order).
  • Every invoice carries a PAY by square QR code, the Slovak banking standard that pre-fills the transfer in any banking app. It needs the bank’s SWIFT/BIC filled in by hand, because the bundled list does not know every Slovak bank.
  • A returned order gets a credit note pointing to the original invoice. Today that is a full credit note only; partial ones are on the list.
  • Business customers will get the invoice as a structured e-invoice from 1 January 2027, when Slovakia’s mandate starts. I wrote about that part in EU e-invoicing for PrestaShop.

One rule from the Slovak e-invoicing FAQ matters for shops with a till: a simplified invoice from eKasa up to €400 is exempt from e-invoicing (example 66 in the FAQ). That covers the counter. The store’s invoices are separate documents and follow the normal rules.

What I would not do is let both systems issue invoices for the same sale. The common trap is click and collect: a customer orders online, pays at the counter, and the cashier scans the items again. Now the stock is deducted twice and there are two documents for one sale.

My test order from 28 September was exactly this case: pickup in the shop, pay at the counter. It reached the till as a stock deduction the moment it was placed. So by the time the customer comes to pay, the items are already out of the till’s stock, and taking the payment must not deduct them a second time.

Before you connect your till: a checklist

  1. Name the owner of each piece of data. Stock, prices, product texts, barcodes. One owner each, written down.
  2. Compare the stock first. Export both lists and count matches, differences and negative numbers. If the owner’s numbers are wrong, fix them with a stock-take before the sync starts copying them.
  3. Pair products by ID. Names change and barcodes are often missing. Check how many items have a barcode in both systems before you rely on it.
  4. Decide when a web order leaves the stock. At order time for bank transfer, after payment for cards. Write down what happens to an order that is never paid.
  5. Use webhooks and polling together, and on each event read the full quantity instead of adding up changes.
  6. Make sending idempotent. Your side must remember what it sent, because the till may not.
  7. Plan cancellations and returns. In Vlnkovo a cancelled web order is not yet returned to the till automatically; staff do it by hand. Know who does it in your shop.
  8. Agree on click and collect with the people at the counter, so the sale is not scanned twice.
  9. Keep till-only items out of the website: coffee, gift wrapping, services.
  10. Give every document type its own number series, and make sure only one system issues each one.
  11. Test on staging, but remember the till is live. Every test order there takes real stock. Return each one, or use a separate test warehouse if your POS has one.

I’m still waiting for the stock-take in the shop before the till takes over. I honestly don’t know how long counting more than two thousand items takes in a yarn shop, and I expect the first week after the switch to show me something I missed.

If you sell in a shop and online and the two numbers keep disagreeing, have a look at how I build online stores and send me what you use today. I’ll tell you which system should own the stock, and what to fix before connecting them.

Sources