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/ |
Upload File : |
<? namespace Lpost\Delivery; use \Bitrix\Main\Localization\Loc, \Bitrix\Main\Config\Option; Loc::loadMessages(__FILE__); class Settings { use Connector; use Base; private static $_instance = null; private $module_id; private $options; private function __clone() { } public function __wakeup() { } private function __construct() { $this->module_id = 'lpost.delivery'; $this->options = []; $tmpOptions = Option::getDefaults($this->module_id); $tmpOptions = array_keys($tmpOptions); foreach($tmpOptions as $nextOption) { $this->options[$nextOption] = Option::get($this->module_id, $nextOption); } $tmpOptions = Option::getForModule($this->module_id); $tmpOptions = array_keys($tmpOptions); foreach($tmpOptions as $nextOption) { if(empty($this->options[$nextOption])) { $this->options[$nextOption] = Option::get($this->module_id, $nextOption); } } } public static function getInstance() { if(self::$_instance != null) { return self::$_instance; } return new self; } /** * @return string url service */ public function getServiceUrl() { $url = defined("LPOST_API_URL") ? LPOST_API_URL : 'https://api.l-post.ru/'; return $this->options['test_mode'] == 'Y' ? 'https://apitest.l-post.ru/' : $url; } /** * @return bool ready or not for use */ public function isReady() { return empty($this->options['secret_key']) ? false : true; } public function getSecretKey() { return $this->options['secret_key']; } /** * @return array with all options this module */ public function getOptions() { return $this->options; } public function setOption($key, $value) { Option::set($this->module_id, $key, $value); } public function getOption($key) { return Option::get($this->module_id, $key); } /** * @return string name of module */ public function getModuleId() { return $this->module_id; } public function getReceivePoints() { $res = \Lpost\Delivery\Entity\ReceivePointsTable::getList([ 'order' => ['city_name' => 'asc', 'address' => 'asc'] ]); $rows = []; while($row = $res->fetch()) { $row['params'] = \Bitrix\Main\Web\Json::decode($row['params']); $rows[] = $row; } return $rows; } public function checkYandexKey($key) { $data = \Lpost\Delivery\Settings::getInstance()->request([ "lang" => "ru_RU", "apikey" => $key, "geocode" => "Moscow" ], "https://geocode-maps.yandex.ru/1.x/", "GET", "xml"); if(empty($data->statusCode[0])) { return true; } return false; } public function checkYandexKeySuggest($key) { $data = \Lpost\Delivery\Settings::getInstance()->request([ "lang" => "en_En", "apikey" => $key, "text" => 'moskva', ], "https://suggest-maps.yandex.ru/v1/suggest", "GET"); if(!empty($data['results'])) { return true; } return false; } public function checkOrderStatus($order) { \Bitrix\Main\Loader::includeModule('sale'); $options = $this->getOptions(); $settingStatusSend = empty($options['send_status_setting']) ? 'from' : $options['send_status_setting']; $settingStatus = empty($options['send_status']) ? 'N' : $options['send_status']; $currentStatus = $order->getField('STATUS_ID'); $arStatuses = []; $statuses = \CSaleStatus::GetList( [], [ "ID" => [ $currentStatus, $settingStatus ], "LID" => "ru", "TYPE" => "O" ], false, false, [ "ID", "NAME", "TYPE", "SORT" ] ); while($status = $statuses->GetNext()) { $arStatuses[$status["ID"]] = $status['SORT']; } if(!empty($arStatuses)) { return $settingStatusSend == 'from' ? $arStatuses[$currentStatus] >= $arStatuses[$settingStatus] : $arStatuses[$currentStatus] == $arStatuses[$settingStatus]; } return false; } } ?>