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

别来无恙 提交于 2019-12-06 12:07:39

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

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

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']) ?>

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.

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