Changing the currency icon in Bitrix
Rus
Eng
Изменяем значок валюты в Битрикс
I solve complex technical challenges for Bitrix and 1C—ranging from auditing existing code to configuring complex integrations—with a guarantee of results.
Recommended

Website hosting

If you are choosing hosting for your project, I recommend Timeweb. Modern infrastructure, a wide range of plans from starter options to high-load VPS, and responsive tech support that actually helps instead of sending template replies. I host some of my own projects there and recommend it to my clients.

Go to site Affiliate link. The price remains the same for you.

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"]
}?>  
Aleksandr Tichiy
Author

Aleksandr Tichiy

Fullstack developer · 1C-Bitrix

I build and modernize online stores and corporate portals on 1C-Bitrix. Integrations with 1C, high-load performance, 152-FZ compliance. Writing about architecture and e-commerce.


Comments

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Please message me to discuss the task. I work remotely and officially (as a self-employed professional); my hourly rate is 1,800 RUB, and I can dedicate 3–4 hours a day to the project. I respond quickly, and the consultation is free.

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site