13 public static function convertByDefault(
float $price,
string $currency,
string $languageId =
''): string
15 if (empty($languageId))
17 $languageId = LANGUAGE_ID;
20 if ($languageId ===
'en' && $currency ===
"USD")
22 return "$".number_format($price, 2,
".",
",");
24 if ($languageId ===
'en' && $currency ===
"EUR")
26 return number_format($price, 2,
".",
",").
" €";
28 if ($languageId ===
'de' && $currency ===
"EUR")
30 return number_format($price, 2,
",",
".").
" €";
32 if ($languageId ===
'la' && $currency ===
"USD")
34 return "$".number_format($price, 2,
".",
",");
36 if ($languageId ===
'br' && $currency ===
"BRL")
38 return "R$".number_format($price, 2,
",",
".");
40 if ($languageId ===
'fr' && $currency ===
"EUR")
42 return number_format($price, 2,
".",
",").
" €";
44 if ($languageId ===
'it' && $currency ===
"EUR")
46 return number_format($price, 2,
",",
".").
" €";
48 if ($languageId ===
'pl' && $currency ===
"PLN")
50 return number_format($price, 2,
",",
" ").
" ¤";
52 if ($languageId ===
'tr' && $currency ===
"TRY")
54 return number_format($price, 2,
",",
".").
"₺";
56 if ($languageId ===
'sc' && $currency ===
"CNY")
58 return "¥".number_format($price, 2,
".",
"");
60 if ($languageId ===
'tc' && $currency ===
"TWD")
62 return "NT$;".number_format($price, 2,
".",
",");
64 if ($languageId ===
'ja' && $currency ===
"JPY")
66 return number_format($price, 2,
"",
",").
"¥";
68 if ($languageId ===
'vn' && $currency ===
"VND")
70 return number_format($price, 2,
",",
".").
" ₫";
72 if ($languageId ===
'id' && $currency ===
"IDR")
74 return "Rs. ".number_format($price, 2,
",",
".");
76 if ($languageId ===
'ms' && $currency ===
"MYR")
78 return "RM ".number_format($price, 2,
".",
",");
80 if ($languageId ===
'th' && $currency ===
"THB")
82 return "฿ ".number_format($price, 2,
".",
",");
84 if ($languageId ===
'en' && $currency ===
"IDR")
86 return "Rs. ".number_format($price, 2,
".",
",");
88 if ($languageId ===
'hi' && $currency ===
"IDR")
90 return "Rs. ".number_format($price, 2,
".",
",");
92 if ($languageId ===
'en' && $currency ===
"GBP")
94 return "£".number_format($price, 2,
".",
",");
96 if ($languageId ===
'la' && $currency ===
"MXN")
98 return "$".number_format($price, 2,
",",
".");
100 if ($languageId ===
'la' && $currency ===
"COP")
102 return "$".number_format($price, 2,
",",
".");
105 return "$".number_format($price, 2,
",",
".");
112 if (Loader::includeModule(
'currency') && Loader::includeModule(
'bitrix24'))
114 $currentAreaConfig = \CBitrix24::getCurrentAreaConfig();
115 $currentAreaConfig[
'CURRENCY'] = $currency;
117 $langSetting = \CCurrencyLang::GetByID($currentAreaConfig[
'CURRENCY'], $currentAreaConfig[
"LANGUAGE_ID"]);
121 isset($formatSetting[
"DECIMALS"])
122 && isset($formatSetting[
"DECIMAL_SEPARATOR"])
123 && isset($formatSetting[
"THOUSANDS_SEPARATOR"])
124 && isset($formatSetting[
"FORMAT_STRING"])
127 $formatSetting[
"THOUSANDS_SEP"] = $formatSetting[
"THOUSANDS_SEPARATOR"];
128 $formatSetting[
"DEC_POINT"] = $formatSetting[
"DECIMAL_SEPARATOR"];
130 return \CCurrencyLang::formatValue($price, $formatSetting);
133 isset($langSetting[
"DECIMALS"])
134 && isset($langSetting[
"DEC_POINT"])
135 && isset($langSetting[
"THOUSANDS_SEP"])
136 && isset($langSetting[
"FORMAT_STRING"])
139 return \CCurrencyLang::formatValue($price, $langSetting);
151 $apiCurrencyFormat = Option::get(
'bitrix24',
'currency_patterns_from_api',
'');
153 if ($apiCurrencyFormat !==
'')
155 $resultOption = Json::decode($apiCurrencyFormat);
157 isset($resultOption[
'time'])
158 && isset($resultOption[
'currencyFormat'])
159 && (((
int)$resultOption[
'time'] + 60*60) > time())
162 return $resultOption[
'currencyFormat'];
167 if (isset($langSetting[
'ID']) && isset($langSetting[
'LANGUAGE_ID']) && isset($langSetting[
'CURRENCY']))
169 $locationAreaId = $langSetting[
'ID'];
170 $languageId = $langSetting[
'LANGUAGE_ID'];
171 $currencyCode = $langSetting[
'CURRENCY'];
172 $url =
'https://util.1c-bitrix.ru/b24/catalog/get.php?currencyCode=' . $currencyCode .
'&productType=CLOUD'
173 .
'&locationAreaId=' . $locationAreaId .
'&languageId=' . $languageId .
'&requestData=formatting|patterns'
176 $resultRequest = $httpClient->get($url);
179 if ($httpClient->getStatus() === 200)
183 $resultDecode = Json::decode($resultRequest);
190 !empty($resultDecode[
"result"][
"formatting"])
191 && is_array($resultDecode[
"result"][
"formatting"])
194 $result = $resultDecode[
"result"][
"formatting"][
"separators"];
195 $result[
'FORMAT_STRING'] = $resultDecode[
"result"][
"patterns"][
"price"][
'per_period'];
196 $result[
'FORMAT_STRING'] = str_replace(
'#PRICE#',
'#', $result[
'FORMAT_STRING']);
197 $resultToOption = [
'time' => time(),
'currencyFormat' => $result];
198 Option::set(
'bitrix24',
'currency_patterns_from_api', JSON::encode($resultToOption));