1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CurrencyFormat.php
См. документацию.
1<?php
2
4
10
12{
13 public static function convertByDefault(float $price, string $currency, string $languageId = ''): string
14 {
15 if (empty($languageId))
16 {
17 $languageId = LANGUAGE_ID;
18 }
19
20 if ($languageId === 'en' && $currency === "USD")
21 {
22 return "$".number_format($price, 2, ".", ",");
23 }
24 if ($languageId === 'en' && $currency === "EUR")
25 {
26 return number_format($price, 2, ".", ",")." &euro;";
27 }
28 if ($languageId === 'de' && $currency === "EUR")
29 {
30 return number_format($price, 2, ",", ".")." &euro;";
31 }
32 if ($languageId === 'la' && $currency === "USD")
33 {
34 return "$".number_format($price, 2, ".", ",");
35 }
36 if ($languageId === 'br' && $currency === "BRL")
37 {
38 return "R$".number_format($price, 2, ",", ".");
39 }
40 if ($languageId === 'fr' && $currency === "EUR")
41 {
42 return number_format($price, 2, ".", ",")." &euro;";
43 }
44 if ($languageId === 'it' && $currency === "EUR")
45 {
46 return number_format($price, 2, ",", ".")." &euro;";
47 }
48 if ($languageId === 'pl' && $currency === "PLN")
49 {
50 return number_format($price, 2, ",", " ")." &#164;";
51 }
52 if ($languageId === 'tr' && $currency === "TRY")
53 {
54 return number_format($price, 2, ",", ".")."&#8378;";
55 }
56 if ($languageId === 'sc' && $currency === "CNY")
57 {
58 return "&#x00A5;".number_format($price, 2, ".", "");
59 }
60 if ($languageId === 'tc' && $currency === "TWD")
61 {
62 return "NT$;".number_format($price, 2, ".", ",");
63 }
64 if ($languageId === 'ja' && $currency === "JPY")
65 {
66 return number_format($price, 2, "", ",")."&#165;";
67 }
68 if ($languageId === 'vn' && $currency === "VND")
69 {
70 return number_format($price, 2, ",", ".")." &#8363;";
71 }
72 if ($languageId === 'id' && $currency === "IDR")
73 {
74 return "Rs. ".number_format($price, 2, ",", ".");
75 }
76 if ($languageId === 'ms' && $currency === "MYR")
77 {
78 return "RM ".number_format($price, 2, ".", ",");
79 }
80 if ($languageId === 'th' && $currency === "THB")
81 {
82 return "&#3647; ".number_format($price, 2, ".", ",");
83 }
84 if ($languageId === 'en' && $currency === "IDR")
85 {
86 return "Rs. ".number_format($price, 2, ".", ",");
87 }
88 if ($languageId === 'hi' && $currency === "IDR")
89 {
90 return "Rs. ".number_format($price, 2, ".", ",");
91 }
92 if ($languageId === 'en' && $currency === "GBP")
93 {
94 return "&#163;".number_format($price, 2, ".", ",");
95 }
96 if ($languageId === 'la' && $currency === "MXN")
97 {
98 return "$".number_format($price, 2, ",", ".");
99 }
100 if ($languageId === 'la' && $currency === "COP")
101 {
102 return "$".number_format($price, 2, ",", ".");
103 }
104
105 return "$".number_format($price, 2, ",", ".");
106 }
107
108 public static function convertBySettings(float $price, string $currency): string
109 {
110 $formatSetting = [];
111 $langSetting = [];
112 if (Loader::includeModule('currency') && Loader::includeModule('bitrix24'))
113 {
114 $currentAreaConfig = \CBitrix24::getCurrentAreaConfig();
115 $currentAreaConfig['CURRENCY'] = $currency;
116 $formatSetting = self::getFormatFromApi($currentAreaConfig);
117 $langSetting = \CCurrencyLang::GetByID($currentAreaConfig['CURRENCY'], $currentAreaConfig["LANGUAGE_ID"]);
118 }
119
120 if (
121 isset($formatSetting["DECIMALS"])
122 && isset($formatSetting["DECIMAL_SEPARATOR"])
123 && isset($formatSetting["THOUSANDS_SEPARATOR"])
124 && isset($formatSetting["FORMAT_STRING"])
125 )
126 {
127 $formatSetting["THOUSANDS_SEP"] = $formatSetting["THOUSANDS_SEPARATOR"];
128 $formatSetting["DEC_POINT"] = $formatSetting["DECIMAL_SEPARATOR"];
129 $formatSetting['CURRENCY'] = $currency;
130
131 return \CCurrencyLang::formatValue($price, $formatSetting);
132 }
133 elseif (
134 isset($langSetting["DECIMALS"])
135 && isset($langSetting["DEC_POINT"])
136 && isset($langSetting["THOUSANDS_SEP"])
137 && isset($langSetting["FORMAT_STRING"])
138 )
139 {
140 $langSetting['CURRENCY'] = $currency;
141 return \CCurrencyLang::formatValue($price, $langSetting);
142 }
143 else
144 {
145 return self::convertByDefault($price, $currency);
146 }
147
148 }
149
150 public static function getFormatFromApi(array $langSetting): array
151 {
152 $result = [];
153 $apiCurrencyFormat = Option::get('bitrix24', 'currency_patterns_from_api', '');
154
155 if ($apiCurrencyFormat !== '')
156 {
157 $resultOption = Json::decode($apiCurrencyFormat);
158 if (
159 isset($resultOption['time'])
160 && isset($resultOption['currencyFormat'])
161 && (((int)$resultOption['time'] + 60*60) > time())
162 )
163 {
164 return $resultOption['currencyFormat'];
165 }
166 }
167
168 $httpClient = new HttpClient();
169 if (isset($langSetting['ID']) && isset($langSetting['LANGUAGE_ID']) && isset($langSetting['CURRENCY']))
170 {
171 $locationAreaId = $langSetting['ID'];
172 $languageId = $langSetting['LANGUAGE_ID'];
173 $currencyCode = $langSetting['CURRENCY'];
174
175 $url = Main\Application::getInstance()->getLicense()->getDomainStoreLicense()
176 . '/b24/catalog/get.php?currencyCode=' . $currencyCode . '&productType=CLOUD'
177 . '&locationAreaId=' . $locationAreaId . '&languageId=' . $languageId . '&requestData=formatting|patterns'
178 ;
179
180 $resultRequest = $httpClient->get($url);
181 if ($resultRequest)
182 {
183 if ($httpClient->getStatus() === 200)
184 {
185 try
186 {
187 $resultDecode = Json::decode($resultRequest);
188 }
189 catch (ArgumentException $e)
190 {
191 }
192
193 if (
194 !empty($resultDecode["result"]["formatting"])
195 && is_array($resultDecode["result"]["formatting"])
196 )
197 {
198 $result = $resultDecode["result"]["formatting"]["separators"];
199 $result['FORMAT_STRING'] = $resultDecode["result"]["patterns"]["price"]['per_period'];
200 $result['FORMAT_STRING'] = str_replace('#PRICE#', '#', $result['FORMAT_STRING']);
201 $resultToOption = ['time' => time(), 'currencyFormat' => $result];
202 Option::set('bitrix24', 'currency_patterns_from_api', JSON::encode($resultToOption));
203 }
204 }
205 }
206 }
207
208 return $result;
209 }
210
211}
static getInstance()
Определения application.php:98
Определения loader.php:13
Определения json.php:9
static convertBySettings(float $price, string $currency)
Определения CurrencyFormat.php:108
static getFormatFromApi(array $langSetting)
Определения CurrencyFormat.php:150
static convertByDefault(float $price, string $currency, string $languageId='')
Определения CurrencyFormat.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$currency
Определения template.php:266
$url
Определения iframe.php:7