43 if(!is_array($initParam))
45 if(intval($initParam) <= 0)
48 $itemsParams = self::getExtraServicesList($initParam);
53 $itemsParams = $initParam;
56 if(empty($itemsParams))
59 if(!empty($this->items))
60 sortByColumn($itemsParams,
array(
"SORT" => SORT_ASC,
"NAME" => SORT_ASC),
'',
null,
true);
62 foreach($itemsParams as
$params)
76 if(static::$classes ===
null)
77 self::initClassesList();
79 return static::$classes;
87 public static function initClassesList()
89 if(static::$classes !==
null)
93 '\Bitrix\Sale\Delivery\ExtraServices\Enum' =>
'lib/delivery/extra_services/enum.php',
94 '\Bitrix\Sale\Delivery\ExtraServices\Store' =>
'lib/delivery/extra_services/store.php',
95 '\Bitrix\Sale\Delivery\ExtraServices\Quantity' =>
'lib/delivery/extra_services/quantity.php',
96 '\Bitrix\Sale\Delivery\ExtraServices\Checkbox' =>
'lib/delivery/extra_services/checkbox.php'
101 unset($classes[
'\Bitrix\Sale\Delivery\ExtraServices\Store']);
102 $event =
new Event(
'sale',
'onSaleDeliveryExtraServicesClassNamesBuildList');
104 $resultList =
$event->getResults();
106 if (is_array($resultList) && !empty($resultList))
108 $customClasses =
array();
110 foreach ($resultList as $eventResult)
113 if ($eventResult->getType() != EventResult::SUCCESS)
116 $params = $eventResult->getParameters();
119 $customClasses = array_merge($customClasses,
$params);
122 if(!empty($customClasses))
125 $classes = array_merge($customClasses, $classes);
129 static::$classes = array_merge(array_keys($classes));
131 return static::$classes;
148 return (isset($this->items[$id]) ? $this->items[$id] :
null);
157 foreach($this->items as $item)
158 if($item->getCode() ==
$code)
172 foreach($this->items as $itemId => $item)
173 $result += $item->getCostShipment($shipment);
188 (isset(
$params[
"RIGHTS"][self::RIGHTS_ADMIN_IDX]) ?
$params[
"RIGHTS"][self::RIGHTS_ADMIN_IDX] :
"Y").
189 (isset(
$params[
"RIGHTS"][self::RIGHTS_MANAGER_IDX]) ?
$params[
"RIGHTS"][self::RIGHTS_MANAGER_IDX] :
"Y").
190 (isset(
$params[
"RIGHTS"][self::RIGHTS_CLIENT_IDX]) ?
$params[
"RIGHTS"][self::RIGHTS_CLIENT_IDX] :
"Y");
193 if(!isset(
$params[
"CLASS_NAME"]) ||
$params[
"CLASS_NAME"] ==
'' || !class_exists(
$params[
"CLASS_NAME"]))
199 if(isset(
$params[
"CLASS_NAME_DISABLED"]))
200 unset(
$params[
"CLASS_NAME_DISABLED"]);
202 if(is_callable(
$params[
"CLASS_NAME"].
"::prepareParamsToSave"))
221 if(!is_callable($className.
'::getAdminParamsControl'))
222 throw new SystemException(
'"'.$className.
'::getAdminParamsControl" does not exist!');
224 return $className::getAdminParamsControl(
$name,
$params);
238 if(
$params[
"CLASS_NAME"] ===
'' )
241 if(!isset(
$params[
"CLASS_NAME"]))
244 if(!class_exists(
$params[
"CLASS_NAME"]))
247 if(!is_subclass_of(
$params[
"CLASS_NAME"], Base::class))
249 throw new \Bitrix\Main\SystemException(
250 'Class "' .
$params[
"CLASS_NAME"] .
'" is not a subclass of the \Bitrix\Sale\Delivery\ExtraServices\Base'
255 $this->items[
$params[
"ID"]] = $item;
264 foreach($values as $eSrvId => $value)
266 $item = $this->
getItem($eSrvId);
269 $item->setValue($value);
279 foreach($this->items as $itemId => $item)
287 if ($shipmentId <= 0 || $deliveryId <= 0)
292 $dbRes = ShipmentExtraServiceTable::getList([
294 '=SHIPMENT_ID' => $shipmentId,
295 '!=ID' => self::getStoresValueId($deliveryId),
299 while ($row =
$dbRes->fetch())
301 $result[$row[
'EXTRA_SERVICE_ID']] = $row[
'VALUE'];
319 if(intval($shipmentId) <= 0)
326 '=SHIPMENT_ID' => $shipmentId
330 while($row =
$dbRes->fetch())
331 $exist[$row[
"EXTRA_SERVICE_ID"]] = $row[
"ID"];
333 if(is_array($extraServices))
335 foreach($extraServices as $extraServiceId => $value)
337 if(array_key_exists($extraServiceId, $exist))
339 $res = ShipmentExtraServiceTable::update($exist[$extraServiceId],
array(
"VALUE" => $value));
343 $res = ShipmentExtraServiceTable::add(
array(
344 "EXTRA_SERVICE_ID" => $extraServiceId,
345 "SHIPMENT_ID" => $shipmentId,
350 if(
$res->isSuccess())
351 unset($exist[$extraServiceId]);
359 foreach($exist as $extraServiceId => $value)
361 $res = ShipmentExtraServiceTable::delete($extraServiceId);
363 if(!
$res->isSuccess())
378 public static function getObjectsForShipment(
int $shipmentId,
int $deliveryId,
string $currency):
array
382 $extraServiceValuesList = ShipmentExtraServiceTable::getList(
385 '=SHIPMENT_ID' => $shipmentId,
386 '!=ID' => self::getStoresValueId($deliveryId)
395 while ($extraServiceValue = $extraServiceValuesList->fetchObject())
397 $extraService = $extraServiceValue->getExtraService();
399 $className = $extraService->getClassName();
402 $extraServiceInstance =
new $className(
403 $extraService->getId(),
405 'NAME' => $extraService->getName(),
406 'CODE' => $extraService->getCode(),
407 'INIT_VALUE' => $extraService->getInitValue(),
408 'PARAMS' => $extraService->getParams()
411 $extraServiceValue->getValue()
414 if (!$extraServiceInstance instanceof
Base)
418 'Object is not of expected type: %s',
424 $result[$extraServiceValue[
'EXTRA_SERVICE_ID']] = $extraServiceInstance;
432 if ($shipmentId <= 0 || $deliveryId <= 0)
437 $storeFields = self::getStoresFields($deliveryId);
438 if (empty($storeFields))
443 $row = ShipmentExtraServiceTable::getList([
445 '=SHIPMENT_ID' => $shipmentId,
446 '=EXTRA_SERVICE_ID' => $storeFields[
'ID'],
451 return $row ? (int)$row[
'VALUE'] : 0;
465 if(intval($shipmentId) <= 0)
470 if(intval($deliveryId) <= 0)
473 $storeFields = self::getStoresFields($deliveryId,
false);
475 if(isset($storeFields[
'ID']))
479 '=SHIPMENT_ID' => $shipmentId,
480 '=EXTRA_SERVICE_ID' => $storeFields[
'ID']
486 if($row =
$dbRes->fetch())
487 $storeRowId = $row[
"ID"];
491 $res = ShipmentExtraServiceTable::update($storeRowId,
array(
"VALUE" => $storeId));
495 $res = ShipmentExtraServiceTable::add(
array(
496 "EXTRA_SERVICE_ID" => $storeFields[
'ID'],
497 "SHIPMENT_ID" => $shipmentId,
502 if(!
$res->isSuccess())
516 $fields = self::getStoresFields($deliveryId);
533 if(intval($deliveryId) <= 0)
536 $result = self::getExtraServicesList($deliveryId,
true);
555 $stores = self::getStoresFields($deliveryId);
556 return isset($stores[
"PARAMS"][
"STORES"]) ? $stores[
"PARAMS"][
"STORES"] :
array();
566 $storesFields = self::getStoresFields($deliveryId,
false);
568 if(empty($storesFields[
'ID']))
574 unset(static::$cachedFields[$deliveryId][$storesFields[
'ID']]);
586 if(intval($deliveryId) <= 0)
589 $storesFields = self::getStoresFields($deliveryId);
591 if(empty($storesFields[
'ID']))
602 static::$cachedFields[$deliveryId][$storesFields[
'ID']][
"ACTIVE"] =
"N";
616 $storesFields = self::getStoresFields($deliveryId,
false);
618 if(!empty($storesFields[
'ID']))
620 $res = Table::update(
625 "STORES" => $storesList
634 "CODE" => self::STORE_PICKUP_CODE,
635 "NAME" => Loc::getMessage(
"DELIVERY_SERVICE_MANAGER_ES_NAME"),
636 "DESCRIPTION" => Loc::getMessage(
"DELIVERY_SERVICE_MANAGER_ES_DESCRIPTION"),
637 "CLASS_NAME" => self::STORE_PICKUP_CLASS,
638 "DELIVERY_ID" => $deliveryId,
642 "STORES" => $storesList
648 if(!
$res->isSuccess())
662 if(intval($deliveryId) <= 0)
665 if(!isset(static::$cachedFields[$deliveryId]))
669 if(!empty($srv[
'PARENT_ID']))
671 self::prepareData(
array($deliveryId, $srv[
'PARENT_ID']));
672 static::$cachedFields[$deliveryId] = static::$cachedFields[$deliveryId] + static::$cachedFields[$srv[
'PARENT_ID']];
676 self::prepareData(
array($deliveryId));
682 foreach(static::$cachedFields[$deliveryId] as $id => $es)
684 if($es[
'CLASS_NAME'] == self::STORE_PICKUP_CLASS)
707 if(empty($servicesIds))
710 foreach($servicesIds as $id)
714 if(!empty($srv[
'PARENT_ID']) && !in_array($id, $servicesIds))
715 $servicesIds[] = $id;
718 $ids = array_diff($servicesIds, array_keys(static::$cachedFields));
722 '=DELIVERY_ID' => $ids,
726 "=CLASS_NAME" => self::STORE_PICKUP_CLASS
733 "select" =>
array(
"*",
"CURRENCY" =>
"DELIVERY_SERVICE.CURRENCY")
736 while($es =
$dbRes->fetch())
738 if(!isset(static::$cachedFields[$es[
'DELIVERY_ID']]))
739 static::$cachedFields[$es[
'DELIVERY_ID']] =
array();
741 static::$cachedFields[$es[
'DELIVERY_ID']][$es[
"ID"]] = $es;
744 foreach($ids as $deliveryId)
745 if(!isset(static::$cachedFields[$deliveryId]))
746 static::$cachedFields[$deliveryId] =
array();
757 if ($this->
isClone() && $cloneEntity->contains($this))
759 return $cloneEntity[$this];
762 $extraServiceClone = clone $this;
763 $extraServiceClone->isClone =
true;
765 if (!$cloneEntity->contains($this))
767 $cloneEntity[$this] = $extraServiceClone;
770 return $extraServiceClone;
778 return $this->isClone;
790 foreach($this->items as $itemId => $item)
static registerAutoLoadClasses($moduleName, array $classes)