3namespace Sale\Handlers\Delivery;
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;
20final class YandextaxiProfile
extends Base
22 private const PROFILE_COURIER =
'courier';
23 private const PROFILE_EXPRESS =
'express';
24 private const PROFILE_CARGO =
'cargo';
27 protected $yandextaxiHandler;
30 protected $profileType;
33 protected static $whetherAdminExtraServicesShow =
true;
36 protected static $isProfile =
true;
39 private $rateCalculator;
42 private $tariffsChecker;
47 public function __construct(
array $initParams)
49 if (empty($initParams[
'PARENT_ID']))
51 throw new ArgumentNullException(
'initParams[PARENT_ID]');
54 parent::__construct($initParams);
56 $this->yandextaxiHandler = Manager::getObjectById($this->parentId);
57 if (!($this->yandextaxiHandler instanceof YandextaxiHandler))
59 throw new ArgumentNullException(
'this->yandextaxiHandler is not instance of YandextaxiHandler');
62 if (!empty($initParams[
'PROFILE_ID']))
64 $this->profileType = $initParams[
'PROFILE_ID'];
66 elseif (!empty($this->config[
'MAIN'][
'PROFILE_TYPE']))
68 $this->profileType = $this->config[
'MAIN'][
'PROFILE_TYPE'];
70 if (empty($this->profileType))
72 throw new ArgumentNullException(
'Profile type is not specified');
77 $this->name = $this->yandextaxiHandler->getProfilesList()[$this->profileType];
80 $this->rateCalculator = ServiceContainer::getRateCalculator();
81 $this->tariffsChecker = ServiceContainer::getTariffsChecker();
87 public static function getClassTitle()
89 return Loc::getMessage(
'SALE_YANDEX_TAXI_TARIFF');
95 protected function getConfigStructure()
99 'TITLE' => Loc::getMessage(
'SALE_YANDEX_TAXI_TARIFF_SETTINGS'),
103 'NAME' => Loc::getMessage(
'SALE_YANDEX_TAXI_TARIFF_CODE'),
105 'DEFAULT' => $this->profileType,
115 protected function calculateConcrete(Shipment $shipment)
117 return $this->rateCalculator->calculateRate($shipment);
123 public function getParentService()
125 return $this->yandextaxiHandler;
131 public static function whetherAdminExtraServicesShow()
133 return self::$whetherAdminExtraServicesShow;
139 public static function isProfile()
141 return self::$isProfile;
147 public function isCompatible(Shipment $shipment)
149 return (
bool)$this->tariffsChecker->isTariffAvailableByShipment($this->profileType, $shipment);
155 public function getCompatibleExtraServiceIds(Shipment $shipment): ?
array
157 $supportedRequirements = $this->tariffsChecker->getSupportedRequirementsByTariff($this->profileType, $shipment);
161 \Bitrix\Sale\Delivery\ExtraServices\Manager::getExtraServicesList($this->
getId()),
162 function ($extraService) use ($supportedRequirements)
165 $extraService[
'CODE'] === OrderEntitiesCodeDictionary::DOOR_DELIVERY_EXTRA_SERVICE_CODE
166 || in_array($extraService[
'CODE'], $supportedRequirements,
true)
177 public function getDeliveryRequestHandler()
179 return new RequestHandler($this);
185 public function getTags():
array
187 return $this->profileType === self::PROFILE_COURIER
188 ? [static::TAG_PROFITABLE]
195 protected function getProfileType(): string
197 return (
string)$this->profileType;
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)