admin管理员组文章数量:1431927
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):
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:
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(); } }
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.
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):
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:
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(); } }
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.
1 Answer
Reset to default 2You 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.
本文标签: javascriptDisplay product price in two currencies at the same timeStack Overflow
版权声明:本文标题:javascript - Display product price in two currencies at the same time? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745595580a2665457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论