Magento – How to show weight in kg and gm on product list page

magento-1product-attribute

In product list weight is 0 gm. I set weight in admin panel, but it's weight show in 0 gm..? I set code in

app/design/frontend/rwd/default/template/catalog/product/list.phtml

code is:

<?php  
     $_weight = $this->htmlEscape($_product->getWeight()); 
  if ($_weight < 1)
    $_weightstr = number_format($_weight*1000) . " gm"; 
  else
    $_weightstr = number_format($_weight) . " kg"; echo $_weightstr; ?>

Please help…!

Best Answer

I believe the attribute "weight" does not have the option "Used in product listing" set to "Yes"; this can be checked by a simple

var_dump($_product->getWeight());

in the list.phtml; I guess it gives NULL.

Change "Used in product listing" to "Yes", reindex & clear the cache to solve this issue.

Related Topic