OpenCart 在产品页面 1.5.6 中显示重量单位
OpenCart show weight units in product page 1.5.6
如何在 1.5.6 的产品页面中显示重量(带单位)。
示例:重量 - 2.5 千克;重量 - 250 毫克 ...
我一直在阅读一些文章,但没有任何内容正常工作。
你好保加利亚人,我以你的名字命名。
如果你想在产品上显示重量很简单。
打开 FTP 并转到 catalog/view/theme/YOURTHEME/template/product
并下载 product.tpl
找到这一行
<span class="reward"><small><?php echo $text_points; ?> <?php echo $points; ?></small></span><br />
<?php } ?>
粘贴后立即
<?php
echo round($weight,2). "kg";
?>
(或将其粘贴到产品页面上您想要查看的位置。)
之后转到 /catalog/controller/product
并打开 product.php
找到这一行
$this->data['model'] = $product_info['model'];
并在粘贴此行后立即:
$this->data['weight'] = $product_info['weight'];
你已经差不多完成了。
希望我正确理解了你的问题。
您可以使用 Opencart 的重量 class format()
方法格式化重量,如下所示:
$this->weight->format($weight,$weight_class_id);
getProduct()
方法已经提供了您需要的两个值,因此您可以像这样从产品控制器轻松调用它:
$this->data['product_weight'] = $this->weight->format($product_info['weight'],$product_info['weight_class_id']);
然后像显示任何其他变量一样在 tpl 中的任何位置显示 $product_weight
。这将为您提供您想要的,但没有 space(即“250mg”)。
如果您想更好地控制格式,您还可以使用 getUnit()
方法如下:
$this->weight->getUnit($product_info['weight_class_id']);
然后您可以根据需要将它们组合在一起。例如,如果你想要 space:
$this->data['product_weight'] = $product_info['weight'] . ' ' . $this->weight->getUnit($product_info['weight_class_id']);
go to catalog/language/english/product/product.php,Find:
$_['text_model'] = 'Product Code:';
在其后添加以下代码
$_['text_weight'] = 'Weight:';
打开catalog/controller/product/product.php,查找:
$data['text_stock'] = $this->language->get('text_stock');
在其后添加以下代码:
$data['text_weight'] = $this->language->get('text_weight');
在同一文件中搜索代码:
$data['model'] = $product_info['model'];
在其后粘贴以下代码:
$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['weight_unit'] = $tablewunit->row['unit'];
现在打开catalog/view/theme/---yourtheme---/template/product/product.tpl,找到:
<li><?php echo $text_stock; ?> <?php echo $stock; ?></li>
在其后添加以下代码:
<td><b><?php echo $text_weight; ?></b></td>
<td><?php echo round ($weight, 2) . ' ' . $weight_unit; ?></td>
<tr>
<?php if ($weight) { ?>
<tr>
<?php } ?>
就这些了
如何在 1.5.6 的产品页面中显示重量(带单位)。 示例:重量 - 2.5 千克;重量 - 250 毫克 ... 我一直在阅读一些文章,但没有任何内容正常工作。
你好保加利亚人,我以你的名字命名。
如果你想在产品上显示重量很简单。
打开 FTP 并转到 catalog/view/theme/YOURTHEME/template/product
并下载 product.tpl
找到这一行
<span class="reward"><small><?php echo $text_points; ?> <?php echo $points; ?></small></span><br />
<?php } ?>
粘贴后立即
<?php
echo round($weight,2). "kg";
?>
(或将其粘贴到产品页面上您想要查看的位置。)
之后转到 /catalog/controller/product
并打开 product.php
找到这一行
$this->data['model'] = $product_info['model'];
并在粘贴此行后立即:
$this->data['weight'] = $product_info['weight'];
你已经差不多完成了。
希望我正确理解了你的问题。
您可以使用 Opencart 的重量 class format()
方法格式化重量,如下所示:
$this->weight->format($weight,$weight_class_id);
getProduct()
方法已经提供了您需要的两个值,因此您可以像这样从产品控制器轻松调用它:
$this->data['product_weight'] = $this->weight->format($product_info['weight'],$product_info['weight_class_id']);
然后像显示任何其他变量一样在 tpl 中的任何位置显示 $product_weight
。这将为您提供您想要的,但没有 space(即“250mg”)。
如果您想更好地控制格式,您还可以使用 getUnit()
方法如下:
$this->weight->getUnit($product_info['weight_class_id']);
然后您可以根据需要将它们组合在一起。例如,如果你想要 space:
$this->data['product_weight'] = $product_info['weight'] . ' ' . $this->weight->getUnit($product_info['weight_class_id']);
go to catalog/language/english/product/product.php,Find:
$_['text_model'] = 'Product Code:';
在其后添加以下代码
$_['text_weight'] = 'Weight:';
打开catalog/controller/product/product.php,查找:
$data['text_stock'] = $this->language->get('text_stock');
在其后添加以下代码:
$data['text_weight'] = $this->language->get('text_weight');
在同一文件中搜索代码:
$data['model'] = $product_info['model'];
在其后粘贴以下代码:
$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['weight_unit'] = $tablewunit->row['unit'];
现在打开catalog/view/theme/---yourtheme---/template/product/product.tpl,找到:
<li><?php echo $text_stock; ?> <?php echo $stock; ?></li>
在其后添加以下代码:
<td><b><?php echo $text_weight; ?></b></td>
<td><?php echo round ($weight, 2) . ' ' . $weight_unit; ?></td>
<tr>
<?php if ($weight) { ?>
<tr>
<?php } ?>
就这些了