Php 在Opencart 2的产品页面中显示重量单位
嗨 如何在Opencart 2.0.2.0的产品页面中显示重量单位(千克、克、盎司、毫升) 现在只显示一个没有单位的数字 我使用的是默认模板 在文件template\product\product.tpl中,如下所示:Php 在Opencart 2的产品页面中显示重量单位,php,opencart,opencart2.x,Php,Opencart,Opencart2.x,嗨 如何在Opencart 2.0.2.0的产品页面中显示重量单位(千克、克、盎司、毫升) 现在只显示一个没有单位的数字 我使用的是默认模板 在文件template\product\product.tpl中,如下所示: ...<li><?php echo $text_model; ?> <?php echo $model; ?></li> <?php if ($weight) { ?> <li><?php echo
...<li><?php echo $text_model; ?> <?php echo $model; ?></li>
<?php if ($weight) { ?>
<li><?php echo $text_weight; ?>
<?php
echo round($weight, 2)?></li>
<?php } ?> ...
还需要添加或更改哪些内容?在默认OpenCart代码中尝试类似的内容 第一步 打开文件
catalog/controller/product/product.php
查找(第242行附近):
在以下内容之后添加:
$data['text_weight'] = $this->language->get('text_weight');
$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'];
$_['text_weight'] = 'Weight:';
<li><?php echo $text_weight; ?> <?php echo $weight . ' ' . $weightunit; ?></li>
步骤2 在同一个文件
catalog/controller/product/product.php
查找(第270行附近):
在以下内容之后添加:
$data['text_weight'] = $this->language->get('text_weight');
$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'];
$_['text_weight'] = 'Weight:';
<li><?php echo $text_weight; ?> <?php echo $weight . ' ' . $weightunit; ?></li>
步骤3 打开文件
catalog/language/english/product/product.php
查找(第6行附近):
在以下内容之后添加:
$data['text_weight'] = $this->language->get('text_weight');
$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'];
$_['text_weight'] = 'Weight:';
<li><?php echo $text_weight; ?> <?php echo $weight . ' ' . $weightunit; ?></li>
步骤4 打开文件
catalog/view/theme/default(您的主题)/template/product/product.tpl
查找(第141行附近):
在以下内容之后添加:
$data['text_weight'] = $this->language->get('text_weight');
$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'];
$_['text_weight'] = 'Weight:';
<li><?php echo $text_weight; ?> <?php echo $weight . ' ' . $weightunit; ?></li>
然后检查它。在默认OpenCart代码中尝试类似的操作 第一步 打开文件
catalog/controller/product/product.php
查找(第242行附近):
在以下内容之后添加:
$data['text_weight'] = $this->language->get('text_weight');
$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'];
$_['text_weight'] = 'Weight:';
<li><?php echo $text_weight; ?> <?php echo $weight . ' ' . $weightunit; ?></li>
步骤2 在同一个文件
catalog/controller/product/product.php
查找(第270行附近):
在以下内容之后添加:
$data['text_weight'] = $this->language->get('text_weight');
$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'];
$_['text_weight'] = 'Weight:';
<li><?php echo $text_weight; ?> <?php echo $weight . ' ' . $weightunit; ?></li>
步骤3 打开文件
catalog/language/english/product/product.php
查找(第6行附近):
在以下内容之后添加:
$data['text_weight'] = $this->language->get('text_weight');
$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'];
$_['text_weight'] = 'Weight:';
<li><?php echo $text_weight; ?> <?php echo $weight . ' ' . $weightunit; ?></li>
步骤4 打开文件
catalog/view/theme/default(您的主题)/template/product/product.tpl
查找(第141行附近):
在以下内容之后添加:
$data['text_weight'] = $this->language->get('text_weight');
$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'];
$_['text_weight'] = 'Weight:';
<li><?php echo $text_weight; ?> <?php echo $weight . ' ' . $weightunit; ?></li>
然后检查一下。非常感谢!它起作用了!我承诺开始学习php和Opencart!还针对oc3.0.2进行了修改,效果非常好!谢谢)非常感谢!它起作用了!我承诺开始学习php和Opencart!还针对oc3.0.2进行了修改,效果非常好!(谢谢)