Display product price in two currencies at the same time?

user2427839 picture user2427839 · Jun 4, 2013 · Viewed 7.2k times · Source

How do I modify PrestaShop 1.5 to display product prices in two currencies at the same time (ie. base currenct and visitor's currency on products listed in product & categories pages):

Example

I think I should be modifying ProductController.php and product.tpl. Is this correct?

Below is one solution for the product page that I find on a forum, but it is for PrestaShop 1.4x:

  1. Override ProductController.php in /controllers/ProductController.php

    <?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();
        }
    }
    
  2. Modify product.tpl:

    {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>
    

In above example USD is the second currency ($second_currency='USD'). I was wondering if it would be possible to modify this code for PrestaShop 1.5, which has changed significantly since 1.4x.

Answer

kmas picture kmas · Jun 6, 2013

You have to loop this array which contains all the currencies you manage: {$currencies}

{foreach from=$currencies item=c}{$c.name}{/foreach}

The default currency is in: {$id_currency_cookie}

If I remember, you have to write this in product.tpl.

I don't know how to display the correct price for your currency. Tell us if you find.