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/wbs24.ozonapinew/lib/ |
Upload File : |
<?php namespace Wbs24\Ozonapinew; use Bitrix\Main\Loader; use Bitrix\Main\SystemException; class TrackNumber { use Exception; // trait protected $allowSendTrackNumber; protected const NEED_STATUS = 'delivering'; public function __construct($objects = []) { try { $this->wrappers = new Wrappers($objects); $this->main = $objects['Main'] ?? new Main(); $this->moduleId = $this->main->getModuleId(); $this->allowSendTrackNumber = ($this->wrappers->Option->get($this->moduleId, 'allowSendTrackNumber') == 'Y'); $this->propertyOfUpdateTrackNumber = $this->wrappers->Option->get($this->moduleId, 'propertyOfUpdateTrackNumber'); if (!Loader::IncludeModule('sale')) { throw new SystemException("Sale module isn`t installed"); } } catch (SystemException $exception) { $this->exceptionHandler($exception); } } public function getIfNeedUpdate($orderId, $shippingInfo) { $track = ''; $orderTrack = $this->getFromOrder($orderId); $needUpdate = $this->isNeedUpdate($orderTrack, $shippingInfo); if ($needUpdate) $track = $orderTrack; return $track; } protected function getFromOrder($orderId) { return ($this->propertyOfUpdateTrackNumber == 'default') ? $this->getTrackNumberFromShipment($orderId) : $this->getTrackNumberFromOrder($orderId); } protected function getTrackNumberFromShipment($orderId) { $trackingNumber = ''; $order = $this->wrappers->Order->load($orderId); $shipmentCollection = $order->getShipmentCollection(); foreach($shipmentCollection as $shipment) { if($shipment->isSystem()) continue; $trackingNumber = $shipment->getField('TRACKING_NUMBER'); } return $trackingNumber; } protected function getTrackNumberFromOrder($orderId) { $trackNumberValue = ''; $order = $this->wrappers->Order->load($orderId); $propertyCollection = $order->getPropertyCollection(); $trackNumberProp = $propertyCollection->getItemByOrderPropertyId($this->propertyOfUpdateTrackNumber); if ($trackNumberProp) $trackNumberValue = $trackNumberProp->getValue(); return $trackNumberValue; } protected function isNeedUpdate($orderTrack, $shippingInfo) { if (!$orderTrack) return false; if (!$this->allowSendTrackNumber) return false; $needUpdate = false; $marketplaceTrack = $this->getFromMarketplace($shippingInfo); if ($orderTrack != $marketplaceTrack) { $needUpdate = true; } return $needUpdate; } protected function getFromMarketplace($shippingInfo) { return $shippingInfo['tracking_number']; } }