Multiple currencies in the Opencart product card
Multiple currencies in the Opencart product card
πŸ’Ό Creation of modern websites of any complexity. | πŸ‘Œ WEB-UKRAINE.COM

Multiple currencies in the Opencart product card

5/54 ratings

Welcome to the pages of our site.

Very often customers who use several currencies on their site ask themselves how to display the price of the goods in just a few currencies in the product card.

By default, opencart gives the opportunity to change the currency only in the header throughout the site, but very many users do not know how to select the desired currency and switch the site to it, so today we'll talk about how to visually display prices in several currencies immediately near the main price.

An example of what will eventually turn out you can look at the photo below:

As I wrote before, opencart by default does not provide the display of different currencies in the product card, but the convert function is present in the currency class:

This function is used by the engine when you change the currency from the store's header, the conversion from the hryvnia to the dollar, for example, is as follows:

Well, with the basic principles figured out now let's get down to practice and deduce different currencies near the price.

First of all I want to note that we will perform all actions on the default template, and by default we have the Hryvnia currency, and additional currencies are the ruble and the dollar, so we will show them.

1. We display different currencies in the product card:

Changes will be made in two files:

And so open the product.tpl file and look for the code that is responsible for displaying the price, namely:

And after it we add the code:

If you need to display just one thing then just specify the required drain.

Thus, we added a price output for the standard price in which there are no shares.

Now we need to add the output for the prices in which the auction price is indicated, in the same file we find the code:

And after it we add:

We finished with the product.tpl file, thus we added the output of the price in two additional currencies.

Now we need to edit the product.php file.

And so open it and look for the code:

Which is responsible for our price by default and after it we add:

Thus, we indicated that we need to display an additional price, but this only again applies only to the price that is without a stock, and that additional currencies are shown also in the products with the share we find the code:

And after it we add:

In these lines of code, the round (...) function allows you to round prices to 2, you can also specify 0 if you do not want to display a penny after the comma.

That's basically all, now we have in the product card will display the value of the goods both in the default price (hryvnia) and in the additional currencies the dollar and ruble are an example in the photo above.

And so with the card of the goods we have finished, but we have many other places where the price is displayed, let's consider other places of output of the currency of prices.

Let's display several of our currencies in modules, for example, novelties, recommended, sales hits, etc. ... for all of them the principle is the same, for this we take as a basis the module of the novelty, for all other actions the same.



2. We show different currencies prices in modules (Latest)

Changes will be made in two files:

First of all we open the latest.tpl file and in it we indicate the place where we will display our price, we find the first code:

And after it we add the following:

Thus, you have displayed a display of the additional price of the currency in the place of the module we need, for a price that does not have a stock, now we find the piece of code that is responsible for the auction price:

And after it we add the currencies we need:

All now you can proceed to the controller itself, that is, open the latest.php file, and in it we search for the output of the price, after which we also need to add a piece of the code we need:

And so we find:

And then we add the code:

Now we need to do everything the same for the auction price, we find the code:

And after it we add:

Well, in principle, that's all, now you have a module in the novelty will display the price in different currencies, other modules do by analogy.

IMPORTANT: In some other modules, use $product_info instead of $result all the rest by analogy.

Now we need to make it possible to display currencies in categories, search, share page, manufacturers, etc ...

For example, we take the page of product categories, the rest do the same.

And so let's make a display of the currency in the category of goods.



3. We show different currencies prices in the category of goods

In the category we will use a slightly different code to display the additional currency, but there's nothing too complicated.

Changes will be made in two files, namely:

Well, let's begin.

Open the category.tpl file and look for the output of the product price without stock:

After this code we add:

To display currency to commodities with shares, look for the code:

And after it we add:

All with the category.tpl file is finished, now proceed to the controller, and so open the category.php file and look for the code:

And after it we add:

There is a little lower after the code:

Adding:

Now all the same we need to add for the product with promotional price, we are looking for the code below:

And after it we add:

And a little lower after the code:

Add the following:

Further we fall below and we search for the code:

And right after it we add:

Well, in the prince and everything, now we have in the category in the list of goods next to the price will be displayed an additional currency, with search pages, producers, shares, etc. ... we do everything by analogy.

Try common, test and everything will work out, and if that does not work ask in the comments.

You may also like

No Comment

You can post first response comment.

Leave a Reply

Π’ΠΈΠ±Π΅Ρ€Ρ–Ρ‚ΡŒ спосіб спілкування
Звязатися Π· Π½Π°ΠΌΠΈ!
Ми Π³ΠΎΡ‚ΠΎΠ²Ρ– Π΄ΠΎ Π΄Ρ–Π°Π»ΠΎΠ³Ρƒ.