Post by ianhaney50 » Mon Dec 02, 2024 5:46 pm

I am trying to show the weight of the product on the category page in opencart 3.0.4.0. I've got the following code but it just says Weight: 0.00

In catalog/controller/product/category.php, I have added

Code: Select all

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

Code: Select all

'weight'      => $result['weight'],
In catalog/view/theme/default/product/category.twig, I have added

Code: Select all

<p>{{'Weight:'}} {{weight}}</p>
I have refreshed the modifications
Last edited by ianhaney50 on Tue Dec 03, 2024 12:52 am, edited 1 time in total.

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by paulfeakins » Mon Dec 02, 2024 8:15 pm

Are you sure this contains correct data?

Code: Select all

$result['weight']

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by khnaz35 » Mon Dec 02, 2024 8:44 pm

Try to print the results

Code: Select all

$this->log->write('Product Weight Raw: ' . print_r($result['weight'], true));

Got an urgent question that’s keeping you up at night? There might just be a magical inbox ready to help: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member
Online

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by ianhaney50 » Mon Dec 02, 2024 11:22 pm

I have managed to get the weight displayed but it currently says 1.00000000

It would be good if can display it as 1kg or 1kilgoram as the weight class is set to kilogram on the admin side

The code I currently have is below

In catalog/controller/product/category.php

Code: Select all

$data['weight'] = $this->weight->format(($result['weight'] ) , $result['weight_class'], $this->language->get('decimal_point'), $this->language->get('thousand_point'));
and

Code: Select all

'weight'      => $result['weight'],
In catalog/view/theme/default/template/catalog/category.twig

Code: Select all

<p class="categorydescription">{{'Weight:'}} {{product.weight}}</p>

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by OSWorX » Tue Dec 03, 2024 9:52 pm

When you use:

Code: Select all

'weight'   => $this->weight->format($result['weight'], $result['weight_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point'))
then you have all you need.

This - of course - should be assigned to the product array, then you can display it like

Code: Select all

{{ product.weight }}
, otherwise you have to call it:

Code: Select all

{{ weight }}
in your template ..

The result should be then this (default template):
Image

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: Baidu [Spider], samm91 and 26 guests