17require_once __DIR__.
'/../inputs.php';
70 if(isset($initParams[
"PARENT_ID"]))
71 $this->parentId = $initParams[
"PARENT_ID"];
75 if(!isset($initParams[
"ACTIVE"]))
76 $initParams[
"ACTIVE"] =
"N";
78 if(!isset($initParams[
"NAME"]))
79 $initParams[
"NAME"] =
"";
81 if(!isset($initParams[
"CONFIG"]) || !is_array($initParams[
"CONFIG"]))
82 $initParams[
"CONFIG"] = array();
84 if(!is_array($initParams[
"CONFIG"]))
85 throw new \Bitrix\Main\ArgumentTypeException(
"CONFIG",
"array");
87 $this->active = $initParams[
"ACTIVE"] ==
"Y";
88 $this->name = $initParams[
"NAME"];
89 $this->config = $initParams[
"CONFIG"];
91 if(isset($initParams[
"ID"]) )
92 $this->
id = $initParams[
"ID"];
94 if(isset($initParams[
"DESCRIPTION"]))
95 $this->description = $initParams[
"DESCRIPTION"];
97 if(isset($initParams[
"CODE"]))
98 $this->code = $initParams[
"CODE"];
100 if(isset($initParams[
"SORT"]))
101 $this->sort = $initParams[
"SORT"];
103 if(isset($initParams[
"LOGOTIP"]))
104 $this->logotip = $initParams[
"LOGOTIP"];
106 if(isset($initParams[
"CURRENCY"]))
107 $this->currency = $initParams[
"CURRENCY"];
109 if(isset($initParams[
"ALLOW_EDIT_SHIPMENT"]))
110 $this->allowEditShipment = $initParams[
"ALLOW_EDIT_SHIPMENT"];
112 if(isset($initParams[
"VAT_ID"]))
113 $this->vatId = intval($initParams[
"VAT_ID"]);
115 if(isset($initParams[
"RESTRICTED"]))
116 $this->restricted = $initParams[
"RESTRICTED"];
118 $this->trackingParams =
119 isset($initParams[
"TRACKING_PARAMS"]) && is_array($initParams[
"TRACKING_PARAMS"])
120 ? $initParams[
"TRACKING_PARAMS"]
124 if(isset($initParams[
"EXTRA_SERVICES"]))
125 $this->extraServices = new \Bitrix\Sale\Delivery\ExtraServices\Manager($initParams[
"EXTRA_SERVICES"], $this->currency);
126 elseif($this->
id > 0)
127 $this->extraServices = new \Bitrix\Sale\Delivery\ExtraServices\Manager($this->
id, $this->currency);
129 $this->extraServices = new \Bitrix\Sale\Delivery\ExtraServices\Manager(array(), $this->currency);
137 return (
string)$this->handlerCode;
148 && ($parentServiceHandlerCode = $parentService->getHandlerCode())
149 && ($profileType = $this->getProfileType())
152 return $parentServiceHandlerCode .
'_' . $profileType;
169 if ($shipment && !$shipment->getCollection())
171 $result->addError(
new Error(
'\Bitrix\Sale\Delivery\Services\Base::calculate() can\'t calculate empty shipment!'));
185 $this->extraServices->setOperationCurrency($shipment->getCurrency());
186 $extraServicePrice = $this->extraServices->getTotalCostShipment($shipment);
188 if ((
float)$extraServicePrice > 0)
190 $result->setExtraServicesPrice($extraServicePrice);
196 'SHIPMENT' => $shipment,
197 'DELIVERY_ID' => $this->id,
200 $event =
new Event(
'sale', self::EVENT_ON_CALCULATE, $eventParams);
202 $resultList = $event->getResults();
204 if (is_array($resultList) && !empty($resultList))
206 foreach ($resultList as &$eventResult)
208 if ($eventResult->getType() != EventResult::SUCCESS)
213 $params = $eventResult->getParameters();
215 if (isset($params[
'RESULT']))
217 $result = $params[
'RESULT'];
230 return $this->extraServices;
238 return $this->currency;
249 foreach($shipment->getShipmentItemCollection() as $shipmentItem)
252 $basketItem = $shipmentItem->getBasketItem();
257 if($basketItem->isBundleChild())
260 $result += $basketItem->getPrice();
302 'DELIVERY_CALCULATION'
314 $structure = $fields[
"CLASS_NAME"]::getConfigStructure();
316 foreach($structure as $key1 => $rParams)
318 foreach($rParams[
"ITEMS"] as $key2 => $iParams)
320 if ($iParams[
"TYPE"] ==
"DELIVERY_SECTION")
325 $value = $fields[
"CONFIG"][$key1][$key2] ??
null;
327 $errors = \Bitrix\Sale\Internals\Input\Manager::getRequiredError($iParams, $value);
331 $errors = \Bitrix\Sale\Internals\Input\Manager::getError($iParams, $value);
336 $strError .=
Loc::getMessage(
"SALE_DLVR_BASE_FIELD").
" \"".$iParams[
"NAME"].
"\": ".implode(
"<br>\n", $errors).
"<br>\n";
346 if(mb_strpos($fields[
'CLASS_NAME'],
'\\') !== 0)
348 $fields[
'CLASS_NAME'] =
'\\'.$fields[
'CLASS_NAME'];
371 if(!is_array($confValues))
372 $confValues = array();
374 if(isset($confStructure[
"ITEMS"]) && is_array($confStructure[
"ITEMS"]))
376 $confStructure[
"ITEMS"] = $this->
glueValuesToConfig($confStructure[
"ITEMS"], $confValues);
380 foreach($confStructure as $itemKey => $itemParams)
382 if(isset($confStructure[$itemKey][
"VALUE"]))
385 if(isset($itemParams[
"ITEMS"]) && is_array($itemParams[
"ITEMS"]))
386 $confStructure[$itemKey][
"ITEMS"] = $this->
glueValuesToConfig($itemParams[
"ITEMS"], $confValues[$itemKey]);
387 elseif(isset($confValues[$itemKey]))
388 $confStructure[$itemKey][
"VALUE"] = $confValues[$itemKey];
389 elseif(!isset($itemParams[
"VALUE"]) && isset($itemParams[
"DEFAULT"]))
390 $confStructure[$itemKey][
"VALUE"] = $itemParams[
"DEFAULT"];
394 return $confStructure;
405 if(!is_array($configStructure))
406 throw new SystemException (
"Method getConfigStructure() must return an array!");
408 foreach($configStructure as $key => $configSection)
409 $configStructure[$key] = $this->
glueValuesToConfig($configSection, isset($this->config[$key]) ? $this->config[$key] : array());
411 return $configStructure;
419 return $this->config;
452 return self::$canHasProfiles;
492 return $this->description;
500 return $this->parentId;
516 $result = $this->name;
519 $result = $parent->getName().
" (".$result.
")";
529 return $this->logotip;
538 return intval($logo) > 0 ? \CFile::GetPath($logo) :
"";
550 if(intval($this->parentId) > 0)
551 $result = Manager::getObjectById($this->parentId);
593 return self::$whetherAdminExtraServicesShow;
602 return new \Bitrix\Main\Result();
610 public static function onAfterAdd($serviceId, array $fields = array())
678 return self::$isProfile;
694 return $this->trackingClass;
702 $this->trackingClass = $class;
710 return $this->trackingParams;
726 return self::$isCalculatePriceImmediately;
734 return $this->restricted;
776 return $this->allowEditShipment !=
'N';
842 public function createClone(\SplObjectStorage $cloneEntity)
844 if ($this->isClone() && $cloneEntity->contains($this))
846 return $cloneEntity[$this];
849 $deliveryServiceClone = clone $this;
850 $deliveryServiceClone->isClone =
true;
852 if (!$cloneEntity->contains($this))
854 $cloneEntity[$this] = $deliveryServiceClone;
858 if ($extraServices = $this->getExtraServices())
860 if (!$cloneEntity->contains($extraServices))
862 $cloneEntity[$extraServices] = $extraServices->createClone($cloneEntity);
865 if ($cloneEntity->contains($extraServices))
867 $deliveryServiceClone->extraServices = $cloneEntity[$extraServices];
871 return $deliveryServiceClone;
879 return $this->isClone;
920 return $this->deliveryRequestHandler;
925 return Manager::createObject($fields);
938 [
'',
'ru',
'kz',
'by',
'ua'],
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static onGetBusinessValueGroups()
static getDefaultVatRate()
prepareFieldsForUsing(array $fields)
static onGetBusinessValueConsumers()
static onBeforeAdd(array &$fields=array())
static onBeforeUpdate($serviceId, array &$fields=array())
getCompatibleExtraServiceIds(Shipment $shipment)
calculate(\Bitrix\Sale\Shipment $shipment=null, $extraServices=array())
getEmbeddedExtraServicesList()
getAdditionalInfoShipmentPublic(Shipment $shipment)
static getSupportedServicesList()
static whetherAdminExtraServicesShow()
static $isCalculatePriceImmediately
isCompatible(Shipment $shipment)
static getClassDescription()
static getAdminFieldsList()
__construct(array $initParams)
static getChildrenClassNames()
getDeliveryRequestHandler()
prepareFieldsForSaving(array $fields)
static $whetherAdminExtraServicesShow
static onAfterAdd($serviceId, array $fields=array())
glueValuesToConfig(array $confStructure, $confValues=array())
static isHandlerCompatible()
createProfileObject($fields)
static onAfterDelete($serviceId)
calculateConcrete(\Bitrix\Sale\Shipment $shipment)
static onAfterUpdate($serviceId, array $fields=array())
getAdditionalInfoShipmentEdit(Shipment $shipment)
processAdditionalInfoShipmentEdit(Shipment $shipment, array $requestData)
static whetherAdminRestrictionsShow()
getAdditionalInfoShipmentView(Shipment $shipment)
isCalculatePriceImmediately()