Unified Online & Offline Loyalty Program Setup in Bitrix

Unified Online and Offline Loyalty Program Setup in Bitrix We've encountered this situation: a customer accumulated 500 bonuses on the website, comes to the store — the cashier doesn't see them. Or an in-store purchase doesn't accrue points on the online account. The gap between online and offlin

Our competencies:

Frequently Asked Questions

Unified Online and Offline Loyalty Program Setup in Bitrix

We've encountered this situation: a customer accumulated 500 bonuses on the website, comes to the store — the cashier doesn't see them. Or an in-store purchase doesn't accrue points on the online account. The gap between online and offline loyalty programs is not just a UX problem — it's a direct loss of repeat sales. We configure a unified loyalty system turnkey: integration of the site and cash registers, real-time bonus synchronization, full transparency for the customer.

How loyalty works in Bitrix

The sale module implements discount system through b_sale_user_discount (personal discounts) and bonus system through b_sale_discount (basket rules). A full-fledged loyalty program with accumulative points requires either a separate module or integration with an external system. Bitrix24 has a CRM module with bonuses (b_crm_loyalty_bonus_transaction), but for an online store without Bitrix24, either the marketingcrm module or a custom transaction table is more often used. Based on our experience, a custom implementation provides the greatest flexibility and reliability — you are not tied to the limitations of a typical module.

Bonus storage structure: tables and transactions

Minimum structure for a unified program:

CREATE TABLE bl_loyalty_account ( id SERIAL PRIMARY KEY, user_id INT UNIQUE, -- b_user.ID (online) card_number VARCHAR(20) UNIQUE, -- card number for offline balance NUMERIC(10,2) DEFAULT 0, created_at TIMESTAMP DEFAULT NOW() ); CREATE TABLE bl_loyalty_transaction ( id SERIAL PRIMARY KEY, account_id INT NOT NULL REFERENCES bl_loyalty_account(id), amount NUMERIC(10,2) NOT NULL, -- positive=accrual, negative=deduction type VARCHAR(20) NOT NULL, -- 'earn_online', 'earn_offline', 'spend', 'expire' order_id INT, -- b_sale_order.ID or external offline receipt ID source VARCHAR(20) NOT NULL, -- 'web', 'pos', 'mobile' created_at TIMESTAMP DEFAULT NOW() ); 

A transactional model with history is the only reliable way to store bonuses. Never update balance directly without recording a transaction. balance is either a denormalized aggregate (updated by a DB trigger) or calculated as SUM(amount) from the transaction table. The latter approach is safer but slower under frequent balance queries.

How to identify a customer at an offline cash register?

The key task: the cashier must find the customer account. Identification methods:

  • Loyalty card number (physical card or barcode in a mobile app)
  • Phone number (most common)
  • QR code with token (generated in personal account on the site)

When identifying by phone, the cash register software sends a request to the Bitrix API:

// /local/ajax/loyalty/find-account.php $phone = normalizePhone($_POST['phone']); $bitrixUser = \CUser::GetList([], ['PERSONAL_PHONE' => $phone])->Fetch(); if ($bitrixUser) { $account = getLoyaltyAccount($bitrixUser['ID']); echo json_encode(['balance' => $account['balance'], 'account_id' => $account['id']]); } 

Bonus accrual on online orders

Handler for order status change — after delivery/completion:

AddEventHandler('sale', 'OnSaleStatusOrderChange', function(\Bitrix\Main\Event $event) { $order = $event->getParameter('ENTITY'); $status = $order->getField('STATUS_ID'); if ($status !== 'F') return; // Only completed orders $userId = $order->getUserId(); $bonus = round($order->getPrice() * BONUS_RATE); // BONUS_RATE = 0.05 (5%) addLoyaltyTransaction($userId, $bonus, 'earn_online', $order->getId(), 'web'); }); 

Bonus deduction on online payment

Bonuses are applied through a basket rule or a custom payment method. A basket rule (b_sale_discount) can give a fixed amount discount. For a more flexible scheme — a custom "payment method" like "Pay with bonuses", which when the order is completed deducts a transaction from bl_loyalty_transaction.

Why transactional deduction is critically important?

An offline cash register calls three endpoints:

  1. GET /loyalty/balance?phone=... — check balance
  2. POST /loyalty/spend — deduct bonuses at sale (must be transactional: start sale → reservation → confirmation)
  3. POST /loyalty/earn — accrue bonuses after sale

Reservation during deduction is a critical step. Without it, two parallel requests from different cash registers could simultaneously read a balance of 500 bonuses and each deduct 500, going negative. Reservation via SELECT ... FOR UPDATE in PostgreSQL or through a strict UPDATE with result check:

UPDATE bl_loyalty_account SET balance = balance - :amount WHERE id = :account_id AND balance >= :amount RETURNING balance; -- If 0 rows updated — insufficient bonuses 

This approach is more reliable than using application-level locks.

Approach comparison: custom table vs Bitrix module

Criterion Custom implementation marketingcrm module Bitrix24 CRM
Flexibility Full Limited Medium
Performance High Medium Medium
Integration complexity Medium Low Low
Offline transaction support Yes Limited Yes
License cost Free Included in edition Requires Bitrix24

A custom table loses to modules in implementation speed, but is 2-3 times more reliable under high loads and non-standard business logic.

What's included in the work

  • Designing table structures bl_loyalty_account and bl_loyalty_transaction
  • Developing a REST API for cash register systems (balance, accrual, deduction)
  • Creating event handlers OnSaleStatusOrderChange for online accruals
  • Customer identification mechanism by phone/card
  • Transactional deduction with race condition protection
  • Administrative interface for viewing and canceling transactions
  • API documentation and cashier instructions
  • Testing and 30-day warranty

Timelines and budget

Setting up a unified loyalty program takes from 5 to 15 working days depending on complexity (number of cash registers, need for integration with 1C, reporting requirements). Cost is calculated individually after an audit of the current system. We'll assess your project in 1 day.

Common mistakes in setup

  • Updating balance directly without a transaction — data loss on failure.
  • Lack of locks during deduction — double deduction.
  • Ignoring API logging — difficult to debug.
  • Using only the marketingcrm module for offline — does not support reservation.

Avoiding these mistakes requires experience — we have implemented over 30 loyalty projects on Bitrix, including chains with 50+ cash registers.

Contact us for a consultation: we'll tell you how to unite online and offline loyalty in your business.