0
votes

I am currently working on an ecommerce website using opencart, trying to show the weight of each product, in product details template it works, however, when I do the same thing to the product block, it shows undefined variable. This is the site KCityMart

So what I did to show the weight in product details page is this

in file catalog/controller/product/product.php I added this

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

and in /catalog/view/theme/theme/template/product/product.tpl I added this

        <ul class="volume">
          <?php if ($weight > 0) { ?>
          <li><?php echo $weight; ?></li>
          <?php } ?>
        </ul>

and it works. But, when I tried to add this to /catalog/view/theme/theme/template/common/product/default.tpl it shows "undefined variable" error.

What could be the problem? Which part did I miss?

Any input from you all will be very much appreciated. Thanks!

1

1 Answers

0
votes

What is default.tpl file ? If it's new file then you need to create controller file for it and then do the same thing which you are performed in product controller.

Assigned weight varible in catalog/controller/product/default.php (Note: If you did not created default.php controller then you need to create) then add following code

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

and in /catalog/view/theme/*/template/product/default.tpl add following code in above file.

<ul class="volume">
      <?php if ($weight > 0) { ?>
      <li><?php echo $weight; ?></li>
      <?php } ?>
    </ul>