We develop an efficient custom countdown timer for promotions in 1C-Bitrix that boosts conversion by 15–25%. A typical scenario: on a product card with a limited discount, you need to show the remaining time until the promotion ends. Bitrix's built-in discount mechanism sets a validity period, but a visual front-end countdown requires separate implementation via components and JavaScript. In one project, we integrated a timer for 250 products on a listing — without batch mode, the page took 15 seconds to load. After optimization — 0.3 seconds. This approach saves up to 40% of loading time. A properly implemented timer increases conversion due to the urgency effect and psychological pressure of limited product availability. We apply a comprehensive approach to server-client synchronization, performance optimization, and integration with the Bitrix system.
Data Source: Where to Get the End Date
The timer must show the actual promotion period, not decorative numbers. In Bitrix, promotion dates are stored in several places:
-
Catalog discounts — table
b_catalog_discount, fields ACTIVE_FROM and ACTIVE_TO. Retrieved via \Bitrix\Catalog\DiscountTable::getList() with filter ACTIVE = Y and ACTIVE_TO > NOW().
-
Basket rules — table
b_sale_discount, similar fields. API: \Bitrix\Sale\Internals\DiscountTable::getList().
-
Product property — you can create an infoblock property
PROMO_END_DATE of type "Date/Time" and fill it manually or automatically when a product is linked to a promotion.
In practice, we recommend combining all approaches: for simple discounts on one or two products in the catalog, use a product property; for systemic basket rules, use the b_sale_discount table. This ensures full flexibility and simplifies promotion management for administrators.
Choosing the source depends on your usage scenario and data structure. If the timer is displayed on a product card, a product property or catalog discount is convenient. If the timer is global (a banner on the main page), use a basket rule or a separate promotion infoblock.
Component Architecture
We create a custom component local:sale.countdown in /local/components/local/sale.countdown/ with full caching support. The standard structure:
-
class.php — data selection logic.
-
templates/.default/template.php — HTML markup.
-
templates/.default/script.js — JavaScript countdown logic.
-
.parameters.php — configurable component parameters.
Component parameters:
| Parameter |
Type |
Description |
| SOURCE_TYPE |
list |
Source: catalog_discount, sale_discount, iblock_property |
| DISCOUNT_ID |
int |
Discount ID (for catalog/sale) |
| IBLOCK_ID |
int |
Infoblock ID (for product property) |
| ELEMENT_ID |
int |
Element ID (for product property) |
| PROPERTY_CODE |
string |
Property code with end date |
| DISPLAY_FORMAT |
list |
Format: days+hours+minutes+seconds or hours+minutes+seconds |
| ACTION_ON_EXPIRE |
list |
Action on expiry: hide / show message |
| CACHE_TIME |
int |
Caching time |
In class.php, the component retrieves the end date from the selected source and passes a timestamp to the template:
$this->arResult['TIMESTAMP_END'] = (new \Bitrix\Main\Type\DateTime($endDate))->getTimestamp();
Why the Timer Must Be Tied to Real Discounts?
If the date is hardcoded in the template, the timer won't update when the promotion changes in the admin panel. The component dynamically queries ACTIVE_TO from the database, uses tagged cache, and resets when the discount is modified via event handlers. A synchronization error can cost up to 100,000 rubles in lost profit due to an incorrect promotion.
How to Synchronize Time on Client and Server?
Client clocks may differ from server clocks — this is critical for a timer. Solution: the server passes not only TIMESTAMP_END, but also TIMESTAMP_SERVER — the current server time. JavaScript calculates the delta and adjusts the countdown:
const serverNow = parseInt(container.dataset.serverTime);
const clientNow = Math.floor(Date.now() / 1000);
const drift = serverNow - clientNow;
const remaining = endTime - (Math.floor(Date.now() / 1000) + drift);
Updating the DOM every second via setInterval works. But for multiple timers on a page (a product listing with promotions), a single requestAnimationFrame loop that updates all timers in one pass is better. Practical advice: the drift often reaches 5-7 seconds on weak computers, so always apply correction, even if the server and client are usually synchronized.
Action on expiry. When remaining <= 0, the timer should not just stop. Options: hide the promotion block, replace the "Buy with discount" button with a normal one, display a "Promotion ended" message. For button change — an AJAX request to the server to check the discount's validity and re-render the price block.
Integration with Composite Cache
Bitrix's composite cache (autocomposite) caches the entire HTML page. A timer with a server timestamp in the HTML breaks the cache: each hit becomes unique.
Solution — place the timer block in a dynamic area. In template.php:
$frame = new \Bitrix\Main\Page\Frame('countdown_' . $this->arParams['DISCOUNT_ID']);
$frame->begin();
// Timer HTML
$frame->end();
Inside the dynamic area, the HTML updates on each request, while the rest of the page is served from cache.
Alternative — don't output the timestamp in HTML at all. Instead, store it in a separate endpoint (/ajax/countdown.php) that JavaScript requests once on page load. The page is fully cached; timer data is loaded separately.
Example discount cache reset handler
\Bitrix\Main\EventManager::getInstance()->addEventHandler(
'catalog',
'OnAfterCatalogDiscountUpdate',
function ($discountId) {
\Bitrix\Main\Data\Cache::clearCacheByTag('catalog_discount_' . $discountId);
}
);
This code clears the tagged cache when a discount is modified, ensuring the timer is always up-to-date.
How Does Batch Mode Work for Product Listings?
A separate task is to display timers on a catalog page with 20-50 products. Each may have its own promotion with a different deadline. The component is called inside a catalog.section loop — this results in multiple SQL queries.
Optimization: implement batch mode in class.php. The component accepts an array ELEMENT_IDS, retrieves all dates in one query, and returns an array of timestamps. In the catalog.section template — one call instead of N. Testing showed that for 50 products, the fetch time drops from 0.5 seconds to 0.01 seconds.
What's Included in the Work
- Analysis of timer usage scenarios and selection of date source.
- Development of the component with tagged cache and composite compatibility.
- Configuration of synchronization with discount rules (agents and event handlers).
- Integration into templates (product card, listing, global blocks).
- Load testing (up to 50 products with timers on one page).
- Documentation and source code delivery.
Implementation Timelines
| Option |
Scope |
Timeline |
| Simple timer |
One component, one discount, static endpoint |
from 3 to 4 days |
| Full solution |
Batch mode, composite compatibility, synchronization with rules, auto cache reset |
from 7 to 10 days |
Cost is calculated individually. Consult with our engineers — they will evaluate your project and choose the optimal solution. Contact us to get a timer that works reliably, doesn't break the cache, and is synchronized with promotions.
1C-Bitrix Module Development and Setup
The main trap of Bitrix is init.php. You add an OnBeforeIBlockElementUpdate handler there, then another one — a year later the file is 2000 lines, and on every hit all that code executes. We move business logic into full-fledged modules with D7 ORM, custom tables, and administrative interface. The module can be disabled, transferred to another project, covered with tests — none of that is possible with init.php. Our team has 10+ years of Bitrix experience, certified specialists, and a 6-month code guarantee. Request a consultation — we'll explain how to migrate legacy code to a modular architecture.
Why is init.php the worst place for business logic?
Init.php does not support class autoloading, lacks an isolated namespace, cannot be unit tested, and cannot be disabled without editing the file itself. Every handler written there runs on every request, even if not needed. In a module, you register handlers through EventManager, and they only execute when the event occurs. Performance difference: up to 3x with 10+ handlers.
Standard Modules: Typical Problems and Solutions
Information blocks. IBlock architecture is the first thing we review on any project. A classic mistake: one catalog infoblock with 80 properties, 30 of which are multiple. The b_iblock_element_property table swells to millions of rows, and CIBlockElement::GetList with filtering on three properties does a full scan. We move reference data to Highload-blocks, eliminate multiple properties where possible, and design the structure for 5x growth.
e-Store (sale). Cart business rules are a separate story. We set discount priorities to prevent two campaigns from giving 60% instead of 30%, connect payment handlers, and write custom validation via OnSaleOrderBeforeSaved.
Search. The built-in search module with morphology works up to 10–15 thousand elements. Beyond that — Elasticsearch. We configure it via the Bitrix search module API, indexing through CSearchFullText or custom indexers.
Highload-blocks for dictionaries, logs, user data — instead of bloated IBlocks. Direct queries via Bitrix\Highloadblock\HighloadBlockTable, custom tables instead of the EAV structure of standard infoblocks. A million records — no degradation.
Mail events. Configuration is not just templates in b_event_message. The key is SPF, DKIM, DMARC on the DNS, otherwise transactional emails go to spam. We check deliverability and set up bounce handling.
How to Design Infoblocks for Performance?
We use Highload-blocks for reference data (colors, sizes, manufacturers) that are not involved in complex queries. For SKUs — a separate infoblock with linking via IBLOCK_ELEMENT_PROPERTY. Enable INDEX_PROPERTY for frequently filtered properties. Tagged caching: when an element changes, only the related cache is cleared. Highload-blocks process up to 10x faster than infoblocks with multiple properties on volumes of 100,000 records.
Custom Module Development
Each module follows the structure /local/modules/vendor.modulename/:
-
install/index.php — setup class, create tables via $DB->RunSQLBatch()
-
lib/ — D7 ORM classes, extending Bitrix\Main\ORM\Data\DataManager
-
admin/ — administrative pages using CAdminList, CAdminForm
-
include.php — autoloading, event handler registration via EventManager::getInstance()->registerEventHandler()
- REST API endpoints via
\Bitrix\Rest\RestManager
The module registers in the system, appears in the "Installed Solutions" list, and has its own settings at /bitrix/admin/settings.php?mid=vendor.modulename. It can be enabled, disabled, and updated through UpdateSystem or custom migration mechanics.
Examples of implemented tasks:
- Campaign management — visual condition builder via
CAdminCalendar, timers via agents (CAgent::AddAgent), analytics linked to the sale module
- Cost calculator — React widget on the frontend, REST API in the module, formulas stored in a Highload-block
- Booking system — real-time calendar, locking via
$DB->StartTransaction() / $DB->Commit() on concurrent requests, integration with channel manager via webhook
Components and Composite Cache
Component customization via result_modifier.php and component_epilog.php, not by editing template.php of the standard template. This way core updates are painless.
Composite cache ("Composite Site" technology) — the server sends ready HTML, bypassing PHP routing. Dynamic areas (cart, authorization) are loaded via CBitrixComponent::setFrameMode(true) and AJAX. TTFB drops to 30–50 ms. But there are caveats: not all components are compatible, $APPLICATION->ShowPanel() breaks composite, and careful markup of <div id="bx-composite-..."> is required.
What to Check Before Installing a Marketplace Module?
Before installing a module from the marketplace, an audit is mandatory. We check: SQL queries without prepared statements (hello SQL injection), direct use of $_REQUEST without filtering, use of outdated kernel API instead of D7, conflicts with the composite cache module. A module with no updates for over a year and a few dozen installations is likely a problem on the next PHP update. A typical case: a module calls CIBlockElement::GetList with no cache reset — the site crashes with 5000 elements.
Migration to D7
When upgrading PHP or switching to a new edition — refactor outdated calls:
-
CIBlockElement::GetList() → Bitrix\Iblock\Elements\ElementTable::getList()
-
CSaleOrder::GetList() → Bitrix\Sale\Order::getList()
-
CModule::IncludeModule() → Bitrix\Main\Loader::includeModule()
Testing on staging, rollback via git on issues.
According to official 1C-Bitrix documentation, D7 ORM is the recommended tool for working with data, providing type safety and automatic query generation.
Comparison: Init.php vs Module
| Criterion |
Init.php |
Module with D7 ORM |
| Performance |
Executes on every hit |
Executes only on event |
| Testability |
No autoloading, tests impossible |
Full PHPUnit support |
| Maintainability |
Codebase grows uncontrollably |
Isolated structure, versioning |
| Migrations |
None |
Custom tables, managed via install |
| Caching |
Does not support auto-invalidation |
Tagged caching, event-based clearing |
Module Development Scope and Cost
What is included in module development?
- Technical specification and architectural plan
- Code following PSR-4 and Bitrix code style
- Unit tests (PHPUnit) for business logic
- Integration tests for events and REST API
- Installation, configuration, and API documentation
- Repository and documentation access
- Administrator training for module usage
- 6-month warranty support
Estimated timelines and complexity:
| Complexity |
Examples |
Timeline |
| Simple |
Callback widget, banner system, simple calculator |
3–5 days |
| Medium |
Booking system, product configurator, review module with moderation |
1–2 weeks |
| Complex |
Multi-regionality, custom loyalty program, ERP integration |
2–4 weeks |
| Enterprise |
Marketplace platform, complex business processes with multiple roles |
1–3 months |
Cost is calculated individually — contact us for a project estimate.
Module Testing
Unit tests via PHPUnit cover business logic: discount calculation, validation, document generation. Mocks for Bitrix\Main\Application::getConnection() allow tests to be DB-independent. Integration tests verify event handlers on a real database — OnAfterIBlockElementAdd, OnSaleOrderSaved, etc. REST API endpoints are tested via curl or PHPUnit HTTP client. Critical for modules working with b_sale_order, b_catalog_price — where errors cost money.
Compatibility is checked on PHP 7.4, 8.0, 8.1, 8.2 and editions: Standard, Small Business, Business. We check conflicts with popular marketplace modules — they often intercept the same events. Load testing: measurements on 10K, 100K, 1M records, profiling via Xdebug for memory leaks and N+1 queries.
Practical Examples
Campaign module for an electronics chain. The built-in sale module discounts did not cover scenarios like "2+1", a gift with purchase over a certain amount, or combined conditions. We built a visual builder: marketers create rules via drag-and-drop without development tickets. Campaign calendar, auto-deactivation via agents, analytics linked to b_sale_order — conversion, average check, usage count. Time to launch a new campaign dropped from two days to half an hour.
Calculator for builders. Parameters (area, materials, number of floors) → formula → preliminary estimate → lead to CRM via CRest::call('crm.lead.add'). Regional coefficients and seasonal markups from a Highload-block, material prices from 1C exchange. The number of target leads increased by a third: clients see a breakdown before calling a manager.
Booking for a hotel chain. Real-time availability via AJAX requests to a custom table vendor_booking_slots, seasonal tariff calculation, synchronization with Booking.com via channel manager API. Room locking on concurrent booking via SELECT ... FOR UPDATE in transactions. Timezones handled via \DateTimeZone — a guest from Vladivostok and a manager from Moscow see the same picture.
We will evaluate your project within one day. Write to us — we'll tell you what is included in turnkey development. Contact us for a consultation on your project. Order a custom module development — get a ready solution with documentation and support.