Bitrix-D7  20.0.0
Класс Manager

Открытые статические члены

static getById ($deliveryId)
 Returns service field, caches results during hit. Подробнее...
 
static getRestrictedObjectsList (Shipment $shipment, $restrictionMode=Restrictions\Manager::MODE_CLIENT)
 
static isServiceExist ($deliveryId)
 
static getActiveList ($calculatingOnly=false, $restrictedIds=null)
 Prepares and caches data during the hit. Подробнее...
 
static getRestrictedList (Shipment $shipment=null, $restrictionMode, array $skipChecks=array())
 
static createObject (array $srvParams)
 
static getPooledObject (array $fields)
 
static getObjectById ($deliveryId)
 
static getObjectByCode ($serviceCode)
 
static getHandlersList ()
 
static calculateDeliveryPrice (Shipment $shipment, $deliveryId=0, $extraServices=array())
 Calculates the price of the shipment. Подробнее...
 
static getGroupId ($name)
 Returns id of delivery service group. Подробнее...
 
static getByParentId ($parentId)
 
static getLocationConnectorEntityName ()
 Returns entity link name for connection with Locations. Подробнее...
 
static add (array $fields)
 Adds delivery service. Подробнее...
 
static generateXmlId ()
 
static update ($id, array $fields)
 Updates delivery service. Подробнее...
 
static delete ($id)
 Deletes delivery service. Подробнее...
 
static onGetBusinessValueConsumers ()
 
static onGetBusinessValueGroups ()
 
static setChildrenFieldsValues ($id, array $fields)
 Sets fields values to all children. Подробнее...
 
static getIdByCode ($code)
 
static getCodeById ($id)
 
static checkServiceUsage ($deliveryId)
 Returns if delivery service and it's children are used in shipments. Подробнее...
 
static getEmptyDeliveryServiceId ()
 
static checkServiceRestriction ($deliveryId, $checkParams, $restrictionClassName)
 
static isDeliveryServiceClassValid ($class)
 Check if given class is valid delivery service class inheritance of Bitrix\Sale\Delivery\Services\Base. Подробнее...
 
static calculate (Shipment $shipment)
 
static getRestrictionObject ($className)
 
static checkServiceRestrictions ($deliveryId, Shipment $shipment, $restrictionsClassesToSkip=array())
 
static getServicesForShipment (Shipment $shipment)
 
static isExistService ($deliveryId)
 
static getActive ()
 
static getServicesBriefsForShipment (Shipment $shipment=null, array $skipChecks=array(), $getAll=false)
 
static createServiceObject (array $srvParams)
 
static getService ($deliveryId)
 
static getServiceByCode ($serviceCode)
 
static getHandlersClassNames ()
 
static getRestrictionClassNames ()
 
static getRestrictionsByDeliveryId ($deliveryId)
 

Поля данных

const SKIP_PROFILE_PARENT_CHECK = 0
 
const SKIP_CHILDREN_PARENT_CHECK = 1
 

Защищенные статические члены

static initHandlers ()
 Gets info about existing delivery services handlers Stores this information during the hit. Подробнее...
 
static getHandlersClasses ()
 
static getIdCodeCached ($value, $type)
 
static setIdCodeCached ($id, $code)
 Saves relation between Id an code of delivery service. Подробнее...
 
static cleanIdCodeCached ($id)
 Cleans cache of delivery service id-code relation. Подробнее...
 
static isDeliveryInShipments ($deliveryId)
 Returns is delivery service is already used in shipments. Подробнее...
 
static deleteRelatedEntities ($deliveryId)
 Deletes related entities. Подробнее...
 

Статические защищенные данные

static $handlers = null
 
static $cachedFields = array()
 
static $handlersDirectories = array()
 
static $objectsPool = null
 

Подробное описание

См. определение в файле sale/lib/delivery/services/manager.php строка 31

Методы

◆ add()

static add ( array  $fields)
static

Adds delivery service.

Аргументы
array$fields
Возвращает
AddResult
Исключения
SystemException

См. определение в файле sale/lib/delivery/services/manager.php строка 721

722  {
723  self::initHandlers();
724  $res = \Bitrix\Sale\Delivery\Services\Table::add($fields);
725 
726  if($res->isSuccess())
727  {
728  if(!empty($fields["CLASS_NAME"]))
729  $fields["CLASS_NAME"]::onAfterAdd($res->getId(), $fields);
730 
731  if(!empty($fields['CODE']))
732  self::setIdCodeCached($res->getId(), $fields['CODE']);
733  }
734 
735  return $res;
736  }

◆ calculate()

static calculate ( Shipment  $shipment)
static
Уст.:
use \Bitrix\Sale\Delivery\Services\Manager::calculateDeliveryPrice()

См. определение в файле sale/lib/delivery/services/manager.php строка 1199

1200  {
1201  $delivery = self::getObjectById($shipment->getDeliveryId());
1202  return $delivery->calculate($shipment);
1203  }

◆ calculateDeliveryPrice()

static calculateDeliveryPrice ( Shipment  $shipment,
  $deliveryId = 0,
  $extraServices = array() 
)
static

Calculates the price of the shipment.

Аргументы
Shipment$shipment
int$deliveryIdoptional
array$extraServicesoptional
Возвращает
\Bitrix\Sale\Delivery\CalculationResult
Исключения
ArgumentNullException

См. определение в файле sale/lib/delivery/services/manager.php строка 625

626  {
627  if($deliveryId <=0)
628  $deliveryId = $shipment->getDeliveryId();
629 
630  $delivery = self::getObjectById($deliveryId);
631 
632  if($delivery)
633  {
634  $result = $delivery->calculate($shipment, $extraServices);
635  }
636  else
637  {
638  $result = new CalculationResult();
639  $result->addError(new Error("Can't create delivery service object with id: \"".$deliveryId."\""));
640  }
641 
642  return $result;
643  }

◆ checkServiceRestriction()

static checkServiceRestriction (   $deliveryId,
  $checkParams,
  $restrictionClassName 
)
static

См. определение в файле sale/lib/delivery/services/manager.php строка 1132

1133  {
1134  if(empty($deliveryId))
1135  throw new ArgumentNullException("deliveryId");
1136 
1137  if(!is_array($deliveryId))
1138  $deliveryId = array($deliveryId);
1139 
1140  $dbRstrRes = ServiceRestrictionTable::getList(array(
1141  'filter' => array(
1142  '=SERVICE_ID' => $deliveryId,
1143  '=SERVICE_TYPE' => Restrictions\Manager::SERVICE_TYPE_SHIPMENT,
1144  '=CLASS_NAME' => $restrictionClassName
1145  )
1146  ));
1147 
1148  $tmp = array();
1149  /** @var Restrictions\Base $restriction */
1150  $restriction = static::getRestrictionObject($restrictionClassName);
1151 
1152  while($rstFields = $dbRstrRes->fetch())
1153  {
1154  $rstParams = is_array($rstFields["PARAMS"]) ? $rstFields["PARAMS"] : array();
1155  $tmp[$rstFields['SERVICE_ID']] = $restriction->check($checkParams, $rstParams, $rstFields['SERVICE_ID']);
1156  }
1157 
1158  if(count($deliveryId) == 1)
1159  return current($tmp);
1160 
1161  $result = array();
1162 
1163  foreach($deliveryId as $id)
1164  if(!isset($tmp[$id]) || (isset($tmp[$id]) && $tmp[$id] == true))
1165  $result[] = $id;
1166 
1167  return $result;
1168  }

◆ checkServiceRestrictions()

static checkServiceRestrictions (   $deliveryId,
Shipment  $shipment,
  $restrictionsClassesToSkip = array() 
)
static
Уст.:
use Restrictions\Manager::checkService()

См. определение в файле sale/lib/delivery/services/manager.php строка 1230

1231  {
1232  return Restrictions\Manager::checkService($deliveryId, $shipment) == Restrictions\Manager::SEVERITY_NONE;
1233  }

◆ checkServiceUsage()

static checkServiceUsage (   $deliveryId)
static

Returns if delivery service and it's children are used in shipments.

Аргументы
$deliveryId
Возвращает
Result
Исключения

См. определение в файле sale/lib/delivery/services/manager.php строка 1049

1050  {
1051  $result = new Result();
1052 
1053  if(self::isDeliveryInShipments($deliveryId))
1054  {
1055  $result->addError(new Error(Loc::getMessage('SALE_DLVR_MNGR_ERR_DEL_IN_SHPMNTS_EXIST')));
1056  }
1057  else
1058  {
1059  $dbRes = Table::getList(array(
1060  'filter' => array(
1061  "PARENT_ID" => $deliveryId
1062  ),
1063  'select' => array("ID")
1064  ));
1065 
1066  while($child = $dbRes->fetch())
1067  {
1068  if(self::isDeliveryInShipments($child["ID"]))
1069  {
1070  $result->addError(new Error(Loc::getMessage('SALE_DLVR_MNGR_ERR_DEL_IN_SHPMNTS_EXIST_CHLD')));
1071  break;
1072  }
1073  }
1074  }
1075 
1076  return $result;
1077  }

◆ cleanIdCodeCached()

static cleanIdCodeCached (   $id)
staticprotected

Cleans cache of delivery service id-code relation.

Аргументы
int$id

См. определение в файле sale/lib/delivery/services/manager.php строка 1010

1011  {
1012  $cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache();
1013  $code = self::getIdCodeCached($id, "id");
1014  $cacheManager->clean("SALE_DELIVERY_ID_CODE_MAP_I_".$id);
1015 
1016  if(strlen($code) > 0)
1017  $cacheManager->clean("SALE_DELIVERY_ID_CODE_MAP_C_".$code);
1018  }

◆ createObject()

static createObject ( array  $srvParams)
static
Аргументы
array$srvParamsDelivery service fields from DataBase to construct service object.
Возвращает
Base|null Delivery service object All errors it writes to system log. It's better to use \Bitrix\Sale\Delivery\Services\Manager::getPooledObject for performance purposes

См. определение в файле sale/lib/delivery/services/manager.php строка 352

353  {
354  self::initHandlers();
355  $errorMsg = "";
356  $service = null;
357 
358  if(!isset($srvParams["PARENT_ID"]))
359  $srvParams["PARENT_ID"] = 0;
360 
361  if(class_exists($srvParams['CLASS_NAME']))
362  {
363  try
364  {
365  $service = new $srvParams['CLASS_NAME']($srvParams);
366  }
367  catch(SystemException $e)
368  {
369  $errorMsg = $e->getMessage();
370  }
371 
372  if($service && !($service instanceof Base))
373  $errorMsg = "Can't create delivery object. Class ".$srvParams['CLASS_NAME'].' is not the instance of Bitrix\Sale\DeliveryService';
374  }
375  else
376  {
377  $errorMsg = "Can't create delivery object. Class \"".$srvParams['CLASS_NAME']."\" does not exist.";
378  }
379 
380  if(strlen($errorMsg) > 0)
381  {
382  $eventLog = new \CEventLog;
383  $eventLog->Add(array(
384  "SEVERITY" => $eventLog::SEVERITY_ERROR,
385  "AUDIT_TYPE_ID" => "SALE_DELIVERY_CREATE_OBJECT_ERROR",
386  "MODULE_ID" => "sale",
387  "ITEM_ID" => 'createObject()',
388  "DESCRIPTION" => $errorMsg." Fields: ".serialize($srvParams),
389  ));
390 
391  return null;
392  }
393 
394  return $service;
395  }

◆ createServiceObject()

static createServiceObject ( array  $srvParams)
static
Уст.:
use \Bitrix\Sale\Delivery\Services\Manager::createObject()

См. определение в файле sale/lib/delivery/services/manager.php строка 1270

1271  {
1272  return self::createObject($srvParams);
1273  }

◆ delete()

static delete (   $id)
static

Deletes delivery service.

Аргументы
int$id
Возвращает
\Bitrix\Main\Result
Исключения
ArgumentNullException
SystemException

См. определение в файле sale/lib/delivery/services/manager.php строка 781

782  {
783  if(intval($id) <= 0)
784  throw new ArgumentNullException('id');
785 
786  $res = self::checkServiceUsage($id);
787 
788  if(!$res->isSuccess())
789  return $res;
790 
791  self::initHandlers();
792 
793  $res = Table::getList(array(
794  'filter' => array(
795  'ID' => $id
796  ),
797  'select' => array('ID', 'CLASS_NAME', 'LOGOTIP')
798  ));
799 
800  $className = '';
801  $logotip = 0;
802 
803  if($service = $res->fetch())
804  {
805  $className = $service['CLASS_NAME'];
806  $logotip = intval($service['LOGOTIP']);
807  }
808 
809  $res = \Bitrix\Sale\Delivery\Services\Table::delete($id);
810 
811  if($res->isSuccess())
812  {
813  if(!empty($className) && class_exists($className))
814  $className::onAfterDelete($id);
815 
816  self::deleteRelatedEntities($id);
817 
818  if($logotip > 0)
819  \CFile::Delete($logotip);
820  }
821 
822  return $res;
823  }

◆ deleteRelatedEntities()

static deleteRelatedEntities (   $deliveryId)
staticprotected

Deletes related entities.

Аргументы
int$deliveryId
Возвращает
bool
Исключения
ArgumentNullException

См. определение в файле sale/lib/delivery/services/manager.php строка 1087

1088  {
1090  $deliveryId = (int)$deliveryId;
1091 
1092  $con->queryExecute("DELETE FROM b_sale_service_rstr WHERE SERVICE_ID=".$deliveryId);
1093  $con->queryExecute("DELETE FROM b_sale_delivery2location WHERE DELIVERY_ID=".$deliveryId);
1094  $con->queryExecute("DELETE FROM b_sale_delivery2paysystem WHERE DELIVERY_ID=".$deliveryId);
1095  $con->queryExecute("DELETE FROM b_sale_delivery_es WHERE DELIVERY_ID=".$deliveryId);
1096 
1097  $dbRes = Table::getList(array(
1098  'filter' => array(
1099  "PARENT_ID" => $deliveryId
1100  ),
1101  'select' => array("ID")
1102  ));
1103 
1104  while($child = $dbRes->fetch())
1105  self::delete($child["ID"]);
1106 
1107  self::cleanIdCodeCached($deliveryId);
1108  return true;
1109  }

◆ generateXmlId()

static generateXmlId ( )
static
Возвращает
string

См. определение в файле sale/lib/delivery/services/manager.php строка 741

742  {
743  return uniqid('bx_');
744  }

◆ getActive()

static getActive ( )
static
Уст.:
use \Bitrix\Sale\Delivery\Services\Manager::getActiveList()

См. определение в файле sale/lib/delivery/services/manager.php строка 1254

1255  {
1256  return self::getActiveList();
1257  }

◆ getActiveList()

static getActiveList (   $calculatingOnly = false,
  $restrictedIds = null 
)
static

Prepares and caches data during the hit.

Аргументы
bool$calculatingOnlyIf we need absolutely all, or calculating items only.
array$restrictedIdsIf we have list of services ids, successful checked restrictions.
Возвращает
array Array of active delivery services fields.
Исключения

См. определение в файле sale/lib/delivery/services/manager.php строка 132

133  {
134  //If we alredy got all active services
135  static $isDataPrepared = false;
136  static $activeIds = array();
137  static $canHasProfiles = array();
138  static $canHasChildren = array();
139  static $DontHaveRestrictionsIds = array();
140 
141  if(is_array($restrictedIds))
142  {
143  $unPreparedRestrictedIds = array_diff_key(
144  array_flip(
145  $restrictedIds
146  ),
147  self::$cachedFields
148  );
149 
150  $unPreparedRestrictedIds = array_keys($unPreparedRestrictedIds);
151  }
152  else
153  {
154  $unPreparedRestrictedIds = array();
155  }
156 
157  if(!$isDataPrepared || !empty($unPreparedRestrictedIds))
158  {
159  $result = array();
160  self::initHandlers();
161 
162  $filter = array(
163  '=ACTIVE' => 'Y'
164  );
165 
166  $params = array(
167  'order' => array('SORT' =>'ASC', 'NAME' => 'ASC'),
168  'filter' => $filter
169  );
170 
171  $params['runtime'] = array(
172  new \Bitrix\Main\Entity\ExpressionField(
173  'RESTRICTIONS_EXIST',
174  'CASE WHEN EXISTS('.
175  'SELECT 1 FROM b_sale_service_rstr SSR WHERE SSR.SERVICE_ID = %s AND SSR.SERVICE_TYPE = '.Restrictions\Manager::SERVICE_TYPE_SHIPMENT.') THEN 1 ELSE 0 END',
176  'ID'
177  )
178  );
179 
180  $params['select'] = array('*', 'RESTRICTIONS_EXIST');
181 
182  if(!empty($unPreparedRestrictedIds))
183  {
184  if($isDataPrepared)
185  {
186  $params['filter']['ID'] = $unPreparedRestrictedIds;
187  }
188  else
189  {
190  $params['filter'][] = array(
191  "LOGIC" => "OR",
192  "ID" => $unPreparedRestrictedIds,
193  'RESTRICTIONS_EXIST' => 0
194  );
195  }
196  }
197 
198  $dbRes = Table::getList($params);
199  $profilesParentsIds = array();
200 
201  while($service = $dbRes->fetch())
202  {
203  if(!is_subclass_of($service["CLASS_NAME"], 'Bitrix\Sale\Delivery\Services\Base'))
204  continue;
205 
206  if(!$service['RESTRICTIONS_EXIST'])
207  $DontHaveRestrictionsIds[] = $service['ID'];
208 
209  if($service["CLASS_NAME"]::canHasChildren())
210  $canHasChildren[$service["ID"]] = true;
211 
212  if ($service['CLASS_NAME']::canHasProfiles())
213  $canHasProfiles[$service["ID"]] = true;
214 
215  if($service["PARENT_ID"] != 0)
216  $profilesParentsIds[$service["PARENT_ID"]] = $service['ID'];
217 
218  $result[$service["ID"]] = $service;
219 
220  if($service['ACTIVE'] == 'Y')
221  $activeIds[$service["ID"]] = $service["ID"];
222  }
223 
224  foreach(array_diff_key($canHasProfiles, $profilesParentsIds) as $id => $tmp)
225  unset($result[$id]);
226 
227  self::$cachedFields = self::$cachedFields + $result;
228  Restrictions\Manager::prepareData(array_keys($result));
229  ExtraServices\Manager::prepareData(array_keys($result));
230 
231  //selected all active
232  if(!$isDataPrepared && empty($unPreparedRestrictedIds))
233  $isDataPrepared = true;
234  }
235 
236  if(is_array($restrictedIds) && !empty($restrictedIds))
237  $storedIds = array_diff($restrictedIds, $unPreparedRestrictedIds);
238  else
239  $storedIds = array();
240 
241  if(!empty($storedIds) && is_array($storedIds))
242  {
243  foreach($storedIds as $storedId)
244  {
245  if(empty(self::$cachedFields[$storedId]))
246  continue;
247 
248  $service = self::$cachedFields[$storedId];
249 
250  if(!class_exists($service["CLASS_NAME"]))
251  continue;
252 
253  if($service["CLASS_NAME"]::canHasChildren())
254  $canHasChildren[$storedId] = true;
255 
256  if ($service['CLASS_NAME']::canHasProfiles())
257  $canHasProfiles[$storedId] = true;
258 
259  if($service['ACTIVE'] == 'Y')
260  $activeIds[$storedId] = $storedId;
261  }
262  }
263 
264  $active = array_intersect_key(self::$cachedFields, array_flip($activeIds));
265 
266  if(is_array($restrictedIds))
267  {
268  $result = array_intersect_key($active, array_flip($DontHaveRestrictionsIds));
269 
270  if(!empty($restrictedIds))
271  $result = $result + array_intersect_key($active, array_flip($restrictedIds));
272  }
273  else
274  {
275  $result = $active;
276  }
277 
278  /*
279  * Clean children if parent is not present in result.
280  * We mean that it doesn't pass restrictions checks.
281  * Or it is not active.
282  */
283 
284  foreach($result as $id => $fields)
285  {
286  if(intval($fields['PARENT_ID']) <= 0)
287  continue;
288 
289  if(empty($result[$fields['PARENT_ID']]))
290  unset($result[$id]);
291  }
292 
293  if($calculatingOnly)
294  $result = array_diff_key($result, $canHasChildren, $canHasProfiles);
295 
296  if(!empty($result))
297  sortByColumn($result, array("SORT" => SORT_ASC, "NAME" => SORT_ASC), '', null, true);
298 
299  return $result;
300  }

◆ getById()

static getById (   $deliveryId)
static

Returns service field, caches results during hit.

Аргументы
int$deliveryId
Возвращает
array Service fields
Исключения
SystemException

См. определение в файле sale/lib/delivery/services/manager.php строка 50

51  {
52  $id = intval($deliveryId);
53 
54  if($id <= 0)
55  throw new SystemException("deliveryId");
56 
57  if(!isset(self::$cachedFields[$deliveryId]) || !is_array(self::$cachedFields[$deliveryId]))
58  {
59  self::$cachedFields[$deliveryId] = array();
60 
61  $resSrvParams = Table::getList(array(
62  'filter' => array("=ID" => $deliveryId)
63  ));
64 
65  if($srvParams = $resSrvParams->fetch())
66  self::$cachedFields[$srvParams["ID"]] = $srvParams;
67  }
68 
69  return self::$cachedFields[$deliveryId];
70  }

◆ getByParentId()

static getByParentId (   $parentId)
static
Аргументы
int$parentIdDelivery service parent id
Возвращает
array Delivery service fields
Исключения

См. определение в файле sale/lib/delivery/services/manager.php строка 689

690  {
691  $result = array();
692  $srvList = self::getActiveList();
693 
694  foreach($srvList as $id => $srv)
695  {
696  if($srv['PARENT_ID'] == $parentId)
697  {
698  $result[$srv['ID']] = $srv;
699  }
700  }
701 
702  return $result;
703  }

◆ getCodeById()

static getCodeById (   $id)
static
Аргументы
int$id
Возвращает
string Delivery service code
Исключения

См. определение в файле sale/lib/delivery/services/manager.php строка 961

962  {
963  $result = self::getIdCodeCached($id, "id");
964 
965  if($result !== false)
966  return $result;
967 
968  $srv = self::getById($id);
969 
970  $result = $srv['CODE'];
971  self::setIdCodeCached($id, $result);
972  return $result;
973  }

◆ getEmptyDeliveryServiceId()

static getEmptyDeliveryServiceId ( )
static
Возвращает
int Empty delivery service id
Исключения
SystemException

См. определение в файле sale/lib/delivery/services/manager.php строка 1115

1116  {
1117  self::initHandlers();
1118  return \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId();
1119  }

◆ getGroupId()

static getGroupId (   $name)
static

Returns id of delivery service group.

Creates if such group does not exist.

Аргументы
string$nameGroup name
Возвращает
int Group id
Исключения
SystemException

См. определение в файле sale/lib/delivery/services/manager.php строка 653

654  {
655  $res = Table::getList( array(
656  'select' => array("ID"),
657  'filter' => array(
658  "=NAME" => $name,
659  "=CLASS_NAME" => '\Bitrix\Sale\Delivery\Services\Group'
660  )
661  ));
662 
663  if($group = $res->fetch())
664  {
665  $result = $group["ID"];
666  }
667  else
668  {
669  $res = self::add(array(
670  "NAME" => $name,
671  "CLASS_NAME" => '\Bitrix\Sale\Delivery\Services\Group',
672  "ACTIVE" => "Y"
673  ));
674 
675  if($res->isSuccess())
676  $result = $res->getId();
677  else
678  throw new SystemException(implode("<br>\n",$res->getErrorMessages()));
679  }
680 
681  return $result;
682  }

◆ getHandlersClasses()

static getHandlersClasses ( )
staticprotected
Возвращает
array Handler Classes
Исключения

См. определение в файле sale/lib/delivery/services/manager.php строка 569

570  {
571  $result = array();
572 
573  foreach(self::$handlersDirectories as $handlersDirectory)
574  {
575  $dirPath = $_SERVER['DOCUMENT_ROOT'].$handlersDirectory;
576 
577  if(!Directory::isDirectoryExists($dirPath))
578  continue;
579 
580  $dir = new Directory($_SERVER['DOCUMENT_ROOT'].$handlersDirectory);
581 
582  foreach ($dir->getChildren() as $handler)
583  {
584  if (!$handler->isDirectory())
585  continue;
586 
587  /** @var Directory $handler */
588 
589  $handlerDir = $handler->getPath();
590  $handlerPath = $handlerDir.'/handler.php';
591 
592  if(!File::isFileExists($handlerPath))
593  continue;
594 
595  $handlerClassName = ucfirst($handler->getName().'Handler');
596  $fullClassName = '\Sale\Handlers\Delivery\\'.$handlerClassName;
597  $result[$fullClassName] = $handlersDirectory.$handler->getName().'/handler.php';
598  require_once($handlerPath);
599  }
600  }
601 
602  return $result;
603  }

◆ getHandlersClassNames()

static getHandlersClassNames ( )
static
Уст.:
use \Bitrix\Sale\Delivery\Services\Manager::getHandlersList()

См. определение в файле sale/lib/delivery/services/manager.php строка 1294

1295  {
1296  return self::getHandlersList();
1297  }

◆ getHandlersList()

static getHandlersList ( )
static
Возвращает
array Known delivery services handlers
Исключения
SystemException

См. определение в файле sale/lib/delivery/services/manager.php строка 609

610  {
611  if(self::$handlers === null)
612  self::initHandlers();
613 
614  return self::$handlers;
615  }

◆ getIdByCode()

static getIdByCode (   $code)
static
Аргументы
string$code
Возвращает
int Service id

См. определение в файле sale/lib/delivery/services/manager.php строка 921

922  {
923  $result = self::getIdCodeCached($code, "code");
924 
925  if($result !== false)
926  return $result;
927 
928  foreach(self::$cachedFields as $id => $srv)
929  {
930  if($srv['CODE'] == $code)
931  {
932  $result = $id;
933  }
934  }
935 
936  if(intval($result) <= 0)
937  {
938  $res = Table::getList(array(
939  'filter' => array(
940  '=CODE' => $code
941  )
942  ));
943 
944  if($handler = $res->fetch())
945  {
946  $result = $handler["ID"];
947  self::$cachedFields[$handler["ID"]] = $handler;
948  }
949  }
950 
951  $result = intval($result);
952  self::setIdCodeCached($result, $code);
953  return $result;
954  }

◆ getIdCodeCached()

static getIdCodeCached (   $value,
  $type 
)
staticprotected
Аргументы
$value
$type
Возвращает
int|string Id or Code of delivery service

См. определение в файле sale/lib/delivery/services/manager.php строка 981

982  {
983  $result = false;
984  $ttl = 315360000;
985  $cacheId = "SALE_DELIVERY_ID_CODE_MAP_".($type == "id" ? "I" : "C")."_".$value;
986  $cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache();
987 
988  if($cacheManager->read($ttl, $cacheId))
989  $result = $cacheManager->get($cacheId);
990 
991  return $result;
992  }

◆ getLocationConnectorEntityName()

static getLocationConnectorEntityName ( )
static

Returns entity link name for connection with Locations.

Возвращает
string

См. определение в файле sale/lib/delivery/services/manager.php строка 709

710  {
711  return 'Bitrix\Sale\Delivery\DeliveryLocation';
712  }

◆ getObjectByCode()

static getObjectByCode (   $serviceCode)
static
Аргументы
string$serviceCodeDelivery service code
Возвращает
Base Delivery service object.
Исключения
ArgumentNullException
SystemException

См. определение в файле sale/lib/delivery/services/manager.php строка 431

432  {
433  if(strlen($serviceCode) <= 0 )
434  throw new ArgumentNullException("serviceCode");
435 
436  $srvParams = array();
437 
438  foreach(self::$cachedFields as $id => $srv)
439  {
440  if($srv['CODE'] == $serviceCode)
441  {
442  $srvParams = $srv;
443  }
444  }
445 
446  if(empty($srvParams))
447  {
448  $resSrvParams = Table::getList(array(
449  'filter' => array('=CODE' => $serviceCode)
450  ));
451 
452  if(!($srvParams = $resSrvParams->fetch()))
453  throw new SystemException("Can't get delivery service data with code: \"".$serviceCode."\"");
454 
455  self::$cachedFields[$srvParams['ID']] = $srvParams;
456  }
457 
458  return self::getPooledObject($srvParams);
459  }

◆ getObjectById()

static getObjectById (   $deliveryId)
static
Аргументы
int$deliveryIdDelivery service id
Возвращает
Base Delivery service object
Исключения
ArgumentNullException
SystemException

См. определение в файле sale/lib/delivery/services/manager.php строка 411

412  {
413  if(intval($deliveryId) <= 0 )
414  throw new ArgumentNullException("deliveryId");
415 
416  $srvParams = self::getById($deliveryId);
417 
418  if(empty($srvParams))
419  return null;
420 
421  return self::getPooledObject($srvParams);
422  }

◆ getPooledObject()

static getPooledObject ( array  $fields)
static

См. определение в файле sale/lib/delivery/services/manager.php строка 397

398  {
399  if(self::$objectsPool === null)
400  self::$objectsPool = new ObjectPool();
401 
402  return self::$objectsPool->getObject($fields);
403  }

◆ getRestrictedList()

static getRestrictedList ( Shipment  $shipment = null,
  $restrictionMode,
array  $skipChecks = array() 
)
static
Аргументы
Shipment$shipment
int$restrictionModeMODE_CLIENT or MODE_MANAGER from Restrictions\Manager.
array$skipChecksself::SKIP_CHILDREN_PARENT_CHECK || self::SKIP_PROFILE_PARENT_CHECK
Возвращает
array Array of active delivery services fields filtered by restrictions.

См. определение в файле sale/lib/delivery/services/manager.php строка 308

309  {
310  $result = array();
311 
312  if(empty($skipChecks))
313  {
314  $skipChecks = array(
315  self::SKIP_CHILDREN_PARENT_CHECK,
316  self::SKIP_PROFILE_PARENT_CHECK
317  );
318  }
319 
320  //Have restrictions and this restrictions successfully checked
321  $restrictedSrvIds = Restrictions\Manager::getRestrictedIds($shipment, $restrictionMode);
322  //Don't have any restrictions + successfully checked
323  $services = self::getActiveList(false, array_keys($restrictedSrvIds));
324 
325  foreach($services as $srvParams)
326  {
327  $srvParams["RESTRICTED"] = false;
328 
329  if(!in_array(self::SKIP_PROFILE_PARENT_CHECK, $skipChecks))
330  if($srvParams["CLASS_NAME"]::canHasProfiles())
331  continue;
332 
333  if(!in_array(self::SKIP_CHILDREN_PARENT_CHECK, $skipChecks))
334  if(is_callable($srvParams["CLASS_NAME"]."::canHasChildren") && $srvParams["CLASS_NAME"]::canHasChildren())
335  continue;
336 
337  if(isset($restrictedSrvIds[$srvParams["ID"]]) && $restrictedSrvIds[$srvParams["ID"]] == Restrictions\Manager::SEVERITY_SOFT)
338  $srvParams["RESTRICTED"] = true;
339 
340  $result[$srvParams["ID"]] = $srvParams;
341  }
342 
343  return $result;
344  }

◆ getRestrictedObjectsList()

static getRestrictedObjectsList ( Shipment  $shipment,
  $restrictionMode = Restrictions\Manager::MODE_CLIENT 
)
static
Аргументы
Shipment$shipment,.
int$restrictionModeMODE_CLIENT or MODE_MANAGER from Restrictions\Manager.
Возвращает
Base[] delivery services objects

См. определение в файле sale/lib/delivery/services/manager.php строка 77

78  {
79  $result = array();
80  $services = self::getRestrictedList($shipment, $restrictionMode);
81 
82  foreach($services as $srvParams)
83  {
84  if($srvParams["CLASS_NAME"]::canHasProfiles())
85  continue;
86 
87  if(is_callable($srvParams["CLASS_NAME"]."::canHasChildren") && $srvParams["CLASS_NAME"]::canHasChildren())
88  continue;
89 
90  $service = self::getPooledObject($srvParams);
91 
92  if(!$service)
93  continue;
94 
95  if(!$service->isCompatible($shipment))
96  continue;
97 
98  if($shipment->getCurrency() != $service->getCurrency())
99  {
100  $service->getExtraServices()->setOperationCurrency(
101  $shipment->getCurrency()
102  );
103  }
104 
105  $result[$srvParams["ID"]] = $service;
106  }
107 
108  return $result;
109  }

◆ getRestrictionClassNames()

static getRestrictionClassNames ( )
static
Уст.:
use Restrictions\Manager::getClassesList()

См. определение в файле sale/lib/delivery/services/manager.php строка 1302

1303  {
1304  return Restrictions\Manager::getClassesList();
1305  }

◆ getRestrictionObject()

static getRestrictionObject (   $className)
static
Уст.:
will be remove in next versions

См. определение в файле sale/lib/delivery/services/manager.php строка 1208

1209  {
1210  if(!class_exists($className))
1211  throw new SystemException("Can't find class: ".$className);
1212 
1213  static $cache = array();
1214 
1215  if(isset($cache[$className]))
1216  return $cache[$className];
1217 
1218  $restriction = new $className;
1219 
1220  if(!is_subclass_of($className, 'Bitrix\Sale\Services\Base\Restriction'))
1221  throw new SystemException('Object must be the instance of Bitrix\Sale\Services\Base\Restriction');
1222 
1223  $cache[$className] = $restriction;
1224  return $restriction;
1225  }

◆ getRestrictionsByDeliveryId()

static getRestrictionsByDeliveryId (   $deliveryId)
static
Уст.:
use Restrictions\Manager::getRestrictionsList()

См. определение в файле sale/lib/delivery/services/manager.php строка 1310

1311  {
1312  return Restrictions\Manager::getRestrictionsList($deliveryId);
1313  }

◆ getService()

static getService (   $deliveryId)
static
Уст.:
use \Bitrix\Sale\Delivery\Services\Manager::getObjectById()

См. определение в файле sale/lib/delivery/services/manager.php строка 1278

1279  {
1280  return self::getObjectById($deliveryId);
1281  }

◆ getServiceByCode()

static getServiceByCode (   $serviceCode)
static
Уст.:
use \Bitrix\Sale\Delivery\Services\Manager::getServiceByCode()

См. определение в файле sale/lib/delivery/services/manager.php строка 1286

1287  {
1288  return self::getObjectByCode($serviceCode);
1289  }

◆ getServicesBriefsForShipment()

static getServicesBriefsForShipment ( Shipment  $shipment = null,
array  $skipChecks = array(),
  $getAll = false 
)
static
Уст.:
use \Bitrix\Sale\Delivery\Services\Manager::getRestrictedList()

См. определение в файле sale/lib/delivery/services/manager.php строка 1262

1263  {
1264  return self::getRestrictedList($shipment, Restrictions\Manager::MODE_CLIENT, $skipChecks);
1265  }

◆ getServicesForShipment()

static getServicesForShipment ( Shipment  $shipment)
static
Уст.:
use \Bitrix\Sale\Delivery\Services\Manager::getRestrictedObjectsList()

См. определение в файле sale/lib/delivery/services/manager.php строка 1238

1239  {
1240  return self::getRestrictedObjectsList($shipment);
1241  }

◆ initHandlers()

static initHandlers ( )
staticprotected

Gets info about existing delivery services handlers Stores this information during the hit.

Возвращает
bool
Исключения
SystemException

См. определение в файле sale/lib/delivery/services/manager.php строка 468

469  {
470  if(self::$handlers !== null)
471  return true;
472 
473  self::$handlersDirectories = array(
474  'LOCAL' => '/local/php_interface/include/sale_delivery/',
475  'CUSTOM' => Option::get('sale', 'delivery_handles_custom_path', BX_PERSONAL_ROOT.'/php_interface/include/sale_delivery/'),
476  'SYSTEM' => '/bitrix/modules/sale/handlers/delivery/'
477  );
478 
479  $result = array(
480  '\Bitrix\Sale\Delivery\Services\Group' => 'lib/delivery/services/group.php',
481  '\Bitrix\Sale\Delivery\Services\Automatic' => 'lib/delivery/services/automatic.php',
482  '\Bitrix\Sale\Delivery\Services\Configurable' => 'lib/delivery/services/configurable.php',
483  '\Bitrix\Sale\Delivery\Services\AutomaticProfile' => 'lib/delivery/services/automatic_profile.php',
484  '\Bitrix\Sale\Delivery\Services\EmptyDeliveryService' => 'lib/delivery/services/emptydeliveryservice.php'
485  );
486 
488 
489  /*
490  * To add you own handler you must wrote smth. like this in for example init.php:
491  *
492  * function addCustomDeliveryServices()
493  * {
494  * return new \Bitrix\Main\EventResult(
495  * \Bitrix\Main\EventResult::SUCCESS,
496  * array(
497  * '\Sale\Handlers\Delivery\SimpleHandler' => '/bitrix/modules/sale/handlers/delivery/simple/handler.php'
498  * ),
499  * 'sale'
500  * );
501  * }
502  *
503  * $eventManager->addEventHandler('sale', 'onSaleDeliveryHandlersClassNamesBuildList', 'addCustomDeliveryServices');
504  */
505 
506  $event = new Event('sale', 'onSaleDeliveryHandlersClassNamesBuildList');
507  $event->send();
508  $resultList = $event->getResults();
509 
510  if (is_array($resultList) && !empty($resultList))
511  {
512  $customClasses = array();
513 
514  foreach ($resultList as $eventResult)
515  {
516  /** @var \Bitrix\Main\EventResult $eventResult*/
517  if ($eventResult->getType() != EventResult::SUCCESS)
518  continue;
519 
520  $params = $eventResult->getParameters();
521 
522  if(!empty($params) && is_array($params))
523  $customClasses = array_merge($customClasses, $params);
524  }
525 
526  if(!empty($customClasses))
527  {
528  \Bitrix\Main\Loader::registerAutoLoadClasses(null, $customClasses);
529  $result = array_merge($result, $customClasses);
530  }
531  }
532 
533  $handlers = self::getHandlersClasses();
534 
535  if(!empty($handlers))
536  {
538  $result = array_merge($result, self::getHandlersClasses());
539  }
540 
541  self::$handlers = array_keys($result);
542 
543  /**
544  * @var \Bitrix\Sale\Delivery\Services\Base $handler
545  */
546  foreach(self::$handlers as $idx => $handler)
547  {
548  if(!$handler::isHandlerCompatible())
549  {
550  unset(self::$handlers[$idx]);
551  continue;
552  }
553 
554  $profiles = $handler::getChildrenClassNames();
555 
556  if(!empty($profiles))
557  {
558  self::$handlers = array_merge(self::$handlers, $profiles);
559  }
560  }
561 
562  return true;
563  }

◆ isDeliveryInShipments()

static isDeliveryInShipments (   $deliveryId)
staticprotected

Returns is delivery service is already used in shipments.

Аргументы
$deliveryId
Возвращает
bool

См. определение в файле sale/lib/delivery/services/manager.php строка 1025

1026  {
1027  $res = ShipmentTable::getList(array(
1028  'filter' => array(
1029  "=DELIVERY_ID" => $deliveryId,
1030  "=SYSTEM" => "N"
1031  ),
1032  'select' => array("ID")
1033  ));
1034 
1035  if($res->fetch())
1036  $result = true;
1037  else
1038  $result = false;
1039 
1040  return $result;
1041  }

◆ isDeliveryServiceClassValid()

static isDeliveryServiceClassValid (   $class)
static

Check if given class is valid delivery service class inheritance of Bitrix\Sale\Delivery\Services\Base.

Аргументы
string$classChecking class.
Возвращает
bool

См. определение в файле sale/lib/delivery/services/manager.php строка 1176

1177  {
1178  if(strlen($class) <= 0)
1179  return false;
1180 
1181  self::initHandlers();
1182 
1183  if(!class_exists($class))
1184  return false;
1185 
1186  if(!is_subclass_of($class, 'Bitrix\Sale\Delivery\Services\Base'))
1187  return false;
1188 
1189  return true;
1190  }

◆ isExistService()

static isExistService (   $deliveryId)
static
Уст.:
use \Bitrix\Sale\Delivery\Services\Manager::isServiceExist()

См. определение в файле sale/lib/delivery/services/manager.php строка 1246

1247  {
1248  return self::isServiceExist($deliveryId);
1249  }

◆ isServiceExist()

static isServiceExist (   $deliveryId)
static
Аргументы
$deliveryId
Возвращает
bool is service exists or not
Исключения
SystemException

См. определение в файле sale/lib/delivery/services/manager.php строка 116

117  {
118  if(intval($deliveryId) <= 0)
119  return false;
120 
121  $srv = self::getById($deliveryId);
122  return !empty($srv);
123  }

◆ onGetBusinessValueConsumers()

static onGetBusinessValueConsumers ( )
static
Возвращает
array registerEventHandler( 'sale', 'OnGetBusinessValueConsumers', 'sale', '\Bitrix\Sale\Delivery\Services\Manager', 'onGetBusinessValueConsumers');

См. определение в файле sale/lib/delivery/services/manager.php строка 832

833  {
834  static $result = null;
835 
836  if($result !== null)
837  return $result;
838 
839  $result = array();
840  $handlers = self::getHandlersList();
841  $consumers = array();
842 
843  /** @var Base $handlerClassName */
844  foreach($handlers as $handlerClassName)
845  {
846  $tmpCons = $handlerClassName::onGetBusinessValueConsumers();
847 
848  /** @var string $handlerClassName*/
849  if(!empty($tmpCons))
850  $consumers[$handlerClassName] = $tmpCons;
851  }
852 
853  $res = Table::getList(array(
854  'filter' => array(
855  '=CLASS_NAME' => array_keys($consumers),
856  '=ACTIVE' => 'Y'
857  ),
858  'select' => array('ID', 'CLASS_NAME', 'NAME')
859  ));
860 
861  while($dlv = $res->fetch())
862  {
863  $result['DELIVERY_'.$dlv['ID']] = $consumers[$dlv['CLASS_NAME']];
864  $result['DELIVERY_'.$dlv['ID']]['NAME'] = $dlv['NAME'];
865  }
866 
867  return $result;
868  }

◆ onGetBusinessValueGroups()

static onGetBusinessValueGroups ( )
static

См. определение в файле sale/lib/delivery/services/manager.php строка 870

871  {
872  $result = array(
873  'DELIVERY' => array('NAME' => Loc::getMessage('SALE_DLVR_MNGR_DLV_SRVS'), 'SORT' => 100),
874  );
875 
876  $handlers = self::getHandlersList();
877 
878  /** @var Base $handlerClassName */
879  foreach($handlers as $handlerClassName)
880  $result = array_merge($result, $handlerClassName::onGetBusinessValueGroups());
881 
882  return $result;
883  }

◆ setChildrenFieldsValues()

static setChildrenFieldsValues (   $id,
array  $fields 
)
static

Sets fields values to all children.

Аргументы
int$id
array$fields
Возвращает
int count modified children
Исключения

См. определение в файле sale/lib/delivery/services/manager.php строка 892

893  {
894  if(empty($fields))
895  return 0;
896 
897  $counter = 0;
898 
899  $res = Table::getList(array(
900  'filter' => array('PARENT_ID' => $id),
901  'select' => array('ID')
902  ));
903 
904  while($child = $res->fetch())
905  {
906  $ures = self::update($child['ID'], $fields);
907 
908  if($ures->isSuccess())
909  $counter++;
910 
911  $counter += self::setChildrenFieldsValues($child['ID'], $fields);
912  }
913 
914  return $counter;
915  }

◆ setIdCodeCached()

static setIdCodeCached (   $id,
  $code 
)
staticprotected

Saves relation between Id an code of delivery service.

Аргументы
int$id
string$code

См. определение в файле sale/lib/delivery/services/manager.php строка 999

1000  {
1001  $cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache();
1002  $cacheManager->set("SALE_DELIVERY_ID_CODE_MAP_I_".$id, $code);
1003  $cacheManager->set("SALE_DELIVERY_ID_CODE_MAP_C_".$code, $id);
1004  }

◆ update()

static update (   $id,
array  $fields 
)
static

Updates delivery service.

Аргументы
int$id
array$fields
Возвращает
\Bitrix\Main\Entity\UpdateResult
Исключения
SystemException

См. определение в файле sale/lib/delivery/services/manager.php строка 754

755  {
756  self::initHandlers();
757 
758  $res = \Bitrix\Sale\Delivery\Services\Table::update($id, $fields);
759 
760  if($res->isSuccess())
761  {
762  if(!empty($fields["CLASS_NAME"]) && class_exists($fields["CLASS_NAME"]))
763  $fields["CLASS_NAME"]::onAfterUpdate($res->getId(), $fields);
764 
765  if(isset($fields['CODE']))
766  self::cleanIdCodeCached($id);
767  }
768 
769  return $res;
770  }

Поля

◆ $cachedFields

$cachedFields = array()
staticprotected

См. определение в файле sale/lib/delivery/services/manager.php строка 37

◆ $handlers

$handlers = null
staticprotected

См. определение в файле sale/lib/delivery/services/manager.php строка 36

◆ $handlersDirectories

$handlersDirectories = array()
staticprotected

См. определение в файле sale/lib/delivery/services/manager.php строка 40

◆ $objectsPool

$objectsPool = null
staticprotected

См. определение в файле sale/lib/delivery/services/manager.php строка 42

◆ SKIP_CHILDREN_PARENT_CHECK

const SKIP_CHILDREN_PARENT_CHECK = 1

См. определение в файле sale/lib/delivery/services/manager.php строка 34

◆ SKIP_PROFILE_PARENT_CHECK

const SKIP_PROFILE_PARENT_CHECK = 0

См. определение в файле sale/lib/delivery/services/manager.php строка 33


Объявления и описания членов класса находятся в файле:
Bitrix\Sale\Cashbox\Manager\update
static update($primary, array $data)
Definition: sale/lib/cashbox/manager.php:250
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
Definition: loc.php:29
Bitrix\Main\Loader\registerAutoLoadClasses
static registerAutoLoadClasses($moduleName, array $arClasses)
Registers classes for auto loading.
Definition: main/lib/loader.php:220
Bitrix\Main\IO\Directory\isDirectoryExists
static isDirectoryExists($path)
Definition: main/lib/io/directory.php:149
Bitrix\Forum\Internals\getById
static getById(int $id)
Definition: forum/lib/internals/entityfabric.php:11
Bitrix\Main\Config\Option\get
static get($moduleId, $name, $default="", $siteId=false)
Returns a value of an option.
Definition: main/lib/config/option.php:29
Bitrix\Main\IO\File\isFileExists
static isFileExists($path)
Definition: main/lib/io/file.php:256
Bitrix\Sale\Cashbox\Manager\delete
static delete($primary)
Definition: sale/lib/cashbox/manager.php:269
Bitrix\Main\Application\getConnection
static getConnection($name="")
Static method returns database connection for the specified name.
Definition: main/lib/application.php:381
Bitrix\Sale\Delivery\Services\Manager\$handlers
static $handlers
Definition: sale/lib/delivery/services/manager.php:36
Bitrix\Sale\Cashbox\Manager\add
static add(array $data)
Definition: sale/lib/cashbox/manager.php:222
Bitrix\Main\Application\getInstance
static getInstance()
Returns current instance of the Application.
Definition: main/lib/application.php:86
Bitrix\Main\EventResult\SUCCESS
const SUCCESS
Definition: main/lib/eventresult.php:7
Bitrix\Sale\Cashbox\Manager\getObjectById
static getObjectById($id)
Definition: sale/lib/cashbox/manager.php:60
Bitrix
Class Button.