17 '\\' . \Sale\Handlers\Delivery\RestHandler::class,
18 '\\' . \Sale\Handlers\Delivery\RestProfile::class,
23 if (!Main\Loader::includeModule(
'rest'))
28 if (empty($fields[
'APP_ID']) || empty($fields[
'CLEAN']) || $fields[
'CLEAN'] !==
true)
33 $app = Rest\AppTable::getByClientId($fields[
'APP_ID']);
39 $restHandlerResult = Internals\DeliveryRestHandlerTable::getList([
40 'select' => [
'ID',
'CODE'],
42 '=APP_ID' => $app[
'CLIENT_ID'],
45 while ($restHandler = $restHandlerResult->fetch())
47 $deliveryResult = Sale\Delivery\Services\Manager::getList([
48 'select' => [
'ID',
'CONFIG'],
50 '@CLASS_NAME' => self::ALLOW_HANDLERS,
53 while ($delivery = $deliveryResult->fetch())
56 if ($handlerCode === $restHandler[
'CODE'])
58 Sale\Delivery\Services\Manager::delete($delivery[
'ID'],
false);
62 Sale\Delivery\Rest\Internals\DeliveryRestHandlerTable::delete($restHandler[
'ID']);
84 Sale\Helpers\Rest\AccessChecker::checkAccessPermission();
93 return self::replaceIncomingKeys($data);
102 return self::replaceOutcomingKeys($data);
109 private static function replaceIncomingKeys(array $data): array
111 return self::replaceKeys($data, static::getIncomingFieldsMap());
118 private static function replaceOutcomingKeys(array $data): array
120 return self::replaceKeys($data, static::getOutcomingFieldsMap());
128 private static function replaceKeys(array $data, array $map): array
130 foreach ($map as $key => $newKey)
132 if (array_key_exists($key, $data))
134 $data[$newKey] = $data[$key];
138 if (isset($data[
'FIELDS']) && array_key_exists($key, $data[
'FIELDS']))
140 $data[
'FIELDS'][$newKey] = $data[
'FIELDS'][$key];
141 unset($data[
'FIELDS'][$key]);
150 $className = $deliveryData[
'CLASS_NAME'];
151 if (self::isRestHandler($className))
155 if ($appId && !empty($handlerData[
'APP_ID']) && $handlerData[
'APP_ID'] !== $appId)
170 return in_array($className, self::ALLOW_HANDLERS,
true);
177 foreach ($config as $configItem)
179 if (!empty($configItem[
'REST_CODE']))
181 $handlerCode = (string)$configItem[
'REST_CODE'];
193 if (!empty($result[$code]))
195 return $result[$code];
198 $handlerData = Internals\DeliveryRestHandlerTable::getList([
199 'filter' => [
'CODE' => $code],
204 $result[$code] = $handlerData;
207 return $result[$code] ??
null;
static includeModule($moduleName)