attributes-at-category-page
attributes-at-category-page

Hi, I answered another stackoverflow question how to show attributes of products in category page in Opencart 2.0 Although I suggest to use VqMod, but manually you can do following:

Open catalog/controller/product/category.php and find following code:

$data['products'][] = array(
'product_id'  => $result['product_id'],
'thumb'       => $image,
'name'        => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price'       => $price,
'special'     => $special,
'tax'         => $tax,
'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating'      => $result['rating'],
'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);

 

Now add one line in it ‘attribute_groups’ => $this->model_catalog_product->getProductAttributes($result[‘product_id’]), then the products array will be like below:

$data['products'][] = array(
'product_id'  => $result['product_id'],
'thumb'       => $image,
'attribute_groups'       => $this->model_catalog_product->getProductAttributes($result['product_id']),
'name'        => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price'       => $price,
'special'     => $special,
'tax'         => $tax,
'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating'      => $result['rating'],
'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);

 

Now open catalog/view/theme/YOUR_THEME_FOLDER/template/product/category.tpl and add following codes just below <p><?php echo $product[‘description’]; ?></p>

<p>
  <?php if ($product['attribute_groups']) { ?>
<div class="tab-pane" id="tab-specification">
  <table class="table table-bordered">
    <?php foreach ($product['attribute_groups'] as $attribute_group) { ?>
    <thead>
    <tr>
      <td colspan="2"><strong><?php echo $attribute_group['name']; ?></strong></td>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
    <tr>
      <td><?php echo $attribute['name']; ?></td>
      <td><?php echo $attribute['text']; ?></td>
    </tr>
    <?php } ?>
    </tbody>
    <?php } ?>
  </table>
</div>
<?php } ?>
</p>

 

Save and reload it will show attributes in category’s products

attributes-at-category-page
attributes-at-category-page

14 COMMENTS

  1. I receive this warning:
    Notice: Undefined index: attribute_groups in /web/htdocs/www.cadoreshop.com/home/catalog/view/theme/theme561/template/product/category.tpl on line 139

  2. Hello rupak do you have this in ocmod to OC 2.0, this change works like a charm if edited manualy the files, but my objetive is create ocmod.I try to create another similar of this but the only change is show ‘sku value’ and i have some issues, in register say
    the line of search not found i put this line “‘thumb’ => $image,” Can you help me?

  3. Hi!
    I am using Opencast 2.2.0. I did exactly what you’ve said countless times.
    I copied the attributes display from product.php and .tpl . No luck.
    I get “Undefined index: attribute_groups in /var/www/virtual/…”
    I am getting crazy here. What am I missing?
    Thank you!

    • Hi Marius,

      You need to change at category.php and category.tpl
      I checked it at 2.2 version and it is working fine with above code.
      Please try it again 🙂
      Hope you will be able to fix it.

      Once I got chance I will publish OCMOD

      Thanks
      Rupak

        • Hi Eds,

          Yes it is possible but it will redundancy of category as we are already in category page so hope not needed to show category in category page for products.

          If needed I will soon write some code for it

  4. Worked for me. Thank you for posting this tutorial.

    How can modify this code to display attributes in this format?

    Attribute Name 1 Attribute Name 2 Attribute Name 3
    Attribute Value 1 Attribute Value 1 Attribute Value 1

    • Hi Faruk,

      It is easy in product page.
      You can add following code at catalog\view\theme\***\template\product\product.tpl where ever you want to show the attributes.

      
                    < ?php foreach ($attribute_groups as $attribute_group) { ?>
                    
                    < ?php foreach ($attribute_group['attribute'] as $attribute) { ?>
                    
                    < ?php } ?>
                    
                    < ?php } ?>
                  
      < ?php echo $attribute_group['name']; ?>
      < ?php echo $attribute['name']; ?> < ?php echo $attribute['text']; ?>

      I have take code from product.tpl, so you can remove those table tags and implement your design

      Thanks
      Rupak

LEAVE A REPLY

Please enter your comment!
Please enter your name here