- Posts: 16
- Thank you received: 0
Display all Currency Prices in various views?
- WillPatterson
-
Topic Author
- Offline
I am in the process of creating a shop which has 4 currencies on it - american dollar, british pound, euro and the Brazilian real. I know there is a built in convertor for the various currencies but i want to then display the current currency values on each of the product detail pages and the category view.
So it should display something like
$220.00 each
R$ 440.00
€180.00
£160.00
thanks.
Please Log in or Create an account to join the conversation.
To display the 4 currencies on a product view or listing view, you just have to edit the view "product / listing_price".
And in this view, copy and paste the following code:
Replace the "$price->price_currency_id" by the currency id wanted, you can find the currencies id in HikaShop > System > Currencies.
You will have:
Please Log in or Create an account to join the conversation.
- WillPatterson
-
Topic Author
- Offline
- Posts: 16
- Thank you received: 0
Please Log in or Create an account to join the conversation.
If you need this display everywhere, you can replace all the occurence of "echo $this->currencyHelper->format($price->price_value_with_tax,$price->price_currency_id);".
Else it depends of your options.
If you display the price with tax, display "$price->price_value_with_tax" else "$price->price_value".
Please Log in or Create an account to join the conversation.
- WillPatterson
-
Topic Author
- Offline
- Posts: 16
- Thank you received: 0
Please Log in or Create an account to join the conversation.
- WillPatterson
-
Topic Author
- Offline
- Posts: 16
- Thank you received: 0
Please Log in or Create an account to join the conversation.
Here is the solution, replace the line:
By:
Don't forget to update your currencies rates in HikaShop > System > Currencies, update rates in the toolbar.
Please Log in or Create an account to join the conversation.
- WillPatterson
-
Topic Author
- Offline
- Posts: 16
- Thank you received: 0
I have changed the code a little to make it more obvious what each is to:
$dollarId = 2;
$brazilId = 28;
$euroId = 1;
$britId = 4;
$dollarPrice = $this->currencyHelper->convertUniquePrice($price->price_value, $price->price_currency_id, $dollarId);
$brazilPrice = $this->currencyHelper->convertUniquePrice($price->price_value, $price->price_currency_id, $brazilId);
$euroPrice = $this->currencyHelper->convertUniquePrice($price->price_value, $price->price_currency_id, $euroId);
$britPrice = $this->currencyHelper->convertUniquePrice($price->price_value, $price->price_currency_id, $britId);
echo $this->currencyHelper->format($dollarPrice,$dollarId)."<br/>";
echo $this->currencyHelper->format($brazilPrice,$brazilId)."<br/>";
echo $this->currencyHelper->format($euroPrice,$euroId)."<br/>";
echo $this->currencyHelper->format($britPrice,$britId)."<br/>";
However it seems to put the currency icon in the wrong order (before the line return) so i get the attached picture
If i can get this solved i'd like to be able to wrap the currency icons in a class and the converted prices in another class so i can style them all individually, if you can point me in the right direction to doing this it would be appreciated and i am very thankful for all your assistance with this, regards...
Please Log in or Create an account to join the conversation.
To add classes on the symbol and on the value, you will have to use the PHP function str_replace() like:
Be careful on the span order, because some currency symbol are before the value and other after.
Please Log in or Create an account to join the conversation.
- WillPatterson
-
Topic Author
- Offline
- Posts: 16
- Thank you received: 0
Please Log in or Create an account to join the conversation.
- WillPatterson
-
Topic Author
- Offline
- Posts: 16
- Thank you received: 0
Please Log in or Create an account to join the conversation.
Are you using the code:
Because in this code, you have to add the currency symbol after "<span class=\'yourClass\'>" like:
For the BRL, with the str_replace you can change it with R$ like:
Please Log in or Create an account to join the conversation.
- WillPatterson
-
Topic Author
- Offline
- Posts: 16
- Thank you received: 0
I want to end the currency symbol class after the symbol so i can style it differently to the actual numerical value so i guess this should just be something like:
echo "<span class='currValue'>".str_replace('$','<span class=\'yourClass\'>$'"</span>",$this->currencyHelper->format($britPrice,$britId))."</span>" ;
thanks again for your help
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.