Configuring Predictive Sales Analytics in 1C-Bitrix
Predictive sales analytics — forecast of future sales based on historical data. For online store this answers questions: how many units of product X will sell next month, when to expect sales peak, which products to purchase in advance. In Bitrix, historical data exists — need to build processing pipeline.
Forecast data
From Bitrix all needed time series are available:
- Sales by day:
b_sale_order_basketJOINb_sale_ordergrouped byDATE_INSERT::date - Product views:
b_catalog_viewed_productbyDATE_VISIT::date - Cart additions:
b_sale_basketbyDATE_INSERT::date - Conversion: ratio of orders to views by periods
Basic query for sales time series by product:
SELECT
DATE(o.DATE_INSERT) AS sale_date,
SUM(ob.QUANTITY) AS qty_sold,
SUM(ob.PRICE * ob.QUANTITY) AS revenue
FROM b_sale_order_basket ob
JOIN b_sale_order o ON o.ID = ob.ORDER_ID AND o.CANCELED = 'N'
WHERE ob.PRODUCT_ID = :product_id
AND o.DATE_INSERT >= NOW() - INTERVAL '365 days'
GROUP BY DATE(o.DATE_INSERT)
ORDER BY sale_date;
Simple forecasting methods without ML
Moving Average — forecast for next period = average sales over last N weeks of similar period. Implemented in pure SQL.
Seasonal smoothing — multiply base forecast by seasonal coefficient. Coefficient is ratio of sales in specific month to average monthly for year based on historical data.
Linear trend — if sales grow 5% each month, extrapolate trend. Trend coefficient: regression via least squares method on historical sample.
These algorithms are implemented in PHP without external libraries — enough to work with data arrays from DB.
Storing forecasts
Create bl_sales_forecast table:
| Field | Type | Description |
|---|---|---|
product_id |
INT | Product ID |
forecast_date |
DATE | Forecast date |
predicted_qty |
FLOAT | Predicted quantity |
predicted_revenue |
FLOAT | Predicted revenue |
confidence_low |
FLOAT | Confidence interval lower bound |
confidence_high |
FLOAT | Confidence interval upper bound |
method |
VARCHAR | Forecasting method |
created_at |
TIMESTAMP | Calculation date |
Agent recalculates forecasts weekly for next 4–8 weeks for all active products.
Forecast dashboard in admin
In "Shop → Analytics" section add forecasts page. Component reads bl_sales_forecast and displays:
- Plan/fact chart for selected product for last 3 months
- Top 20 products with highest predicted demand for next week
- Products where predicted demand exceeds current stock — signal to purchase
Chart built via Chart.js or ApexCharts, data loaded via AJAX from AdminForecastController.
Integration with inventory management
When forecast shows that in 2 weeks 50 units needed, but only 10 in stock — purchase recommendation created. Agent compares bl_sales_forecast.predicted_qty with b_catalog_store_product.AMOUNT and writes recommendations to bl_reorder_suggestions — same table used in auto-order service.
What we configure
- SQL queries for building sales time series from
b_sale_order_basket - Forecasting algorithms (moving average + seasonal coefficients) in PHP class
SalesForecastEngine - Weekly forecast recalculation agent with write to
bl_sales_forecast - Admin dashboard with plan/fact chart
- Integration of forecasts with inventory management module via
bl_reorder_suggestions







