Changing the currency icon in Bitrix
The last notes
All English-language materials have been translated fully automatically using the Google service
The question often arises of replacing the classic price display with your own. If you want to do this throughout the site , then go to Settings-> Currencies-> List of currencies
. Go to the Language settings
tab and in the "Format string for displaying currency:"
fields of the corresponding languages, change rub.
to the sign we need
Programmatically change the currency icon in the old template basket
In our component template sale.basket.basket
, find the file basket_items.php
. For other sections of the basket, edit other files. Somewhere in the beginning, we write, relying on our currencies:
$ currency = $ _COOKIE ['currency']; // Take the current currency from cookies
// Write the currency icon to the $ pound variable
if ($ currency == 'DKK')
$ pound = 'D.Kr.';
if ($ currency == 'SEK')
$ pound = 'S.Kr.';
if ($ currency == 'NOK')
$ pound = 'N.Kr.';
// Connect the module for cost conversion
CModule :: IncludeModule ('currency'); </code> </pre>
<pre><code> // Display in hidden inputs the currency icon and the conversion factor from the base currency (in my case, the base "GBP").
// These lines are needed to recalculate the prices in the basket using ajax. Ajax needs to be edited separately with great pain. I will not quote here.
<input id = "currencytext" type = "text" hidden value = "<? = $ pound?>" />
<input id = "currencyrate" type = "text" hidden value = "<? = CCurrencyRates :: GetConvertFactor ($ currency," GBP ");?>">
Next, where there is a price display in the template, write this type of code
if ($ arItem ["CURRENCY"]! = $ currency) {// If we switched the currency from the base
// Convert the unformatted price, write it to $ intotal
$ intotal = CCurrencyRates :: ConvertCurrency ($ arItem ["PRICE"], "GBP", $ currency);
// Remove unnecessary characters, leave 2 characters after the point
$ intotal2 = substr ($ intotal, 0, strripos ($ intotal, '.') + 3);
// Display the new formatted value in $ currency
echo $ pound. ' '.intotal2
}
// If the currency is base, then we can immediately display the formatted price
else {
echo $ arItem ["PRICE_FORMATED"]
}?>
Comments