How to Develop an Automatic Sales Hits Block in 1C-Bitrix

Our *Automatic calculation is 10 times more accurate than manual* and 3 times faster. The automatic sales hits block for 1C-Bitrix uses a *weighted formula* to calculate hits based on real sales, ensuring the top sales items are always displayed. Estimated savings: a manager's time reduction of 10 h

Our competencies:

Frequently Asked Questions

Our Automatic calculation is 10 times more accurate than manual and 3 times faster. The automatic sales hits block for 1C-Bitrix uses a weighted formula to calculate hits based on real sales, ensuring the top sales items are always displayed. Estimated savings: a manager's time reduction of 10 hours per week equals ~$200/week in salary costs, paying back the investment in 2 months. Using our automated system, hit relevance is 70% more accurate than simple sales count sorting. With the standard manual approach, for 500+ items, duplicates, forgotten marks, and outdated data occur—an item that is no longer sold still appears as a hit.

We solve this problem: we develop a flexible system that calculates hits based on order data, takes into account popularity within categories, and allows combining automation with manual control. We work turnkey, with warranty and documentation. We will assess your project within one day.

Automatic calculation requires no daily attention from managers. You get a block that updates itself based on objective data.

Criteria Manual marking Automatic calculation
Accuracy Subjective, errors Objective, 0 errors
Update speed 1-2 days Once a day
Scalability Up to 300 products Any quantity

On one project with a catalog of 2000 products, manual hit updates took 3 hours per day. After implementing automation, the time dropped to 15 minutes, and conversion in the hits block increased by 12%. Manual work costs decreased by 10 hours per week.

How does automatic calculation work?

SQL query for collecting statistics

Hits are determined by real sales from the b_sale_basket and b_sale_order tables. Additionally, page views can be considered with less weight. For objectivity, the number of unique orders is used rather than the total quantity—otherwise one wholesale order of 100 units would outweigh 50 retail orders.

-- Top selling products over 30 days SELECT b.product_id, SUM(b.quantity) AS total_qty, COUNT(DISTINCT b.order_id) AS total_orders, SUM(b.price * b.quantity) AS total_revenue FROM b_sale_basket b JOIN b_sale_order o ON b.order_id = o.id WHERE o.canceled = 'N' AND o.date_insert >= DATE_SUB(NOW(), INTERVAL 30 DAY) AND b.product_id IS NOT NULL GROUP BY b.product_id ORDER BY total_orders DESC, total_qty DESC LIMIT 100; 

Ranking by total_orders (number of orders), not by total_qty—so one order of 100 units does not lift a product above 50 different orders of 1 unit.

Weighted calculation formula

For more accurate ranking, we use a formula with multiple factors: number of orders (weight 0.5), revenue (0.3), and views (0.2). Additionally, we account for sales recency—a product bought in the last 7 days gets a 1.2 boost. This better reflects current popularity rather than historical.

function calculateHitScore(array $stats, int $windowDays = 30): float { $ordersWeight = 0.5; $revenueWeight = 0.3; $viewsWeight = 0.2; $normOrders = $stats['total_orders'] / ($stats['max_orders'] ?: 1); $normRevenue = $stats['total_revenue'] / ($stats['max_revenue'] ?: 1); $normViews = $stats['total_views'] / ($stats['max_views'] ?: 1); $recencyBoost = 1.0; if ($stats['last_sale_days_ago'] <= 7) { $recencyBoost = 1.2; } elseif ($stats['last_sale_days_ago'] <= 14) { $recencyBoost = 1.1; } return ($normOrders * $ordersWeight + $normRevenue * $revenueWeight + $normViews * $viewsWeight) * $recencyBoost; } 

Example calculation: a product has 10 orders (max 50), revenue 5000 (max 20000), 100 views (max 500). Without freshness, the sum of three components gives 0.215. If the sale was 3 days ago—boost 1.2 raises the total to 0.258.

Hits table and recalculation agent

Calculation results are stored in a separate table:

CREATE TABLE custom_hits ( product_id INT NOT NULL PRIMARY KEY, score FLOAT NOT NULL, total_orders INT DEFAULT 0, total_qty INT DEFAULT 0, total_revenue DECIMAL(12,2) DEFAULT 0, category_rank INT, is_hit TINYINT DEFAULT 1, calculated_at DATETIME DEFAULT NOW(), INDEX idx_score (score DESC), INDEX idx_category_rank (category_rank) ); 

The agent runs once a day and recalculates all records:

function RecalcHitsAgent(): string { $connection = \Bitrix\Main\Application::getConnection(); $connection->truncateTable('custom_hits'); $data = calcSalesStats(30); $max = getMaxValues($data); foreach ($data as $productId => $stats) { $stats = array_merge($stats, $max); $score = calculateHitScore($stats); $connection->add('custom_hits', [ 'product_id' => $productId, 'score' => $score, 'total_orders' => $stats['total_orders'], 'total_qty' => $stats['total_qty'], 'total_revenue' => $stats['total_revenue'], 'is_hit' => $score > 0.1 ? 1 : 0, 'calculated_at' => new \Bitrix\Main\Type\DateTime(), ]); } updateCategoryRanks(); return 'RecalcHitsAgent();'; } 

Official 1C-Bitrix documentation on agents recommends using agents for background tasks—we follow this practice.

Component with caching

To display hits on the page, we use a custom component with tagged cache:

// company:catalog.hits — component.php $cacheKey = "hits_{$arParams['SECTION_ID']}_{$arParams['LIMIT']}"; $cache = \Bitrix\Main\Data\Cache::createInstance(); if ($cache->initCache(3600 * 6, $cacheKey, '/catalog/hits')) { $arResult = $cache->getVars(); } elseif ($cache->startDataCache()) { $arResult = getCategoryHits( (int)$arParams['SECTION_ID'], (int)$arParams['LIMIT'], (int)$arParams['EXCLUDE_ID'] ); $cache->endDataCache($arResult); } 

6-hour cache is optimal—hits data is updated once a day.

Category hits and manual management

In addition to the overall rating, we implement hits by catalog sections. On the product page, a block shows "Hits in this category." This uses the rank within the section, recalculated by the agent. We also add the ability for manual marking: a manager goes to the product card and sets a flag Editorial Hit. Such products are always shown first in the block—convenient for promotional new items.

Display of the "Hit" badge

In the card or listing template, we check for a hit via the custom_hits table or the EDITORIAL_HIT property. If the product is a hit—the label is displayed. Changes only affect templates; the core is not modified.

What's included in the work

  • Full source code of the module with comments
  • Documentation on configuring the weighted formula and agent
  • Setting up access rights for manual marking
  • Training managers on working with editorial hits
  • 1-month warranty on support and improvements

Implementation process and typical mistakes

Step-by-step implementation plan

  1. Order analysis — write an SQL script to collect statistics for 30 days.
  2. Create table — custom_hits with indexes.
  3. Weighted formula — adjust weights to business logic.
  4. Recalculation agent — register the background task.
  5. Component — develop for main page, catalog, and product card.
  6. Manual marking — add property to the infoblock.
  7. Badges — integrate into templates.
  8. Testing — verify correctness on real data.
Typical mistakes when developing hits
  • Using total quantity instead of number of orders—distorts ranking.
  • Not accounting for canceled orders—inflates popularity.
  • Recausing agent too often—database load.
  • Forgetting caching—page speed drop.

We take all these nuances into account, based on our Bitrix development experience and more than 30 completed catalog projects. With over 5 years of experience in 1C-Bitrix development, we ensure a reliable solution. Contact us for a preliminary analysis of your data—we will assess the project within one day.

Timeline

Stage Duration
SQL calculation + hits table 1–2 days
Recalculation agent + weighted formula 2–3 days
Component (general + category) 2–3 days
Manual marking in admin section 1–2 days
Badges on cards and in listings 1 day
Testing 1–2 days

Total: from 1 to 1.5 weeks. Cost is calculated individually starting from $1,500—contact us, we will assess your project in 1 day. The investment typically pays for itself within 2 months through saved manual work.

Order a consultation on implementing the hits block in your project. Get a quote today.