如何在opencart中的产品页面上显示货币?

时间:2012-10-16 16:41:58

标签: opencart

我想在产品说明页面上显示货币列表。我怎么能这样做?

我从header.tpl()复制了代码并将其粘贴到product.tpl中但是我收到错误:

注意:未定义的变量:第60行的C:\ xampp \ htdocs \ mysite.com \ catalog \ view \ theme \ mytheme \ template \ product \ product.tpl中的货币。

我尝试在product.tpl中添加以下代码。

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

但这也不起作用。请帮忙,因为我想让这个工作。

5 个答案:

答案 0 :(得分:3)

controller / common / header.php函数index()加入到:

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

catalog \ view \ theme \ default \ template \ common \ header.tpl添加到:

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

答案 1 :(得分:1)

最好的就是这样做

$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']            
        );
     }
 }

感谢

答案 2 :(得分:1)

我想这可能是最简单的方法。

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

OR

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

答案 3 :(得分:0)

$ currency变量由/catalog/controller/module/currency.php控制器构建,该控制器通常由/catalog/controller/common/header.php调用(使用$ this-&gt; children数组)。 / p>

要在产品模板中显示此元素,您需要使用产品控制器的$ this-&gt; children数组调用此控制器(及其视图)(/catalog/controller/product/product.php )。在opencart 1.5.4.1中,它位于第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
);

不幸的是,默认情况下,这会在页面顶部显示货币元素,因为此元素的样式设置为绝对定位。您需要编辑/catalog/view/theme/*/template/module/currency.tpl以使HTML和CSS更灵活。

答案 4 :(得分:0)

你可以使用非常简单的代码。将其添加到控制器文件中。

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

现在您可以使用此

在相关的.tpl文件中回显它
<?php echo $currency-symbol ;?>
相关问题