How to get currency to show on product page in opencart?

戏子无情 提交于 2019-12-07 20:09:38

问题


I want to display the currency list on the product description page. How can I do that?

I copied the code from header.tpl () and pasted it in the product.tpl but I get an error:

Notice: Undefined variable: currency in C:\xampp\htdocs\mysite.com\catalog\view\theme\mytheme\template\product\product.tpl on line 60.

I tried adding the following code in product.tpl.

<?php include(DIR_APPLICATION.'\view\theme\mytheme\template\module\currency.tpl');

but that did not work either. Please help as I want to get this working.


回答1:


controller/common/header.php function index() add in to:

     $this->data['mygetcurrency'] = $this->currency->getCode();

catalog\view\theme\default\template\common\header.tpl add in to:

      <?php echo $mygetcurrency; ?>
      //EUR



回答2:


The best will be to do like this

$this->load->model('localisation/currency');
$this->data['allcurrencies'] = array();
$results = $this->model_localisation_currency->getCurrencies();   
foreach ($results as $result) {
     if ($result['status']) {
           $this->data['allcurrencies'][] = array(
           'title'        => $result['title'],
           'code'         => $result['code'],
           'symbol_left'  => $result['symbol_left'],
           'symbol_right' => $result['symbol_right']            
        );
     }
 }

thanks




回答3:


i guess this can be the easiest way.

<?php echo $this->currency->getSymbolRight($this->session->data['currency']) ?>

OR

<?php echo $this->currency->getSymbolLeft($this->session->data['currency']) ?>



回答4:


The $currency variable is built by the /catalog/controller/module/currency.php controller, which is normally called by /catalog/controller/common/header.php (using $this->children array).

To display this element in the product template, you'll need to call on this controller (and its view) using the $this->children array of the product controller (/catalog/controller/product/product.php). In opencart 1.5.4.1, it's around line 362

$this->children = array(
    'common/column_left',
    'common/column_right',
    'common/content_top',
    'common/content_bottom',
    'common/footer',
    'common/header',
    'module/currency' // Just add this line
);

Unfortunately, this will display the currency element at the top of the page by default, because this element's style is set to absolute positioning. You'll need to edit /catalog/view/theme/*/template/module/currency.tpl to make the HTML and CSS a bit more flexible.




回答5:


you can use very simple code. add this in your controller file.

$data['currency-symbol'] = $this->currency->getSymbolLeft($this->session->data['currency']);

And now you can echo it in your related .tpl file using this

<?php echo $currency-symbol ;?>


来源:https://stackoverflow.com/questions/12919496/how-to-get-currency-to-show-on-product-page-in-opencart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!