Post by aljawaid » Sun May 17, 2015 6:22 am

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?
Last edited by aljawaid on Sun May 17, 2015 11:12 pm, edited 1 time in total.

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by tabook » Sun May 17, 2015 2:43 pm

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; ?>

Forget complex and inconvenient stock Categories and Products in OpenCart - use Acute Category Manager +!
Ready for 1.5.x and 2.x Editions


New member

Posts

Joined
Sun Mar 01, 2015 6:27 pm

Post by aljawaid » Sun May 17, 2015 11:09 pm

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 :)

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by Gatak » Sun Jul 26, 2015 12:09 am

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>

Newbie

Posts

Joined
Wed May 06, 2015 9:34 pm

Post by opencartboost » Sun Jul 26, 2015 11:28 am

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

Active Member

Posts

Joined
Thu Jul 09, 2015 5:59 am
Who is online

Users browsing this forum: No registered users and 11 guests