Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/lpost.delivery/lib/handlers/ |
Upload File : |
<? namespace Lpost\Delivery\Handlers; use Bitrix\Main\Context; use Bitrix\Main\DI\ServiceLocator; use Bitrix\Sale\Delivery\CalculationResult, Bitrix\Main\Localization\Loc, \Lpost\Delivery\Settings; use Bitrix\Sale\Delivery\Services\Base; use Bitrix\Sale\Shipment; use Lpost\Delivery\Components\Soa; use Lpost\Delivery\Main\City; use Lpost\Delivery\Order; use Lpost\Delivery\Order\HandlerCalculateOrder\HandlerCalculateRouter; use Lpost\Delivery\Order\HandlerCalculateOrder\HandlerOrderCalculate; use Lpost\Delivery\Order\HandlerCalculateOrder\StrategyDispatcher; use Lpost\Delivery\Order\HandlerCalculateOrder\StrategyOrderMakeZone; use Lpost\Delivery\Service\DeliveryCalculate\StrategyCalculateZone; use Lpost\Delivery\Order\OrderManager; use \Lpost\Delivery\Order\Property; Loc::loadMessages(__FILE__); class Zone extends Base { use \Lpost\Delivery\Base; const TYPE = "zone"; protected static $isProfile = true; protected static $parent = null; protected static $arResCompatible = []; public function __construct(array $initParams) { parent::__construct($initParams); $this->parent = \Bitrix\Sale\Delivery\Services\Manager::getObjectById($this->parentId); } public static function getClassTitle() { return Loc::getMessage("lpost.handler_profile_zone_name"); } public static function getClassDescription() { return Loc::getMessage("lpost.handler_profile_zone_description"); } public function getParentService() { return $this->parent; } public function isCalculatePriceImmediately() { return $this->getParentService()->isCalculatePriceImmediately(); } public static function isProfile() { return self::$isProfile; } /** * @throws \Bitrix\Main\NotSupportedException * @throws \Bitrix\Main\ObjectPropertyException * @throws \Bitrix\Main\NotImplementedException * @throws \Bitrix\Main\ArgumentNullException * @throws \Bitrix\Main\ArgumentOutOfRangeException * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\SystemException * @throws \ErrorException */ protected function calculateConcrete(Shipment $shipment) { $orderManager = new OrderManager($shipment->getOrder()); $deliveryId = $this->getId() ?: $shipment->getDeliveryId(); if(!$orderManager->isLpostDeliveryId($deliveryId)) { return false; } $handlerCalculate = new HandlerOrderCalculate( $orderManager, Context::getCurrent()->getRequest() ); return $handlerCalculate->execute(); } public function getConfigStructure() { $config = $this->parent->getConfigStructure(); $config['MAIN']['TITLE'] = Loc::getMessage("lpost.handler_zone_name"); $config['MAIN']['DESCRIPTION'] = Loc::getMessage("lpost.handler_zone_description"); $config['MAIN']['ITEMS']['IS_FITTING'] = [ "TYPE" => "Y/N", "DEFAULT" => "N", "NAME" => Loc::getMessage("lpost.handler_setting_is_fitting") ]; return $config; } public function prepareFieldsForSaving($fields) { $issue_type = $fields['CONFIG']['MAIN']['ISSUE_TYPE']; $fitting = $fields['CONFIG']['MAIN']['IS_FITTING']; if ($issue_type == 0 && $fitting == 'Y') { $error_text = Loc::getMessage("lpost.handler_setting_error_is_fitting"); throw new \Bitrix\Main\SystemException($error_text); } return parent::prepareFieldsForSaving($fields); } public function isCompatible(Shipment $shipment) { if(!\Sale\Handlers\Delivery\lpost_deliveryHandler::isTokenReady()) { return false; } if (empty(Settings::getInstance()->getOption('yandex_map_api_key'))) { return false; } $weight = $shipment->getWeight(); if ($weight > 150000) { return false; } $order = $shipment->getCollection()->getOrder(); $props = $order->getPropertyCollection(); $deliveryLocation = $props->getDeliveryLocation(); if (!$deliveryLocation) { return false; } if(!$locationCode = $deliveryLocation->getValue()) { return false; } $deliveryId = $this->getId() ?: $shipment->getDeliveryId(); $res = false; if(isset(self::$arResCompatible[$locationCode.'_'.$deliveryId])){ $res = self::$arResCompatible[$locationCode.'_'.$deliveryId]; } else{ // $this->setDebug('Zone isCompatible deliveryLocation arZone', $arZone); if($arZone = \Lpost\Delivery\Main\Zone::getZoneCityById($locationCode, false)){ //if(OrderManager::isLpostDeliveryId($deliveryId)){ $orderManager = new OrderManager($order); $locationId = $orderManager->getLocationId(); if(empty($arZone['city']['name'])) $arZone['city']['name'] = City::getCityData($locationId)['name']; if(empty($arZone['id_pickup'])) $arZone['id_pickup'] = 0; $strategyCalculate = (new StrategyCalculateZone()) ->setBasket($orderManager->getBasket()) ->setPickupId($arZone['id_pickup']) ->setProfileId($deliveryId) ->setIsNotExactAddress(1) ->setAddress(!empty($arZone['city']['full_name']) ? $arZone['city']['full_name'] : $arZone['city']['name']); $addCac = false; $dataCalc = $strategyCalculate->getPreparedData(); //toLogFile(print_r($dataCalc, 1), 'dataCalc'); $result = (new \Lpost\Delivery\Api\Manager())->getServicesCalc($dataCalc); if(!empty($result['JSON_TXT']) && empty($result['Message'])){ $jsonData = \Bitrix\Main\Web\Json::decode($result['JSON_TXT']); if(!empty($jsonData['JSON_TXT']) && is_array($jsonData['JSON_TXT'])){ if( !empty($jsonData['JSON_TXT'][0]['DayLogistic']) ){ self::calculateConcrete($shipment); $res = true; } } } // add if approved if(!$res && isset($dataCalc['DateShipment'])){ unset($dataCalc['DateShipment']); $result = (new \Lpost\Delivery\Api\Manager())->getServicesCalc($dataCalc); if(!empty($result['JSON_TXT']) && empty($result['Message'])){ $jsonData = \Bitrix\Main\Web\Json::decode($result['JSON_TXT']); if(!empty($jsonData['JSON_TXT']) && is_array($jsonData['JSON_TXT'])){ if( !empty($jsonData['JSON_TXT'][0]['DayLogistic']) ){ self::calculateConcrete($shipment); $res = true; } } } } // add if approved if(!$res && isset($jsonData['JSON_TXT'][0]['DayLogistic']) && $jsonData['JSON_TXT'][0]['DayLogistic'] == 0 && !empty($jsonData['JSON_TXT'][0]['PossibleDelivDates'])){ self::calculateConcrete($shipment); $res = true; } //} } self::$arResCompatible[$locationCode.'_'.$deliveryId] = $res; } return $res; } }