Page 1 of 2

Displaying Product dimensions & weight?

Posted: Wed Jul 24, 2019 4:00 pm
by ihateusernames
I've created some products in opencart, but the default theme doesn't show the dimensions or weight of the product that I've entered? Is there a simple way to add this information to the product page or description? Or do I need a different theme? Or something else?

Thanks for any information provided.

Re: Displaying Product dimensions & weight?

Posted: Wed Jul 24, 2019 5:57 pm
by paulfeakins
This has been asked and answered before:
viewtopic.php?t=184213

Re: Displaying Product dimensions & weight?

Posted: Wed Jul 24, 2019 7:11 pm
by ihateusernames
Thanks, I've edited the php & twig files, but I now get an error. When I open the php file it states there's a syntax error (unexpected T_VARIABLE).
Code Line reads:

$data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');

Any suggestions? Thanks for your assistance so far.

Re: Displaying Product dimensions & weight?

Posted: Wed Jul 24, 2019 10:22 pm
by Johnathan
If you don't want to make custom edits, the easiest way to do this is to just use product attributes to enter that data. You'll have to enter it twice for every product, but that will show up automatically on the product page, and wouldn't require any editing. The only downside is you can't choose where to display it, since it will show up in the area where attributes are listed.

Re: Displaying Product dimensions & weight?

Posted: Fri Jul 26, 2019 1:35 am
by xxvirusxx

Re: Displaying Product dimensions & weight?

Posted: Sun Jul 28, 2019 8:46 pm
by ihateusernames
Thanks Jonathan & xxvirusxx,

I'll look into both options. I'm happy to edit stuff, but just need help with the errors. Still getting the parse error explained before....
Thanks.

Re: Displaying Product dimensions & weight?

Posted: Sun Jul 28, 2019 9:21 pm
by xxvirusxx
We don't know what you changed, where you changed and code you used...to tell you how to fix the error/errors.

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 4:58 pm
by ihateusernames
Thanks, as I previously mentioned, I followed the instructions in the linked email. The copied parts all seem ok, but the following line is the one generating the parse error. That line of code reads:
$data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
Can you see anything wrong with it? Thanks.

I also tried downloading the extension you mentioned, but after unzipping & trying to upload it in Extensions, OpenCart stated that the .xml file was an invalid file type. That was the only file in the folder? So not sure what to do there? But thanks for the suggestion.

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 5:07 pm
by ihateusernames
OK, extension now uploaded & installed properly 'I think!'. I was trying to upload the file rather than the folder.

But still getting the parse syntax error on the line of code in my previous post.

Thanks.

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 5:10 pm
by xxvirusxx
ihateusernames wrote:
Mon Jul 29, 2019 4:58 pm
Thanks, as I previously mentioned, I followed the instructions in the linked email.
What instructions?

Now need to unzip, just install as it is (blabla.ocmod.zip) and that tell you clear on extension page....

1. Go to Extensions-->Installer
2. Click on Upload and chose the file product_dimensions_and_weight.ocmod.zip
3. Refresh Ocmod

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 5:31 pm
by ihateusernames
Here is the instructions as guided by the first guy who responded to this post.

Open the product controller file and search the below line

file location -> catalog / controller / product then open the product.php file

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

Then after this line add the below line

$data['weight'] = $product_info['weight'];
$data['length'] = $product_info['length'];
$data['width'] = $product_info['width'];
$data['height'] = $product_info['height'];

Then open the product.tpl file and serach for the below line

File Location-> catalog / view / theme / default or (Your_Theme_Folder_If_You_Use_any_theme) / template / product then product.tpl file

<li><?php echo $text_stock; ?> <?php echo $stock; ?></li>

just after that line add the below code

<?php if($weight) { ?>
Weight : <?php echo number_format($weight,2); ?>
<?php } ?>
<br/>
<?php if($length || $width || $height) { ?>
L x W x H : <?php echo number_format($length,2)," x ", number_format($width,2) , " x " , number_format($height,2); ?>
<?php } ?>

Thanks.

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 5:35 pm
by xxvirusxx
ihateusernames wrote:
Mon Jul 29, 2019 5:31 pm
<?php if($weight) { ?>
Weight : <?php echo number_format($weight,2); ?>
<?php } ?>
<br/>
<?php if($length || $width || $height) { ?>
L x W x H : <?php echo number_format($length,2)," x ", number_format($width,2) , " x " , number_format($height,2); ?>
<?php } ?>
And you have converted this code for 3.x?

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 5:58 pm
by ihateusernames
Sorry, I copied the wrong post! This is the correct data I inserted. (apologies....)

(1) file location -> catalog / controller / product then open the product.php file
search/find line
$data['points'] = $product_info['points'];

Then after this line add the below line
$data['weight'] = $this->weight->format(($product_info['weight'] ) , $product_info['weight_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point'))

(2) File Location-> catalog / view / theme / default or (Your_Theme_Folder_If_You_Use_any_theme) / template / product then product.twig file
search/find line <li>{{ text_stock }} {{ stock }}</li>

Then after this line add the below line
<li>{{'Weight:'}} {{weight}}</li>

Thanks.

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 6:03 pm
by xxvirusxx
ihateusernames wrote:
Mon Jul 29, 2019 5:58 pm
$data['weight'] = $this->weight->format(($product_info['weight'] ) , $product_info['weight_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point'))
Try with this

$data['weight'] = $this->weight->format(($product_info['weight'] ) , $product_info['weight_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point'));

And use

Code: Select all

<li>{{'Weight:'}} {{ weight }}</li>

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 6:19 pm
by ihateusernames
Thanks , parse error now gone & product pages all loading fine.

However, still no weight or dimensions showing on the product page? If I use the attributes it looks like they show up in the specifications tab rather than on the product itself (as per Jonathan's suggestion). I'd rather they showed up on the product tab or info. Is this possible?

Thanks.

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 6:31 pm
by xxvirusxx
You have refreshed ocmod? Cleared SASS cache, theme cache?

Code work just fine

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 6:54 pm
by ihateusernames
Thanks, the refresh ocmod extension did the trick. I guess that is standard procedure in OpenCart after an install.

Apologies as I'm still finding my way around all the intricacies of this app. The layout & use is not what I was expecting, but hopefully I'll get there in the end :)

I've just noticed the weight is now shown twice, above & below the Dimensions.....!

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 6:55 pm
by xxvirusxx
ihateusernames wrote:
Mon Jul 29, 2019 6:54 pm
I've just noticed the weight is now shown twice, above & below the Dimensions.....!
Then disable my extension....or remove that code and use my extension.

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 8:46 pm
by ihateusernames
OK, if I disable your ext & remove the lines of code I inserted previously, everything reverts back to 'as before'.

If I insert the lines of code, the weight & dimensions still don't show up at all?

If I remove the lines of code & enable your ext, then the weight is shown twice & the dimensions once?

Any suggestions? Thanks.

Re: Displaying Product dimensions & weight?

Posted: Mon Jul 29, 2019 8:54 pm
by ihateusernames
OK, clearing SASS & theme caches did the trick for the ext.

Thanks.....