Bitrix API

OrderDealSynchronizer uses FlowTrait

Synchronizer of the products of the order and the deal.

Synchronization works only in the CRM mode without orders and occurs only if the products of the deal or the order are changed.

Mechanics of products synchronization:

  1. when adding a product to a deal, a new basket item is added to the order, the received item is linked to the crm product row: the XML_ID fields are filled in b_sale_basket and in b_crm_product_row;
  2. when editing a product in a deal (price, quantity, discount, the product itself, variation, etc.), if the product is already in the order (checked by XML_ID), then the basket item is updated. Otherwise, a new basket item is added;
  3. when the product is removed from the deal the linked basket item is deleted. If there is no position, then nothing is deleted.
Tags
see
BasketXmlId
see
ProductRowXmlId

Before changing the products of the deal, the possibility of such actions in the order is checked (verifyDealProducts method). There is no such check in the opposite direction.

Places where the synchronizer is called:

  1. The events of saving the products of the deal: OnBeforeCrmDealProductRowsSave and OnAfterCrmDealProductRowsSave;
  2. After saving the crm order: Bitrix\Crm\Order\Order::onAfterSave;
  3. when saving a deal from a component, if inventory accounting elements are used: crm/install/components/bitrix/crm.deal.details/ajax.php

For example create deal and update products by order:

$order = \Bitrix\Crm\Order\Order::load($orderId);

$synchronizer = new \Bitrix\Crm\Order\OrderDealSynchronizer;
$synchronizer->createDealFromOrder($order);
$synchronizer->updateDealFromOrder($order);

For example create and update order products by deal:

$synchronizer = new \Bitrix\Crm\Order\OrderDealSynchronizer;
$synchronizer->createOrderFromDeal($dealId);
$synchronizer->updateOrderFromDeal($dealId);

Table of Contents

Methods

__construct()  : mixed
createDealFromOrder()  : void
Create deal from order.
createOrderFromDeal()  : void
Create order from deal.
syncOrderReservesFromDeal()  : void
Update order reserves from reservations result of deal.
updateDealFromOrder()  : void
Update deal products from order.
updateOrderFromDeal()  : void
Update order from deal.
verifyDealProducts()  : Result
Checking the list of products of the deal, whether they can be saved in the order.

Methods

__construct()

public __construct([bool|null $isSupportSync = null ]) : mixed
Parameters
$isSupportSync : bool|null = null

if sets null - init automatically.

createDealFromOrder()

Create deal from order.

public createDealFromOrder(Order $order) : void

Don't create new deal if order already binded to deal.

Parameters
$order : Order

createOrderFromDeal()

Create order from deal.

public createOrderFromDeal(int $dealId) : void

If the deal is already binded to the order, a new order will not be created and synchronization will not be performed.

Parameters
$dealId : int

syncOrderReservesFromDeal()

Update order reserves from reservations result of deal.

public syncOrderReservesFromDeal(int $dealId, ReservationResult $result[, bool $beforeSyncProducts = false ]) : void

If the order not exists, creates it.

Parameters
$dealId : int
$result : ReservationResult
$beforeSyncProducts : bool = false

updateDealFromOrder()

Update deal products from order.

public updateDealFromOrder(Order $order) : void

A deal is not created if the order is not binded to the deal at the time of synchronization.

Parameters
$order : Order

updateOrderFromDeal()

Update order from deal.

public updateOrderFromDeal(int $dealId) : void

If the deal is not binded to the order, a new order will not be created and synchronization will not be performed.

Parameters
$dealId : int

verifyDealProducts()

Checking the list of products of the deal, whether they can be saved in the order.

public verifyDealProducts(int $dealId, array<string|int, mixed> $dealProducts) : Result
Parameters
$dealId : int
$dealProducts : array<string|int, mixed>
Return values
Result

        
On this page

Search results