7

如何修改 PrestaShop 1.5 以同时以两种货币显示产品价格(即产品和类别页面中列出的产品的基础货币和访客货币):

例子

我想我应该修改ProductController.phpproduct.tpl. 这个对吗?

以下是我在论坛上找到的产品页面的一种解决方案,但它适用于 PrestaShop 1.4x:

  1. 覆盖 /controllers/ProductController.php 中的 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. 修改product.tpl

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

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

在上面的示例中,美元是第二种货币 ( $second_currency='USD')。我想知道是否可以为 PrestaShop 1.5 修改此代码,该代码自 1.4x 以来发生了显着变化。

4

1 回答 1

2

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.

于 2013-06-06T13:58:12.860 回答