Jump to content

how can i publish the price in 2 different currencies at same time?


sbhard

Recommended Posts

how can i do something like this?post-343850-0-13552800-1337644881_thumb.jpg
i mean, how can i show 2 different currencies at same time in one article?
Thank you for your answers!

 

SOLVED!

i decided to use vekia's module: show price in many currencies. Mainly because of fact that it works well with quantity discounts (when i increase / decrease quantity of product) and combinations that affects price.

Link to comment
Share on other sites

  • 4 months later...

Hi again

 

Create this file override/controllers/ProductController.php

 

Put this code in the file :

<?php
class ProductController extends ProductControllerCore{
   public function displayContent()
{
    global $currency;
    $second_currency = 'USD';

    $productPriceWithTax = Product::getPriceStatic($this->product->id, true, NULL, 6);
   if (Product::$_taxCalculationMethod == PS_TAX_INC)
 $productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
   $productPriceWithoutEcoTax = (float)($productPriceWithTax - $this->product->ecotax);

    $current_currency = $currency->iso_code;
    $default_currency = Currency::getDefaultCurrency()->iso_code;
    $currency_array =   Currency::getCurrencies($object = false, $active = 1);

    if ($current_currency == $default_currency){
	    foreach ($currency_array as $arr){
		    if ((string)$arr['iso_code'] == $second_currency ){
		    $second_currency_price = Tools::ps_round($productPriceWithoutEcoTax * (float)$arr['conversion_rate'],2);
		    }
	    }

    }
   self::$smarty->assign('second_currency_price',$second_currency_price.' '.$second_currency);
   parent::displayContent();
   }
}

 

In product.tpl modify

{if $priceDisplay >= 0 && $priceDisplay <= 2}
										    <span id="our_price_display">{convertPrice price=$productPrice}</span>

To

{if $priceDisplay >= 0 && $priceDisplay <= 2}
										    {$second_currency_price}/
  <span id="our_price_display">{convertPrice price=$productPrice}</span>

 

I choosed USD to be the second currency ($second_currency='USD') , I have then this display 349.02 USD/ 259,53 € TTC.

 

Regards

Make backup before modifications.

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 months later...

A simpler way might be to use the smarty modifier "convertAndFormatPrice". It takes two parameters: the price and the id of a currency. You'll need to know the id of the currency you want to use as the second one, but that shouldn't be too hard to figure out....

 

The format for modifiers is:

 

{$first_param|modifier-name:param2:param3:....}

 

It would appear that all you need to do is use the following in your template:

 

{if $priceDisplay >= 0 && $priceDisplay <= 2}
 <span id="our_price_display">{$productPrice|convertAndFormatPrice:2}/{convertPrice price=$productPrice}</span>

 

The above assumes that you non-default currency has an id of '2'.

 

EDIT: Sadly the function used in my original attempt only changes the currency display and not the actual price it would seem.... modified the code which should work now....

Edited by Paul C (see edit history)
Link to comment
Share on other sites

  • 2 months later...

Hi again

 

Create this file override/controllers/ProductController.php

 

Put this code in the file :

<?php
class ProductController extends ProductControllerCore{
public function displayContent()
{
	global $currency;
	$second_currency = 'USD';

	$productPriceWithTax = Product::getPriceStatic($this->product->id, true, NULL, 6);
if (Product::$_taxCalculationMethod == PS_TAX_INC)
 $productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
$productPriceWithoutEcoTax = (float)($productPriceWithTax - $this->product->ecotax);

	$current_currency = $currency->iso_code;
	$default_currency = Currency::getDefaultCurrency()->iso_code;
	$currency_array =   Currency::getCurrencies($object = false, $active = 1);

	if ($current_currency == $default_currency){
		foreach ($currency_array as $arr){
			if ((string)$arr['iso_code'] == $second_currency ){
			$second_currency_price = Tools::ps_round($productPriceWithoutEcoTax * (float)$arr['conversion_rate'],2);
			}
		}

	}
self::$smarty->assign('second_currency_price',$second_currency_price.' '.$second_currency);
parent::displayContent();
}
}

 

In product.tpl modify

{if $priceDisplay >= 0 && $priceDisplay <= 2}
											<span id="our_price_display">{convertPrice price=$productPrice}</span>

To

{if $priceDisplay >= 0 && $priceDisplay <= 2}
											{$second_currency_price}/
  <span id="our_price_display">{convertPrice price=$productPrice}</span>

 

I choosed USD to be the second currency ($second_currency='USD') , I have then this display 349.02 USD/ 259,53 € TTC.

 

Regards

Make backup before modifications.

 

Hi,

can you show how will look this code for PS 1.5.4.x?

Edited by galactic (see edit history)
Link to comment
Share on other sites

  • 7 months later...

Hi all

 

I was looking for solution to display dual currency in PrestaShop - its actual for European Union countries who changes national currency to Euro and must display prices at least half year before and after in TWO currencies - national and Eur.

After reading topics I was trying other metods but nothing works. And after all I found super simple solution - no changes to controllers or so:

 

Just add:

 | €{round($productPrice*0.2896, 2)}

After:

<span id="our_price_display">{convertPrice price=$productPrice}</span>

In: product.tpl

 

You just need to change RATE of national currency to other currency. In my case its LTL:EUR=0.2896

 

Thats it :) 

  • Like 3
Link to comment
Share on other sites

  • 4 months later...

A simpler way might be to use the smarty modifier "convertAndFormatPrice". It takes two parameters: the price and the id of a currency. You'll need to know the id of the currency you want to use as the second one, but that shouldn't be too hard to figure out....

 

The format for modifiers is:

 

{$first_param|modifier-name:param2:param3:....}

 

It would appear that all you need to do is use the following in your template:

 

{if $priceDisplay >= 0 && $priceDisplay <= 2}
  <span id="our_price_display">{$productPrice|convertAndFormatPrice:2}/{convertPrice price=$productPrice}</span>
The above assumes that you non-default currency has an id of '2'.

 

EDIT: Sadly the function used in my original attempt only changes the currency display and not the actual price it would seem.... modified the code which should work now....

 

But this doesn't work when product has combinations

Link to comment
Share on other sites

  • 1 month later...

Hi all

 

I was looking for solution to display dual currency in PrestaShop - its actual for European Union countries who changes national currency to Euro and must display prices at least half year before and after in TWO currencies - national and Eur.

After reading topics I was trying other metods but nothing works. And after all I found super simple solution - no changes to controllers or so

This solution worked great but only added a second currency to product details page. Frontpage still has default currency. Any ideas what to change in order to add a second currency on product list, in a cart and so on?

Link to comment
Share on other sites

  • 2 weeks later...

I would also be grateful if someone could answer this question about 2 currencies at the same time (It's for European Union law to have 2 currencies). Maybe there is a module for this for those who do not know how to code? Thanks

Link to comment
Share on other sites

    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

use this in classes/controllers/frontController.php

 

then in template file use: (in product-list.tpl)

{convertPrice price=FrontController::ConvertPrice($product.price,$cookie->id_currency,2)}

in product.tpl

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

2 is an id of currency you want to display.

 

Please note that this modification does not change the value of second price if you will switch an attribute! (for example if your attribute has a price impact)

module that works well with attributes change and quantitiy discount is here show price in 2 different currencies

Link to comment
Share on other sites

So I should change this one below to yours? 

public static function getCurrentCustomerGroups()

{
if (!Group::isFeatureActive())
return array();
 
$context = Context::getContext();
if (!isset($context->customer) || !$context->customer->id)
return array();
 
if (!is_array(self::$currentCustomerGroups))
{
self::$currentCustomerGroups = array();
$result = Db::getInstance()->executeS('SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.(int)$context->customer->id);
foreach ($result as $row)
self::$currentCustomerGroups[] = $row['id_group'];
}
return self::$currentCustomerGroups;



Where (which line and wether do I delete sth or overwrite) do I put this code?

in template file use: (in product-list.tpl)

{convertPrice price=FrontController::ConvertPrice($product.price,$cookie->id_currency,2)}

And this: 

 

in product.tpl

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

2 is an id of currency you want to display.

Thanks!

Link to comment
Share on other sites

in controller (frontController.php) you can:

- create an override

 

or just change original file, paste function:

    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

before last closing bracket.

 

then you will be able to use smarty code:
 

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

there, where you want to display other currency price

Link to comment
Share on other sites

in controller (frontController.php) you can:

- create an override

 

or just change original file, paste function:

    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

before last closing bracket.

 

then you will be able to use smarty code:

 

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

there, where you want to display other currency price

when i do all and upload to server my site is down, not showing , only shows white list, wish solutions?

Link to comment
Share on other sites

  • 2 weeks later...

Smarty code works. I works great in product.tpl but in the product-list.tpl not really. I can see only $0.00 next to all listed products original price.

 

Here is how I pasted the smarty code:

						<a class="quick-view" href="{$product.link|escape:'html':'UTF-8'}" rel="{$product.link|escape:'html':'UTF-8'}">
							<span>{l s='Quick view'}</span>
						</a>
						{/if}
						{if (!$PS_CATALOG_MODE AND ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
							<div class="content_price" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
								{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}
									<span itemprop="price" class="price product-price">
										{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}
                                <!-- EDVINAS keiciam ir cia valiuta i dvi valiutas QUICK VIEW vieta-->   
                                <font size="2">|{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,1)}</font>
                                 <!-- Edvinas. -->
									</span>
                                    
                                 
                                    
									<meta itemprop="priceCurrency" content="{$currency->iso_code}" />
									{if isset($product.specific_prices) && $product.specific_prices && isset($product.specific_prices.reduction) && $product.specific_prices.reduction > 0}
										{hook h="displayProductPriceBlock" product=$product type="old_price"}
										<span class="old-price product-price">
											{displayWtPrice p=$product.price_without_reduction}
										</span>
										{if $product.specific_prices.reduction_type == 'percentage'}
											<span class="price-percent-reduction">-{$product.specific_prices.reduction * 100}%</span>
										{/if}
									{/if}
									{hook h="displayProductPriceBlock" product=$product type="price"}
									{hook h="displayProductPriceBlock" product=$product type="unit_price"}
								{/if}
							</div>
						{/if}

in controller (frontController.php) you can:

- create an override

 

or just change original file, paste function:

    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

before last closing bracket.

 

then you will be able to use smarty code:
 

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

there, where you want to display other currency price

 

Link to comment
Share on other sites

one more question.. Tax is included in all prices but not in second price on product page... is it possible to fix some how this?

 

product-list.tpl use $product as an array not as an object

it means taht in product-list.tpl you have to use $product.price instead of $product->price

 

 

Thanks  :D

Link to comment
Share on other sites

one more question.. Tax is included in all prices but not in second price on product page... is it possible to fix some how this?

 

on product page you can use $productPrice or $productPriceWithoutReduction

 

reductions means taxes in this case?

Link to comment
Share on other sites

no, there is how I changed smarty to display two curencies on product page (product.tpl)

<p class="our_price_display">
   {if $priceDisplay >= 0 && $priceDisplay <= 2}
         <span id="our_price_display" class="price">{convertPrice price=$productPrice}</span>
         <span style="color:#c60200; font-size:16px;"> / </span>
         <span id="our_price_display_eu" class="price">{($productPrice * $currencies[0].conversion_rate)|round:"2"}</span>
         <span style="color:#c60200; font-size:16px;">{l s='eu'}</span>
         {if $tax_enabled  && ((isset($display_tax_label) && $display_tax_label == 1) OR !isset($display_tax_label))}
                 {if $priceDisplay == 1}{l s='tax excl.'}{else}{l s='tax incl.'}{/if}
         {/if}
   {/if}
</p>

I also modify product.js

$('#our_price_display').text(our_price);
$('#our_price_display_eu').text(Number(our_price_eu / 3.4528).toFixed(2));
$('#old_price_display').text(formatCurrency(productPriceWithoutReduction, currencyFormat, currencySign, currencyBlank));
$('#old_price_display_eu').text(Number(productPriceWithoutReduction / 3.4528).toFixed(2));

3.4528 is the official exchange rate, and in this way it works when there are several combinations of products.

 

sorry for my English :)

Link to comment
Share on other sites

no, there is how I changed smarty to display two curencies on product page (product.tpl)

<p class="our_price_display">
   {if $priceDisplay >= 0 && $priceDisplay <= 2}
         <span id="our_price_display" class="price">{convertPrice price=$productPrice}</span>
         <span style="color:#c60200; font-size:16px;"> / </span>
         <span id="our_price_display_eu" class="price">{($productPrice * $currencies[0].conversion_rate)|round:"2"}</span>
         <span style="color:#c60200; font-size:16px;">{l s='eu'}</span>
         {if $tax_enabled  && ((isset($display_tax_label) && $display_tax_label == 1) OR !isset($display_tax_label))}
                 {if $priceDisplay == 1}{l s='tax excl.'}{else}{l s='tax incl.'}{/if}
         {/if}
   {/if}
</p>

I also modify product.js

$('#our_price_display').text(our_price);
$('#our_price_display_eu').text(Number(our_price_eu / 3.4528).toFixed(2));
$('#old_price_display').text(formatCurrency(productPriceWithoutReduction, currencyFormat, currencySign, currencyBlank));
$('#old_price_display_eu').text(Number(productPriceWithoutReduction / 3.4528).toFixed(2));

3.4528 is the official exchange rate, and in this way it works when there are several combinations of products.

 

sorry for my English :)

Does all you change was product.tpl and product.js? I try the same, but nothing happen.

Link to comment
Share on other sites

Hi, Vekia,

 

Your method works fine. Just two things not exactly: 

1. in product page EURO price is calculated without taxes (I am using retail price without taxes, and added a 21% VAT tax rule for every product. For customers who must pay taxes (VAT) the price in my currency is shown right - including taxes. But in euros the price is shown excluding taxes - VAT) 

 

2. The calculated price should be round to decimals after comma. For example 125 Lt should be shown as 36.20 EUR. But instead it's shown 36 EUR. 

 

p.s.  I hope I have written quite understandable. Thanks for any help.

 

in controller (frontController.php) you can:

- create an override

 

or just change original file, paste function:

    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

before last closing bracket.

 

then you will be able to use smarty code:
 

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

there, where you want to display other currency price

Link to comment
Share on other sites

EDIT: oh my gush.. I've just got it how the smarty code works.. :D I was so stupid.. sorry. Everything works perfect. You just need to find places where to add the smarty code and change what price you want to convert.

 

Smarty code:

{convertPrice price=FrontController::ConvertPrice($productPrice,$cookie->id_currency,3)}

$productPrice is a product price tax included

$cookie-id_currency - no worries about it, just don't change it

number is a currency you want to see

 

and now.. If you want to see lets say shopping cart total price, change the $productPrice to $product.total_wt

 

I don't know how these things is called (maybe Vieka could tell us) but you can find them already on the code just use your brains if you don't know the code, experiment..

 

 

OLD:

2. problem I solved going to currencies and turning on to show the decimals. 

 

Hi, Vekia,

 

Your method works fine. Just two things not exactly: 

1. in product page EURO price is calculated without taxes (I am using retail price without taxes, and added a 21% VAT tax rule for every product. For customers who must pay taxes (VAT) the price in my currency is shown right - including taxes. But in euros the price is shown excluding taxes - VAT) 

 

2. The calculated price should be round to decimals after comma. For example 125 Lt should be shown as 36.20 EUR. But instead it's shown 36 EUR. 

 

p.s.  I hope I have written quite understandable. Thanks for any help.

Edited by gadnis (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...
    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

use this in classes/controllers/frontController.php

 

then in template file use: (in product-list.tpl)

{convertPrice price=FrontController::ConvertPrice($product.price,$cookie->id_currency,2)}

in product.tpl

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

2 is an id of currency you want to display.

 

 

hi vekia I am using it in shopping-cart.tpl, and I found this problem:

{if $cookie->id_currency != 1}
<span>({displayPrice price=FrontController::ConvertPrice($total_price,$cookie->id_currency,1)})</span>
{/if}

if 1 pound is 0.787600 euros
 
then 56 euros are 44,10 pounds
but 44,10 pounds are 55,99 euros
 
when I see total shopping cart in pounds the second price is 55,99 euros, not 56  :blink:
Link to comment
Share on other sites

Good morning

 

I try Vekia code, its working, but when i go from HP to am products or something else prices are different

 

In home page for e.g  Greita peržiūra1 199,96 LT |€ 347.53 right price. But when i click and redirect inside this product i see this 1 199,96 LT |€ 287.21. :D

 

Any sugestions ? UP@!@

Link to comment
Share on other sites

Hi again

 

Create this file override/controllers/ProductController.php

 

Put this code in the file :

<?php
class ProductController extends ProductControllerCore{
    public function displayContent()
{
	    global $currency;
	    $second_currency = 'USD';
	   
	    $productPriceWithTax = Product::getPriceStatic($this->product->id, true, NULL, 6);
    if (Product::$_taxCalculationMethod == PS_TAX_INC)
	 $productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
    $productPriceWithoutEcoTax = (float)($productPriceWithTax - $this->product->ecotax);
	   
	    $current_currency = $currency->iso_code;
	    $default_currency = Currency::getDefaultCurrency()->iso_code;
	    $currency_array =   Currency::getCurrencies($object = false, $active = 1);
	   
	    if ($current_currency == $default_currency){
		    foreach ($currency_array as $arr){
			    if ((string)$arr['iso_code'] == $second_currency ){
			    $second_currency_price = Tools::ps_round($productPriceWithoutEcoTax * (float)$arr['conversion_rate'],2);
			    }
		    }
		   
	    }
    self::$smarty->assign('second_currency_price',$second_currency_price.' '.$second_currency);
    parent::displayContent();
    }
}
In product.tpl modify

{if $priceDisplay >= 0 && $priceDisplay <= 2}
											    <span id="our_price_display">{convertPrice price=$productPrice}</span>
To

{if $priceDisplay >= 0 && $priceDisplay <= 2}
											    {$second_currency_price}/
	  <span id="our_price_display">{convertPrice price=$productPrice}</span>
I choosed USD to be the second currency ($second_currency='USD') , I have then this display 349.02 USD/ 259,53 € TTC.

 

Regards

Make backup before modifications.

 

 

 

Hi again

 

Create this file override/controllers/ProductController.php

 

Put this code in the file :

<?php
class ProductController extends ProductControllerCore{
    public function displayContent()
{
	    global $currency;
	    $second_currency = 'USD';
	   
	    $productPriceWithTax = Product::getPriceStatic($this->product->id, true, NULL, 6);
    if (Product::$_taxCalculationMethod == PS_TAX_INC)
	 $productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
    $productPriceWithoutEcoTax = (float)($productPriceWithTax - $this->product->ecotax);
	   
	    $current_currency = $currency->iso_code;
	    $default_currency = Currency::getDefaultCurrency()->iso_code;
	    $currency_array =   Currency::getCurrencies($object = false, $active = 1);
	   
	    if ($current_currency == $default_currency){
		    foreach ($currency_array as $arr){
			    if ((string)$arr['iso_code'] == $second_currency ){
			    $second_currency_price = Tools::ps_round($productPriceWithoutEcoTax * (float)$arr['conversion_rate'],2);
			    }
		    }
		   
	    }
    self::$smarty->assign('second_currency_price',$second_currency_price.' '.$second_currency);
    parent::displayContent();
    }
}
In product.tpl modify

{if $priceDisplay >= 0 && $priceDisplay <= 2}
											    <span id="our_price_display">{convertPrice price=$productPrice}</span>
To

{if $priceDisplay >= 0 && $priceDisplay <= 2}
											    {$second_currency_price}/
	  <span id="our_price_display">{convertPrice price=$productPrice}</span>
I choosed USD to be the second currency ($second_currency='USD') , I have then this display 349.02 USD/ 259,53 € TTC.

 

Regards

Make backup before modifications.

 

 

 

 

 

i'am don't find this lines :( where changed it? i add my  files from server, please see and ask me whats problem site is www.kvepinkis.lt

http://speedy.sh/B6ED5/product.tpl
http://speedy.sh/VRqHW/ProductController.php
Link to comment
Share on other sites

  • 4 weeks later...
    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

use this in classes/controllers/frontController.php

 

then in template file use: (in product-list.tpl)

{convertPrice price=FrontController::ConvertPrice($product.price,$cookie->id_currency,2)}

in product.tpl

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

2 is an id of currency you want to display.

 

 

Could you offer a solution working in PrestaShop 1.4?

Link to comment
Share on other sites

  • 2 weeks later...

It worked graet.

    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

use this in classes/controllers/frontController.php

 

then in template file use: (in product-list.tpl)

{convertPrice price=FrontController::ConvertPrice($product.price,$cookie->id_currency,2)}

in product.tpl

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

2 is an id of currency you want to display.

 

 But... combinations not working... :(

I tried solution from #32 post, but it didn't work for me. Is there any one who found universal or some how working solution to make combinations work. 

Any help is welcome.   

Link to comment
Share on other sites

Create this file override/controllers/ProductController.php

Put this code in the file : <?php
class ProductController extends ProductControllerCore{
public function displayContent()
{
     global $currency;
     $second_currency = 'USD';
    
     $productPriceWithTax
= Product::getPriceStatic($this->product->id, true, NULL, 6);
if (Product::$_taxCalculationMethod == PS_TAX_INC)
     $productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
$productPriceWithoutEcoTax = (float)($productPriceWithTax - $this->product->ecotax);
    
     $current_currency
= $currency->iso_code;
     $default_currency = Currency::getDefaultCurrency()->iso_code;
     $currency_array = Currency::getCurrencies($object = false, $active = 1);
    
    
if ($current_currency == $default_currency){
         foreach ($currency_array as $arr){
             if ((string)$arr['iso_code'] == $second_currency ){
             $second_currency_price = Tools::ps_round($productPriceWithoutEcoTax * (float)$arr['conversion_rate'],2);
             }
         }
        
    
}
self::$smarty->assign('second_currency_price',$second_currency_price.' '.$second_currency);
parent::displayContent();
}
} In product.tpl modify
{if $priceDisplay >= 0 && $priceDisplay <= 2}
                                             <span id="our_price_display">{convertPrice price=$productPrice}</span> To
{if $priceDisplay >= 0 && $priceDisplay <= 2}
                                             {$second_currency_price}/
     <span id="our_price_display">{convertPrice price=$productPrice}</span> I choosed USD to be the second currency ($second_currency='USD') , I have then this display 349.02 USD/ 259,53 € TTC.

Regards
Make backup before modifications.

 

 

 

math_php, on 27 Sept 2012 - 5:07 PM, said:snapback.png

Hi again

Create this file override/controllers/ProductController.php

Put this code in the file :

<?php
class ProductController extends ProductControllerCore{
public function displayContent()
{
     global $currency;
     $second_currency = 'USD';
    
     $productPriceWithTax
= Product::getPriceStatic($this->product->id, true, NULL, 6);
if (Product::$_taxCalculationMethod == PS_TAX_INC)
     $productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
$productPriceWithoutEcoTax = (float)($productPriceWithTax - $this->product->ecotax);
    
     $current_currency
= $currency->iso_code;
     $default_currency = Currency::getDefaultCurrency()->iso_code;
     $currency_array = Currency::getCurrencies($object = false, $active = 1);
    
    
if ($current_currency == $default_currency){
         foreach ($currency_array as $arr){
             if ((string)$arr['iso_code'] == $second_currency ){
             $second_currency_price = Tools::ps_round($productPriceWithoutEcoTax * (float)$arr['conversion_rate'],2);
             }
         }
        
    
}
self::$smarty->assign('second_currency_price',$second_currency_price.' '.$second_currency);
parent::displayContent();
}
} In product.tpl modify
{if $priceDisplay >= 0 && $priceDisplay <= 2}
                                             <span id="our_price_display">{convertPrice price=$productPrice}</span> To
{if $priceDisplay >= 0 && $priceDisplay <= 2}
                                             {$second_currency_price}/
     <span id="our_price_display">{convertPrice price=$productPrice}</span> I choosed USD to be the second currency ($second_currency='USD') , I have then this display 349.02 USD/ 259,53 € TTC.

Regards
Make backup before modifications.

 

 

 

 

 

i'am don't find this lines :( where changed it? i add my  files from server, please see and ask me whats problem site is www.kvepinkis.lt

http://speedy.sh/B6ED5/product.tpl http://speedy.sh/VRqHW/ProductController.php

Edited by tikis (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Hi there,

 

I am trying to do this thing as well, but can't work it out with product-list.tpl file.

I managed to show two prices in product page, but can't make it with product list.

I attach the picture and here is where I added the line:

 

{foreach from=$products item=product name=products}

{math equation="(total%perLine)" total=$smarty.foreach.products.total perLine=$nbItemsPerLine assign=totModulo}
{math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineTablet 
 
assign=totModuloTablet}
{math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineMobile 
 
assign=totModuloMobile}
{if $totModulo == 0}{assign var='totModulo' value=$nbItemsPerLine}{/if}
{if $totModuloTablet == 0}{assign var='totModuloTablet' value=$nbItemsPerLineTablet}{/if}
{if $totModuloMobile == 0}{assign var='totModuloMobile' value=$nbItemsPerLineMobile}{/if}
<div class="ajax_block_product col-sp-12 {$colValue}{if $smarty.foreach.products.iteration%$nbItemsPerLine == 0} 
last-in-line
{elseif $smarty.foreach.products.iteration%$nbItemsPerLine == 1} first-in-line{/if}
{if $smarty.foreach.products.iteration > ($smarty.foreach.products.total - $totModulo)} last-line{/if}
{if $smarty.foreach.products.iteration%$nbItemsPerLineTablet == 0} last-item-of-tablet-line
{elseif $smarty.foreach.products.iteration%$nbItemsPerLineTablet == 1} first-item-of-tablet-line{/if}
{if $smarty.foreach.products.iteration%$nbItemsPerLineMobile == 0} last-item-of-mobile-line
{elseif $smarty.foreach.products.iteration%$nbItemsPerLineMobile == 1} first-item-of-mobile-line{/if}
{if $smarty.foreach.products.iteration > ($smarty.foreach.products.total - $totModuloMobile)} last-mobile-line
 
{/if}">
 
{include file="$tpl_dir./product-item.tpl" callFromModule=isset($class)}
{convertPrice price=FrontController::ConvertPrice($product.price,$cookie->id_currency,2)}
</div>
{/foreach}

post-539024-0-58067300-1416826403_thumb.jpg

Edited by GreddyMR2 (see edit history)
Link to comment
Share on other sites

in controller (frontController.php) you can:

- create an override

 

or just change original file, paste function:

    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

before last closing bracket.

 

then you will be able to use smarty code:

 

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

there, where you want to display other currency price

 

Thank you Vekia, I have tried this code and it works perfectly for product-list.tpl, but I cannot find a place where to add this code on product.tpl? Could you help me, please, where to add this code so I could see my prices in 2 currencies at the same time?

Link to comment
Share on other sites

  • 1 month later...

in controller (frontController.php) you can:

- create an override

 

or just change original file, paste function:

    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

before last closing bracket.

 

then you will be able to use smarty code:

 

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

there, where you want to display other currency price

 

Hi,

I made modificaition as you said. But product_list.tpl files shows prices with tax included but product.tpl file shows prices without tax in currency after convert. I show to my customer all prices with tax in my shop. I use prestahop 1.6.9 and use default template.

 

Example: price 29.50TRL(tax includeded) convert price 10.77$ in product_list.tpl file. but same product convert price is 9.97$ that is converted without tax price.

 

Adsiz.png

Adsiz2.png

 

Please help.

 

Thanks

Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...

hi ppl,

 

I've managed to add second currency to product.tpl and product-list.tpl so it is working. But for some reason it does not work at all in my blockcart.tpl file. I've tryed everything of this:

 

$total, $shipping_cost, $products_wt, $order_total

 

still only original price is displayed. I've tried clearing cache and cookies. Feels like there is some sort of access denial to Front Controller, but dunno.

Edited by Vitazzz (see edit history)
Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...

in controller (frontController.php) you can:

- create an override

 

or just change original file, paste function:

    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

before last closing bracket.

 

then you will be able to use smarty code:

 

{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

there, where you want to display other currency price

 

Hello, it's seems to be not working on Prestashop 1.6 with specific price... I have a EUR price and a specific price pour US dollar...

With your tricks the price displayed are the same...

 

Did i miss something ?

 

Thank

Link to comment
Share on other sites

  • 1 year later...
On 8/19/2014 at 3:55 AM, vekia said:

    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

use this in classes/controllers/frontController.php

 

then in template file use: (in product-list.tpl)


{convertPrice price=FrontController::ConvertPrice($product.price,$cookie->id_currency,2)}

in product.tpl


{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

2 is an id of currency you want to display.

 

Please note that this modification does not change the value of second price if you will switch an attribute! (for example if your attribute has a price impact)

module that works well with attributes change and quantitiy discount is here show price in 2 different currencies

Hi,

We bought the module and it works well, but it does not swap the values if you select the secondary currency from the currency selector. Is ther a way to fix this issue? 

Regards,

currencyswitch.jpg

Link to comment
Share on other sites

On 5/21/2012 at 5:02 PM, sbhard said:

how can i do something like this?post-343850-0-13552800-1337644881_thumb.jpg
i mean, how can i show 2 different currencies at same time in one article?
Thank you for your answers!

 

SOLVED!

i decided to use vekia's module: show price in many currencies. Mainly because of fact that it works well with quantity discounts (when i increase / decrease quantity of product) and combinations that affects price.

Hi,

I also bought the module but wanted to ask if you also have a problem when you swap from primary currency to secondary currency? like my image shows.

Regards,

 

currencyswitch.jpg

Link to comment
Share on other sites

  • 2 years later...
On 8/19/2014 at 2:31 PM, vekia said:

in controller (frontController.php) you can:

- create an override

 

or just change original file, paste function:


    public static function ConvertPrice($value,$currencyFrom,$currencyTo){
        $currency_from = new currency($currencyFrom);
        $currency_to = new Currency($currencyTo);
        return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
    }   

before last closing bracket.

 

then you will be able to use smarty code:
 


{convertPrice price=FrontController::ConvertPrice($product->price,$cookie->id_currency,2)}

there, where you want to display other currency price

 

It may be more effective to use ISO codes instead of using IDs in currencies.

in controller (frontController.php) you can:

public static function ConvertPrice($value,$currencyFrom,$currencyTo){
	$currency_from = new Currency((int)Currency::getIdByIsoCode($currencyFrom));
	$currency_to = new Currency((int)Currency::getIdByIsoCode($currencyTo));
	return Tools::displayPrice(Tools::convertPriceFull($value,$currency_from,$currency_to),$currency_to);
}

then you will be able to use smarty code:

{FrontController::ConvertPrice($product->price_amount,'USD','TRY')}

there, where you want to display other currency price

Link to comment
Share on other sites

  • 5 months later...
  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...