Page 1 of 1
[SOLVED] Show Weight Unit Properly on Product Page
Posted: Sun May 17, 2015 6:22 am
by aljawaid
Hello all, was wondering if anybody could help...
I have products showing in kg, g, lb, oz.
With thanks to
http://forum.opencart.com/viewtopic.php ... 27#p484527 I have managed to get the weight showing on my product page but it shows me the id from the database. I have tried many guesses but it throws white pages or fatal/illegal errors.
I know I am doing it wrong but I'm not sure where. Here's my code:
File: catalog/controller/product/product.php
I added:
Code: Select all
$data['weight_class_id'] = $product_info['weight_class_id'];
File: catalog/view/theme/default/template/product
I added:
Code: Select all
<li><span data-toggle="tooltip" title="Product weights are estimated">Weight: </span> <?php echo round($weight, 3); ?> <?php echo $weight_class_id; ?></li>
The weight is correct:
Product 1 shows 10.5 but instead of kg it shows as 10.5
1
Product 2 shows 160 but instead of grams it shows 160
2
I know these are the id in the database table but I can't figure out how to change it to show the unit as 10.5kg or 160g.
Can anyone help with this please?
Re: Show Weight Unit Properly on Product Page
Posted: Sun May 17, 2015 2:43 pm
by tabook
Did not verify but something like that:
File: catalog/controller/product/product.php
Code: Select all
$data['weight_with_caption'] = $this->weight->format($product_info['weight'], $product_info['weight_class_id']);
And output within template file
Code: Select all
<?php echo $weight_with_caption; ?>
[SOLVED]Re: Show Weight Unit Properly on Product Page
Posted: Sun May 17, 2015 11:09 pm
by aljawaid
tabook wrote:Did not verify but something like that:
File: catalog/controller/product/product.php
Code: Select all
$data['weight_with_caption'] = $this->weight->format($product_info['weight'], $product_info['weight_class_id']);
And output within template file
Code: Select all
<?php echo $weight_with_caption; ?>
My friend you are fantastic, thanks so much for this, it works
Now I need to work out how to add dimensions

Re: [SOLVED] Show Weight Unit Properly on Product Page
Posted: Sun Jul 26, 2015 12:09 am
by Gatak
I made an OCMOD with the help of this thread. This will display weight on all product pages, including in search list.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<name>Display weight on product pages</name>
<code>product_weight_v2</code>
<version>1.0</version>
<author>Gatak</author>
<file path="system/library/weight.php">
<operation>
<search><![CDATA[return number_format($value, 2, $decimal_point, $thousand_point) . $this->weights[$weight_class_id]['unit'];]]></search>
<add position="replace"><![CDATA[return number_format($value, 0, $decimal_point, $thousand_point) . $this->weights[$weight_class_id]['unit'];]]></add>
</operation>
</file>
<file path="catalog/controller/product/category.php,catalog/controller/product/manufacturer.php,catalog/controller/product/search.php,catalog/controller/product/special.php">
<operation>
<search><![CDATA['rating' => $result['rating'],]]></search>
<add position="after"><![CDATA[
'weight' => sprintf($this->weight->format($result['weight'], $result['weight_class_id']), $this->language->get('text_product_weight')),
]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/product/category.tpl,catalog/view/theme/*/template/product/manufacturer_info.tpl,catalog/view/theme/*/template/product/search.tpl,catalog/view/theme/*/template/product/special.tpl">
<operation>
<search><![CDATA[<h4><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></h4>]]></search>
<add position="replace"><![CDATA[<h4><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></h4>
<p><?php if ($product['weight'] >= '1') { ?>
<span>Weight: <?php echo $product['weight']; ?></span></p>
<?php } ?>
]]></add>
</operation>
</file>
<file path="catalog/controller/product/product.php">
<operation>
<search><![CDATA[$data['model'] = $product_info['model'];]]></search>
<add position="after"><![CDATA[
$data['weight'] = $this->weight->format($product_info['weight'], $product_info['weight_class_id']);
]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/product/product.tpl">
<operation>
<search><![CDATA[<li><?php echo $text_model; ?> <?php echo $model; ?></li>]]></search>
<add position="after"><![CDATA[
<?php if ($weight >= '1') { ?>
<li>Weight: <?php echo $weight; ?></li>
<?php } ?>
]]></add>
</operation>
</file>
</modification>
Re: [SOLVED]Re: Show Weight Unit Properly on Product Page
Posted: Sun Jul 26, 2015 11:28 am
by opencartboost
aljawaid wrote:
Now I need to work out how to add dimensions
I have mods to show dimension and weight at product page and category page, you can check here
http://www.opencart.com/index.php?route ... on_id=2937