Configuring Order Submission from a Site to Bitrix24 CRM
An order is placed on the site — it does not appear in CRM. Managers process orders in the site's admin panel without seeing the customer's communication history, tasks, or calls from Bitrix24. The two systems can be connected via the OnSaleOrderSaved event and the REST API.
What Gets Transferred to CRM
When an order is created on the site, the following are created in Bitrix24:
-
Contact (
crm.contact.add) — from the buyer's data: name, phone, email. -
Deal (
crm.deal.add) — with the order total, status, and link to the contact. -
Product line items (
crm.deal.productrows.set) — list of products, quantities, and prices.
If the buyer is a legal entity, a Company (crm.company.add) is also created and linked to the deal via COMPANY_ID.
Order Event Handler
// In init.php or a module handler
AddEventHandler('sale', 'OnSaleOrderSaved', 'onOrderSavedHandler');
function onOrderSavedHandler($order) {
$isNew = $order->isNew();
if (!$isNew) return; // process new orders only
$orderId = $order->getId();
$orderProps = $order->getPropertyCollection();
$basket = $order->getBasket();
// Collect buyer data from order properties
$name = $orderProps->getItemByOrderPropertyCode('NAME')->getValue();
$phone = $orderProps->getItemByOrderPropertyCode('PHONE')->getValue();
$email = $orderProps->getItemByOrderPropertyCode('EMAIL')->getValue();
// Submit to B24
$b24 = new B24Integration();
$contactId = $b24->findOrCreateContact($phone, $email, $name);
$dealId = $b24->createDeal($orderId, $order->getPrice(), $contactId);
$b24->setDealProducts($dealId, $basket);
}
Mapping Order Statuses to Deal Stages
Statuses from b_sale_status (site table) must be mapped to Bitrix24 pipeline stages. Pipeline stages are retrieved via crm.dealcategory.stage.list:
| Order status | Status code | B24 deal stage |
|---|---|---|
| New | N | NEW |
| Confirmed | P | PREPARATION |
| Paid | A | EXECUTING |
| Shipped | D | FINAL_INVOICE |
| Completed | F | WON |
| Cancelled | C | LOSE |
When the order status changes on the site, call crm.deal.update with the new stage. Store the Bitrix24 deal ID in the order property B24_DEAL_ID or in b_sale_order_props_value.
Storing the Order–Deal Link
// Save the deal ID in the order properties
$dealProp = $orderProps->getItemByOrderPropertyCode('B24_DEAL_ID');
if ($dealProp) {
$dealProp->setValue($dealId);
$order->save();
}
Product Line Items
crm.deal.productrows.set replaces the entire list of deal line items. Each item:
$products[] = [
'PRODUCT_NAME' => $basketItem->getField('NAME'),
'PRICE' => $basketItem->getPrice(),
'QUANTITY' => $basketItem->getQuantity(),
'CURRENCY_ID' => 'USD',
'PRODUCT_ID' => 0, // 0 if there is no catalog in B24
];
If Bitrix24 has a product catalog synchronized with the site, pass the actual PRODUCT_ID for correct product-level analytics.
Repeat Orders from the Same Customer
For a repeat order from the same customer, check for an existing contact via crm.duplicate.findByComm by phone. If the contact exists — use its ID and do not create a duplicate. The new deal is linked to the existing contact.
Basic setup for new order submission — 6–8 hours. Full two-way status synchronization — 2–3 working days.







