Working via register
This approach helps avoiding mistakes in naming a required method when handling online store entities in Bitrix24 editions with Online Store and CRM features.
Note: when using standard online store classes in such combinations of Bitrix24 editions, some CRM-only specific operational errors can occur (for example, when working with automation rules).
\Bitrix\Main\Loader::includeModule('sale'); $registry = \Bitrix\Sale\Registry::getInstance( \Bitrix\Sale\Registry::REGISTRY_TYPE_ORDER ); $orderClassName = $registry->getOrderClassName(); $order = $orderClassName::load(...);
The main point to the described method:
- Loading the module sale and getting a register object.
A map is initialized describing which classes are responsible for the specified Online Store entity when loading the object. CRM uploads its own classes into this map, getting it up-to-date for the Bitrix24 edition with CRM.
- Now, you don't need to directly work with class name, but request it from the register instead, using the method type getOrderClassName. It returns the correct class name.
- As the result, the variable
$orderClassName
is used instead of directly indicated class. This variable contains a correct class name and you can continue working as usual with the needed order's methods, such as load($id).
For the rest of online store entities, methods for getting a correct class are similar (for example, to handle a payment, call getPaymentClassName() instead of getOrderClassName()).