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/yandex.market/lib/data/ |
Upload File : |
<?php namespace Yandex\Market\Data; use Bitrix\Main; use Yandex\Market; class Weight { use Market\Reference\Concerns\HasLang; const UNIT_GRAM = 'g'; const UNIT_KILOGRAM = 'kg'; protected static function includeMessages() { Main\Localization\Loc::loadMessages(__FILE__); } public static function getUnitList() { return [ static::UNIT_GRAM, static::UNIT_KILOGRAM, ]; } public static function getBitrixUnit() { return static::UNIT_GRAM; } public static function getServiceUnit() { return static::UNIT_KILOGRAM; } public static function getUnitTitle($unit, $version = '') { $suffix = ''; if ((string)$version !== '') { $suffix = '_' . TextString::toUpper($version); } return static::getLang('DATA_WEIGHT_UNIT_' . TextString::toUpper($unit) . $suffix, null, $unit); } public static function format($value, $precision = 4) { return Number::format($value, $precision); } public static function convertUnit($weight, $fromUnit, $toUnit) { $fromRatio = static::getRatio($fromUnit); $toRatio = static::getRatio($toUnit); return $weight * ($fromRatio / $toRatio); } protected static function getRatio($unit) { switch ($unit) { case static::UNIT_GRAM: $result = 1; break; case static::UNIT_KILOGRAM: $result = 1000; break; default: throw new Main\ArgumentException('unknown unit'); break; } return $result; } }