Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
new_to_automatic.php
1<?
3
5
14{
16 protected $service = null;
17 const HANDLER = __FILE__;
18
22 public function __construct(Base $service)
23 {
24 $this->service = $service;
25 }
26
30 public function Init()
31 {
32 return array(
33 "SID" => 'new'.$this->service->getId(),
34 "NAME" => $this->service->getName(),
35 "DESCRIPTION" => $this->service->getDescription(),
36 "DESCRIPTION_INNER" => "DESCRIPTION_INNER",
37 "BASE_CURRENCY" => $this->service->getCurrency(),
38 "HANDLER" => self::HANDLER,
39
40 // Handler methods
41 "COMPABILITY" => array($this, "compatibility"),
42 "CALCULATOR" => array($this, "calculate"),
43
44 // Fake profile
45 "PROFILES" => array(
46 "profile" => array(
47 "TITLE" => ".",
48 "DESCRIPTION" => ""
49 )
50 )
51 );
52 }
53
60 public function compatibility($arOrder, $arConfig)
61 {
62 $result = array();
63 $shipment = \CSaleDelivery::convertOrderOldToNew($arOrder);
64
65 if($this->service->isCompatible($shipment))
66 $result = array('profile');
67
68 return $result;
69 }
70
79 public function calculate($profile, $arConfig, $arOrder, $STEP, $TEMP = false)
80 {
81 $res = $this->service->calculate(
82 \CSaleDelivery::convertOrderOldToNew($arOrder)
83 );
84
85 return array(
86 "VALUE" => $res->getPrice(),
87 "TRANSIT" => $res->getPeriodDescription(),
88 "RESULT" => $res->isSuccess() ? "OK" : "ERROR",
89 );
90 }
91
98 public static function convertNewServiceToOld($service)
99 {
100 if (intval($service["ID"]) <= 0)
101 {
102 return [];
103 }
104
105 $newService = Manager::getObjectById($service["ID"]);
106 if (is_null($newService))
107 {
108 return [];
109 }
110
111 $service["SID"] = 'new'.$service["ID"];
112 $service["TAX_RATE"] = 0;
113 $service["INSTALLED"] = 'Y';
114 $service["BASE_CURRENCY"] = $service["CURRENCY"];
115 $service["SETTINGS"] = array();
116 $service["HANDLER"] = self::HANDLER;
117
118 if (intval($service["LOGOTIP"]) > 0)
119 $service["LOGOTIP"] = \CFile::getFileArray($service["LOGOTIP"]);
120
121 $service["CONFIG"] = array(
122 "CONFIG_GROUPS" => array(),
123 "CONFIG" => array(),
124 );
125
126 $service["PROFILES"] = array();
127
128 $profileParams = array(
129 "TITLE" => "",
130 "DESCRIPTION" => $service["DESCRIPTION"],
131 "TAX_RATE" => 0,
132 "ACTIVE" => $service["ACTIVE"]
133 );
134
135 $restrictions = Restrictions\Manager::getRestrictionsList($service["ID"]);
136
137 foreach($restrictions as $restriction)
138 {
139 switch($restriction["CLASS_NAME"])
140 {
141 case '\Bitrix\Sale\Delivery\Restrictions\ByWeight':
142 $profileParams["RESTRICTIONS_WEIGHT"] = array($restriction["PARAMS"]["MIN_WEIGHT"], $restriction["PARAMS"]["MAX_WEIGHT"]);
143 break;
144
145 case '\Bitrix\Sale\Delivery\Restrictions\ByPrice':
146 $profileParams["RESTRICTIONS_SUM"] = array($restriction["PARAMS"]["MIN_PRICE"], $restriction["PARAMS"]["MAX_PRICE"]);
147 break;
148
149 case '\Bitrix\Sale\Delivery\Restrictions\ByDimensions':
150 $profileParams["RESTRICTIONS_DIMENSIONS"] = array(
151 $restriction["PARAMS"]["LENGTH"],
152 $restriction["PARAMS"]["WIDTH"],
153 $restriction["PARAMS"]["HEIGHT"]
154 );
155
156 $profileParams["RESTRICTIONS_MAX_SIZE"] = $restriction["PARAMS"]["MAX_DIMENSION"];
157 $profileParams["RESTRICTIONS_DIMENSIONS_SUM"] = $restriction["PARAMS"]["MAX_DIMENSIONS_SUM"];
158 break;
159
160 default:
161 break;
162 }
163 }
164
165 $service["PROFILES"]['profile'] = $profileParams;
166
167 $newToAutomatic = new self($newService);
168 $service = array_merge($newToAutomatic->init(), $service);
169 return $service;
170 }
171}
static getObjectById($deliveryId)
Definition manager.php:438
calculate($profile, $arConfig, $arOrder, $STEP, $TEMP=false)