Last Modified: 09.06.2022
System mechanisms allow customizing and adding your own delivery services. In this aspect, e-store in core D7 such services are represented by classes. Subsequently, you can use inheritance mechanism. To create your own delivery service you have to create a class - descendant of the base class \Bitrix\Sale\Delivery\Services\Base .
Example of inheriting for delivery services:
class SimpleHandler extends \Bitrix\Sale\Delivery\Services\Base
protected static $isCalculatePriceImmediately = true;
protected static $whetherAdminExtraServiceShow = true;
* @param array $initParams
* @throws \Bitrix\Main\ArgumentTypeException
public function __construct(array $initParams)
System will search for handler in the following directories:
self::$handlersDirectories = array(
'LOCAL' = > '/local/php_interface/include/sale_delivery',
'CUSTOM' = > '/bitrix/php_interface/include/sale_delivery',
'SYSTEM' = > '/bitrix/modules/sale/handlers/delivery'
You can limit the use of delivery service by specific parameters. For example, by limit by maximum weight or size.
Apply standard restrictions for this purpose. When you need something specific, create your own types of restrictions.
Additionally, you can use the the event onSaleDeliveryServiceCalculate available for delivery services that can modify delivery price calculation (i. e. you can increase delivery price per 100 units):
function myCalc(\Bitrix\Main\Event $event)
/** @var Delivery\CalculationResult $baseResult */
$baseResult = $event->getParameter('RESULT');
$shipment = $event->getParameter('SHIPMENT');
$price = $baseResult->getDeliveryPrice() + 100;
EventResult::SUCCESS, array('RESULT' => $baseResult)
Important! You need to consider that the site can have both both UTF-8 and CP-1251 encodings. When data exchange is performed with a delivery service, you need to correctly modify the encoding when sending and receiving data. The following method will be helpful for this purpose: \Bitrix\Main\Text\Encoding::convertEncoding().
: you can find more details on handling delivery services REST in a
This section overviews delivery service REST principles:
- Delivery service handler settings;
- Delivery service settings;
- Additional service setup for delivery service;
- Handling shipment properties;
- Standard scenario for delivery services REST: handling delivery in sales center.
Starting point for manager can be payment feature ("Accept
payment in deal") or creating a delivery activity.
Examples of delivery services
Take a look at the delivery service examples below:
- \Sale\Handlers\Delivery\SimpleHandler (
/bitrix/modules/sale/handlers/delivery/simple/handler.php) - simplest example of handlers.
- \Sale\Handlers\Delivery\SpsrHandler (
/bitrix/modules/sale/handlers/delivery/spsr/handler.php) - a little more complex variant with all features of current architecture fully employed.
There is an available mechanism of automatic tracking of dispatch IDs (tracking number) (i. e., as implemented for delivery service Spsr: \Sale\Handlers\Delivery\SpsrTracking).
It's recommended to use an integrated class \Bitrix\Main\Web\HttpClient for querying delivery services instead of third-party extensions. Optimal exchange format - json, due to the option of integrated class \Bitrix\Main\Web\Json.
Often, during data exchange with delivery services, you must send locations IDs. Matching online store location IDs with delivery service IDs - is a non-trivial task. For example, you can use \Sale\Handlers\Delivery\Spsr\Location::mapStepless().
To void creating redundant queries to delivery service, slowing down site operation, it's preferable to cache information, received from delivery services. However, you have to do it accurately to prevent undesirable side effects. Use \Sale\Handlers\Delivery\Spsr\Cache.
In case of errors, it's recommended to maintain a debugging log with records of events, associated with received information from delivery services. For this purpose, use the class \CEventLog.