1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
profile.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\Delivery;
4
5use Bitrix\Main\ArgumentNullException;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Sale\Delivery\Services\Base;
8use Bitrix\Sale\Delivery\Services\Manager;
9use Bitrix\Sale\Shipment;
10use Sale\Handlers\Delivery\YandexTaxi\Common\OrderEntitiesCodeDictionary;
11use Sale\Handlers\Delivery\YandexTaxi\RateCalculator;
12use Sale\Handlers\Delivery\YandexTaxi\ServiceContainer;
13use Sale\Handlers\Delivery\YandexTaxi\TariffsChecker;
14use Sale\Handlers\Delivery\YandexTaxi\RequestHandler;
15
20final class YandextaxiProfile extends Base
21{
22 private const PROFILE_COURIER = 'courier';
23 private const PROFILE_EXPRESS = 'express';
24 private const PROFILE_CARGO = 'cargo';
25
27 protected $yandextaxiHandler;
28
30 protected $profileType;
31
33 protected static $whetherAdminExtraServicesShow = true;
34
36 protected static $isProfile = true;
37
39 private $rateCalculator;
40
42 private $tariffsChecker;
43
47 public function __construct(array $initParams)
48 {
49 if (empty($initParams['PARENT_ID']))
50 {
51 throw new ArgumentNullException('initParams[PARENT_ID]');
52 }
53
54 parent::__construct($initParams);
55
56 $this->yandextaxiHandler = Manager::getObjectById($this->parentId);
57 if (!($this->yandextaxiHandler instanceof YandextaxiHandler))
58 {
59 throw new ArgumentNullException('this->yandextaxiHandler is not instance of YandextaxiHandler');
60 }
61
62 if (!empty($initParams['PROFILE_ID']))
63 {
64 $this->profileType = $initParams['PROFILE_ID'];
65 }
66 elseif (!empty($this->config['MAIN']['PROFILE_TYPE']))
67 {
68 $this->profileType = $this->config['MAIN']['PROFILE_TYPE'];
69 }
70 if (empty($this->profileType))
71 {
72 throw new ArgumentNullException('Profile type is not specified');
73 }
74
75 if ($this->id <= 0)
76 {
77 $this->name = $this->yandextaxiHandler->getProfilesList()[$this->profileType];
78 }
79
80 $this->rateCalculator = ServiceContainer::getRateCalculator();
81 $this->tariffsChecker = ServiceContainer::getTariffsChecker();
82 }
83
87 public static function getClassTitle()
88 {
89 return Loc::getMessage('SALE_YANDEX_TAXI_TARIFF');
90 }
91
95 protected function getConfigStructure()
96 {
97 return [
98 'MAIN' => [
99 'TITLE' => Loc::getMessage('SALE_YANDEX_TAXI_TARIFF_SETTINGS'),
100 'ITEMS' => [
101 'PROFILE_TYPE' => [
102 'TYPE' => 'STRING',
103 'NAME' => Loc::getMessage('SALE_YANDEX_TAXI_TARIFF_CODE'),
104 'READONLY' => true,
105 'DEFAULT' => $this->profileType,
106 ],
107 ]
108 ]
109 ];
110 }
111
115 protected function calculateConcrete(Shipment $shipment)
116 {
117 return $this->rateCalculator->calculateRate($shipment);
118 }
119
123 public function getParentService()
124 {
125 return $this->yandextaxiHandler;
126 }
127
131 public static function whetherAdminExtraServicesShow()
132 {
133 return self::$whetherAdminExtraServicesShow;
134 }
135
139 public static function isProfile()
140 {
141 return self::$isProfile;
142 }
143
147 public function isCompatible(Shipment $shipment)
148 {
149 return (bool)$this->tariffsChecker->isTariffAvailableByShipment($this->profileType, $shipment);
150 }
151
155 public function getCompatibleExtraServiceIds(Shipment $shipment): ?array
156 {
157 $supportedRequirements = $this->tariffsChecker->getSupportedRequirementsByTariff($this->profileType, $shipment);
158
159 return array_column(
160 array_filter(
161 \Bitrix\Sale\Delivery\ExtraServices\Manager::getExtraServicesList($this->getId()),
162 function ($extraService) use ($supportedRequirements)
163 {
164 return (
165 $extraService['CODE'] === OrderEntitiesCodeDictionary::DOOR_DELIVERY_EXTRA_SERVICE_CODE
166 || in_array($extraService['CODE'], $supportedRequirements, true)
167 );
168 }
169 ),
170 'ID'
171 );
172 }
173
177 public function getDeliveryRequestHandler()
178 {
179 return new RequestHandler($this);
180 }
181
185 public function getTags(): array
186 {
187 return $this->profileType === self::PROFILE_COURIER
188 ? [static::TAG_PROFITABLE]
189 : [];
190 }
191
195 protected function getProfileType(): string
196 {
197 return (string)$this->profileType;
198 }
199}
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393