1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
handler.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\Delivery;
4
5use Bitrix\Main,
6 Bitrix\Main\Loader,
7 Bitrix\Main\Localization\Loc,
8 Bitrix\Sale\Delivery\Services\Base,
9 Bitrix\Sale\Delivery\Services\Manager;
10
11Loader::registerAutoLoadClasses(
12 'sale',
13 [
14 __NAMESPACE__.'\RestProfile' => 'handlers/delivery/rest/profile.php',
15 ]
16);
17
18Loc::loadMessages(__FILE__);
19
24final class RestHandler extends Base
25{
26 private const HANDLER_CODE_PREFIX = 'BITRIX_REST_';
27
28 protected static $canHasProfiles = true;
29 protected static $whetherAdminExtraServicesShow = true;
30
35 public static function getClassTitle(): string
36 {
37 return Loc::getMessage('SALE_DELIVERY_REST_HANDLER_NAME');
38 }
39
43 public static function getClassDescription(): string
44 {
45 return Loc::getMessage('SALE_DELIVERY_REST_HANDLER_DESCRIPTION');
46 }
47
53 public function __construct(array $initParams)
54 {
55 parent::__construct($initParams);
56
57 if (isset($initParams['REST_CODE']) && $initParams['REST_CODE'] !== '')
58 {
59 $this->handlerCode = $initParams['REST_CODE'];
60 }
61 elseif (isset($this->config['MAIN']['REST_CODE']))
62 {
63 $this->handlerCode = $this->config['MAIN']['REST_CODE'];
64 }
65
66 if ((int)$this->id <= 0)
67 {
68 $settings = $this->getHandlerSettings();
69 if ($settings !== null)
70 {
71 $this->name = $settings['NAME'];
72 $this->description = $settings['DESCRIPTION'];
73 }
74 }
75 }
76
80 public function getHandlerCode(): string
81 {
82 return self::HANDLER_CODE_PREFIX . (string)$this->handlerCode;
83 }
84
85 private function getHandlerSettings(): ?array
86 {
87 $handlerList = \Bitrix\Sale\Delivery\Services\Manager::getRestHandlerList();
88 $code = str_replace(self::HANDLER_CODE_PREFIX, '', $this->getHandlerCode());
89
90 return $handlerList[$code] ?? null;
91 }
92
97 protected function getConfigStructure(): array
98 {
99 $settings = $this->getHandlerSettings();
100
101 if (!empty($settings['SETTINGS']['CONFIG']))
102 {
103 $result['MAIN'] = $settings['SETTINGS']['CONFIG'];
104 }
105 else
106 {
107 $result['MAIN'] = [
108 'TITLE' => Loc::getMessage('SALE_DELIVERY_REST_HANDLER_SETTING_TITLE'),
109 'DESCRIPTION' => Loc::getMessage('SALE_DELIVERY_REST_HANDLER_SETTING_DESCRIPTION'),
110 ];
111 }
112
113 $result['MAIN']['ITEMS']['REST_CODE'] = [
114 'TYPE' => 'STRING',
115 'NAME' => Loc::getMessage('SALE_DELIVERY_REST_HANDLER_SETTING_REST_CODE'),
116 'READONLY' => true,
117 'DEFAULT' => $settings['CODE'] ?? '',
118 ];
119
120 return $result;
121 }
122
130 public static function onAfterAdd($serviceId, array $fields = array()): bool
131 {
132 if ($serviceId <= 0)
133 {
134 return false;
135 }
136
137 $result = true;
138
139 // Add profiles
140 $fields['ID'] = $serviceId;
141 $srv = new self($fields);
142 $profiles = $srv->getProfilesListFull();
143 if (is_array($profiles) && !empty($profiles))
144 {
145 foreach($profiles as $profileType => $profileFields)
146 {
147 $profile = $srv->getProfileDefaultParams($profileType, $profileFields);
148 $res = Manager::add($profile);
149 $result = $result && $res->isSuccess();
150 }
151 }
152
153 return $result;
154 }
155
159 public function getProfilesListFull(): array
160 {
161 $settings = $this->getHandlerSettings();
162
163 return $settings['PROFILES'] ?? [];
164 }
165
171 private function getProfileDefaultParams($type, array $fields): array
172 {
173 $active = $fields['ACTIVE'] ?? ($this->active ? 'Y' : 'N');
174 $sort = $fields['SORT'] ?? $this->sort;
175
176 return [
177 'CODE' => '',
178 'PARENT_ID' => $this->id,
179 'NAME' => $fields['NAME'],
180 'ACTIVE' => $active,
181 'SORT' => $sort,
182 'DESCRIPTION' => $fields['DESCRIPTION'],
183 'CLASS_NAME' => '\Sale\Handlers\Delivery\RestProfile',
184 'CURRENCY' => $this->currency,
185 'CONFIG' => [
186 'MAIN' => [
187 'PROFILE_TYPE' => $type,
188 ]
189 ]
190 ];
191 }
192
196 public static function whetherAdminExtraServicesShow(): bool
197 {
198 return self::$whetherAdminExtraServicesShow;
199 }
200
204 public static function getChildrenClassNames(): array
205 {
206 return [
207 '\Sale\Handlers\Delivery\RestProfile'
208 ];
209 }
210
214 public function getProfilesList(): array
215 {
216 $result = [];
217
218 $profiles = $this->getProfilesListFull();
219 foreach($profiles as $profileType => $profile)
220 {
221 $result[$profileType] = $profile['NAME'];
222 }
223
224 return $result;
225 }
226
230 public static function canHasProfiles(): bool
231 {
232 return self::$canHasProfiles;
233 }
234}
$type
Определения options.php:106
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$settings
Определения product_settings.php:43
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$currency
Определения template.php:266
$fields
Определения yandex_run.php:501