user1750710
user1750710

Reputation: 21

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

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.

Upvotes: 2

Views: 9725

Answers (5)

Pavan
Pavan

Reputation: 345

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

Upvotes: 0

Punit Gajjar
Punit Gajjar

Reputation: 4997

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

Upvotes: 2

Limitless isa
Limitless isa

Reputation: 3802

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

Upvotes: 3

spiralclick
spiralclick

Reputation: 56

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

Upvotes: 1

Nicolas Connault
Nicolas Connault

Reputation: 464

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.

Upvotes: 0

Related Questions