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/OrdersTab/ |
Upload File : |
<?php namespace Wbs24\Ozonapinew\OrdersTab; use Bitrix\Main\{ Loader, SystemException }; use Wbs24\Ozonapinew\{ Main, Exception, Wrappers, Accounts, Api, Product }; class Split { use Exception; // trait use Accounts; // trait public const DONT_DIE = true; protected $accountIndex; public function __construct($accountIndex, $objects = []) { try { if (!Loader::IncludeModule('sale')) { throw new SystemException("Sale module isn`t installed"); } if (!Loader::IncludeModule('iblock')) { throw new SystemException("Iblock module isn`t installed"); } if (!Loader::IncludeModule('catalog')) { throw new SystemException("Catalog module isn`t installed"); } $this->main = $objects['Main'] ?? new Main(); $this->moduleId = $this->main->getModuleId(); $this->wrappers = new Wrappers($objects, self::DONT_DIE); $this->accountIndex = $accountIndex; $dependencies = $this->getDependencies($accountIndex); $this->Api = $objects['Api'] ?? new Api($dependencies); } catch (SystemException $exception) { $this->exceptionHandler($exception, self::DONT_DIE); $this->lastError = $exception->getMessage(); } } public function validateOrder($externalId): array { $validationPassed = false; $shippingInfo = $this->Api->getShippingInformation($externalId); $productsObject = []; if ($shippingInfo) { $products = $shippingInfo['products'] ?? []; $productsObject = $this->getProductsObject($products); $validationPassed = true; } return [ 'products' => $productsObject, 'validation' => $validationPassed ]; } protected function getProductsObject($products): array { $productsObject = []; foreach ($products as $product) { $productsObject[] = [ 'product_id' => $product['sku'], 'name' => $product['name'], 'quantity' => $product['quantity'], ]; } return $productsObject; } }