2
votes

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.

5
Show us the code... the codeuser1537415

5 Answers

3
votes

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
votes

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

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

0
votes

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.

0
votes

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 ;?>