2

我想在产品描述页面上显示货币列表。我怎样才能做到这一点?

我从 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');

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

4

5 回答 5

3

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

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

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

      <?php echo $mygetcurrency; ?>
      //EUR
于 2014-10-29T09:07:39.537 回答
2

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

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

或者

<?php echo $this->currency->getSymbolLeft($this->session->data['currency']) ?>
于 2016-01-22T11:12:02.080 回答
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']            
        );
     }
 }

谢谢

于 2012-12-13T16:51:27.287 回答
0

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

要在产品模板中显示此元素,您需要使用产品控制器 (/catalog/controller/product/product.php) 的 $this->children 数组调用此控制器(及其视图)。在 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 更加灵活。

于 2012-10-18T07:06:12.573 回答
0

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

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

现在您可以使用它在相关的 .tpl 文件中回显它

<?php echo $currency-symbol ;?>
于 2017-03-03T18:01:52.720 回答