How to forecast demand and stock inside PrestaShop, without external services
Knowing what to buy and when is one of the decisions that moves the most money in an online shop, and PrestaShop doesn't help: it stores orders and stock, but forecasts nothing. The usual answers are spreadsheets or external platforms with monthly fees. We wanted the forecast inside the shop, with the merchant's own data and no fees. That is how Demand Forecast was born.
Why it isn't trivial
- History is misleading. A sold-out product sells zero, but not because nobody wants it. Without discounting out-of-stock days, the forecast underestimates precisely the best sellers.
- Every product behaves differently. A daily best seller, a spare part sold once a month and a new product without history can't be forecast with the same method.
- Seasons and campaigns overlap. December rises because of the season and also because of Christmas; separating both effects avoids counting them twice.
- It has to run on any hosting. No external libraries, PHP 7.1 to 8.5 and PrestaShop 1.6 to 9, with shops of thousands of products and years of orders.
The approach: a small, honest statistical engine
We chose classic, well understood methods that can be explained to the merchant, instead of a black box. Each product and combination gets the method that best fits its data:
- Damped trend (Holt) for products with regular sales.
- Croston SBA for intermittent demand, products that sell in bursts.
- Own monthly seasonality, but only if it beats the plain forecast in a test on the product's own data; otherwise it inherits its category's.
- Category or similar product for new items, blended with the first weeks of real sales.
Technical decisions
Campaigns that aren't counted twice
The effect of each campaign (Black Friday, sales, Mother's Day) is measured in previous years against the weeks before, keeping only what the season doesn't explain. It also requires enough volume: with four scattered sales, a rise is noise, not a campaign.
From forecast to order date
The forecast becomes what the merchant needs: cover in days, run-out date, safety stock by service level and order-by date given each supplier's lead time. That builds the purchase list per supplier, rounded to the pack size and net of stock already on the way.
Batched work
The first load may read three years of orders. The scheduled task works in batches of under a minute and resumes where it left off, so it never blocks the server or hits hosting time limits.
Repeat customers inside the forecast
The same history detects each customer's repurchase rhythm. Those expected purchases are added to demand, and the module can remind customers just before they run out, with consent and one-click unsubscribe.
Tested against real and simulated data
The engine has unit tests without PrestaShop and integration tests on the four main versions, with demo data reproducing Christmas and summer peaks, sporadic products and new items. Reviewing them, we found and fixed edge cases such as campaigns inflating the forecast in low season.
What we learnt
A good forecast depends less on a sophisticated algorithm than on cleaning the data well, choosing the method per product and stating clearly how far the merchant can trust each figure. It is the same approach we bring to the reports, ERP integrations and automations we build to measure.
What this development demonstrates
- Time series forecasting models in dependency-free PHP
- Data cleaning: out-of-stock days, abnormal orders and exclusions
- Reorder point, safety stock and purchase list calculation
- Long batched processes that work on any hosting
- Repeat purchases and GDPR-compliant consent e-mails
- Compatibility from PrestaShop 1.6 to 9 and multistore