在 Opencart 2 的产品页面中显示重量单位

Show unit of weight in product page for Opencart 2

嗨!

Opencart 2.0.2.0如何在商品页面显示重量单位(kg.,gr.,oz.,ml.)

现在只显示没有单位的数字。

我正在使用默认模板

在文件 template\product\product.tpl 中看起来像这样:

...<li><?php echo $text_model; ?> <?php echo $model; ?></li>

<?php if ($weight) { ?>

<li><?php echo $text_weight; ?>
<?php
echo round($weight, 2)?></li>
 <?php } ?> ...

catalog\controller\product\product.php

我添加了行

$data['text_weight'] = $this->language->get('text_weight');

$data['weight'] = $product_info['weight'];

还有什么需要添加或更改的?

尝试使用默认的 OpenCart 代码。

步骤 1

打开文件catalog/controller/product/product.php

查找(242行左右):

$data['text_tags'] = $this->language->get('text_tags');

后加:

$data['text_weight'] = $this->language->get('text_weight');


第 2 步

在同一个文件中catalog/controller/product/product.php

查找(270行左右):

$data['points'] = $product_info['points'];

后加:

$data['weight'] = $product_info['weight'];
$tablewunit = $this->db->query("SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE (wcd.weight_class_id = " . $product_info['weight_class_id'] . ") AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
$data['weightunit'] = $tablewunit->row['unit'];


步骤 3

打开文件catalog/language/english/product/product.php

查找(第6行左右):

$_['text_model']               = 'Product Code:';

后加:

$_['text_weight']       = 'Weight:';


第 4 步

打开文件catalog/view/theme/default(your theme)/template/product/product.tpl

查找(141行左右):

<li><?php echo $text_model; ?> <?php echo $model; ?></li>

后加:

<li><?php echo $text_weight; ?> <?php echo $weight . ' ' . $weightunit; ?></li>

然后检查一下。