Page 1 of 2
[SOLVED] Display attributes on Category and Mnufacturer page
Posted: Mon Oct 31, 2011 11:05 pm
by monkeyplay
Hi,
Am using OpenCart v1.5.1. I want to display product attributes on both the category and manufacturer pages. Have searched but cannot find a module or solution for this.
Can anyone help?
Have copied code below from product.tpl and put into category.tpl.
Code: Select all
<?php foreach ($attribute_groups as $attribute_group) { ?>
<?php echo $attribute_group['name']; ?><br> <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<?php echo $attribute['name']; ?>: <?php echo $attribute['text']; ?>
<?php } ?>
<?php } ?>
Also added
Code: Select all
$this->data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);
to category.php
My understanding of PHP is not great so am just looking for the relevant code in product.php and product.tpl to transfer to category.php and category.tpl, however am not having much luck.
Anybody know if this is easy to do? I don't mind paying someone to achieve this.
Cheers,
Rob
Re: Display attributes on Category and Manufacturer pages
Posted: Tue Nov 01, 2011 3:22 pm
by wernerrenrew
Hi,
Im on the newest version but here is something to help you get on your way.
category/controller/product/category.php something like line 187
replace this
Code: Select all
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'rating' => $result['rating'],
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])
);
replace with this
Code: Select all
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'rating' => $result['rating'],
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id']),
'attribute_groups' => $this->model_catalog_product->getProductAttributes($result['product_id'])
);
catalog/view/theme/your_theme/template/product/category.tpl paste somewhere inside the foreach ($products as $product) loop the best place to inject would be between line 75 and 76 of original tpl file
Code: Select all
<?php if ($product['attribute_groups']) { ?>
<table class="attribute">
<?php foreach ($product['attribute_groups'] as $attribute_group) { ?>
<thead>
<tr>
<td colspan="2"><?php echo $attribute_group['name']; ?></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>
<?php } ?>
If you need more help pm me but it will coast you im a programmer
Best regards Werner
Re: Display attributes on Category and Manufacturer pages
Posted: Tue Nov 01, 2011 5:29 pm
by monkeyplay
Hi Werner,
Thank you very much. Is exactly what I was after, has worked perfectly.

Will definitely get in touch if I have further work. Thanks for your help.
Cheers,
Rob
Re: Display attributes on Category and Manufacturer pages
Posted: Tue Nov 01, 2011 11:09 pm
by wernerrenrew
Good to hear,
Your welcome

Re: Display attributes on Category and Mnufacturer
Posted: Fri Dec 16, 2011 8:53 pm
by remcofaasse
hi, I would like to display the attribute text on the category page (in grid and list view).
Just below the product name. I am working in OC v 1.5.1.3.
Thanks for help!
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Sat Jan 21, 2012 2:35 am
by w1nt
Hi,
I'm also need this functionality on OC v1.5.13,
just try above tutorial and not working
please help...
thanks & regards
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Tue Jan 31, 2012 12:42 am
by andreicon
The code works for v1.5.0, many thanks wernerrenrew.
But is there a way to limit the number of attributes displayed in category page?
All the best!
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Thu Apr 12, 2012 12:41 am
by rajbrothers
Thanks Bro! - This worked like a Charm!!
I was working for one of my client and your code saved my ASS
Those who have complained that code did not work, please copy paste it correctly without spaces and when you add it on category.php template make sure you add it after this tag to make it work!
Code: Select all
<?php foreach ($products as $product) { ?>
Thx man!
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Fri Apr 13, 2012 12:09 am
by remcofaasse
Hi, it works but I have a problem with the languages. After an upload in English the attributes are displayed at all languages. And I am using the correct language ID. Please advise.
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Wed Apr 18, 2012 2:52 am
by pasha_st
Hello. Help me please to display additional images оn category page.
This is code from controller/product/product.php:
Code: Select all
$this->data['images'] = array();
$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
foreach ($results as $result) {
$this->data['images'][] = array(
'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
);
}
I tried to paste this code in controller/product/category.php, but my php-skills is vary bad

Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Thu Apr 26, 2012 10:03 pm
by remcofaasse
hi raj,
Is it possible that I do not have this code: ]<?php foreach ($products as $product) { ?>
in my category.php?
I have copied the attribute code in the tpl. Now I have added the attribute code below: $this->data['products'][] = array(
But that does not work. It would be fantastic to receive any tips regarding this as it costs me some terrible long nights
Thanks for your advise, Kind regards, Remco
rajbrothers wrote:Thanks Bro! - This worked like a Charm!!
I was working for one of my client and your code saved my ASS
Those who have complained that code did not work, please copy paste it correctly without spaces and when you add it on category.php template make sure you add it after this tag to make it work!
Code: Select all
<?php foreach ($products as $product) { ?>
Thx man!
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Wed May 09, 2012 12:17 am
by newdepth27
Thanks Werner for posting this code modification!
I am using OpenCart v1.5.1.3 and I was able to successfully display attributes on the category page using the code changes Werner provided above. I did run into one issue when modifying the code on the category.tpl. When I first pasted the code Werner provided for the category.tpl, I commented out this line
Code: Select all
<div class="description"><?php echo $product['description']; ?></div>
I then added the attributes code (provided by werner) below the commented out description code. At first, this caused the description on the category page to be displayed with a value of "null" and did not display the attributes. I then moved the attributes code so it was within the description <div> tags which fixed the problem and the attributes were displayed correctly on the category page. Below is the placement of the code modification for the category.tpl that worked for me:
Code: Select all
<div class="description"><!--<?php echo $product['description']; ?>-->
<?php if ($product['attribute_groups']) { ?>
<table class="cat-attributes">
<?php foreach ($product['attribute_groups'] as $attribute_group) { ?>
<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>
<?php } ?> </div>
Note that the category.tpl code Werner provided is within the description <div> tags.
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Tue Mar 05, 2013 4:15 am
by modernmagic
Since you figured out the syntax for attributes, is there a way to get specific fields from the product's Data tab to display in the product category view?
http://forum.opencart.com/viewtopic.php ... 86#p387486
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Wed Aug 07, 2013 4:38 am
by ssventerprises
Can some one be able to develop the below requirement.
Options of the product should be displayed in the category view.
upon selecting the option of product -displayed in category view the price should be updated for that options and should be added to cart.
I hope this above requirement can be only developed by adding AJAX code.
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Thu Jan 02, 2014 7:40 pm
by sant.battar
Hi ssventerprises,
I am also looking for the same extension did you have any luck in getting it work. Please let me know Thanks in advance
you can contact me @
sant.battar@gmail.com or you leave me your contact mail or number.
With Regards
Santosh
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Fri Oct 31, 2014 3:15 pm
by mousasoleymani
I need help
does anyone know how to add just one of the attribute from a group to category page.
for example if i have attribute A, B and C in one group i want to show only attribute A and when i try to add this code from this topic viewtopic.php?f=139&t=50476
<div class="description">
....
<span><?php echo $text_stock; ?></span> <?php echo $stock; ?>
<br/><br/>
<!-- Start Additional Info -->
<?php if ($attribute_groups) { ?>
<?php foreach ($attribute_groups as $attribute_group) { ?>
<?php if ($attribute_group['name'] == 'Product Info') { ?>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<span><?php echo $attribute['name']; ?></span> <?php echo html_entity_decode($attribute['text']); ?><br />
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
<!-- End Additional Info -->
</div>
it gives me this error
.... Notice: Undefined variable: text_stock in /home/public_html/catalog/view/theme/template/product/category.tpl on line 79 Notice: Undefined variable: stock in /home/public_html/catalog/view/theme/template/product/category.tpl on line 79
Notice: Undefined variable: attribute_groups in /home/public_html/catalog/view/theme/template/product/category.tpl on line 82
i would greatly appreciate if someone know how to fix this . thanks
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Thu Nov 27, 2014 1:11 am
by stefanl
Did you manage to resolve your issue with a single attribute?
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Thu Jan 01, 2015 9:47 pm
by cod3gen
I need two single attributes to show up on category page on frontend on 2.0.1.1... Any one got some tips for this?
Re: [SOLVED] Display attributes on Category and Mnufacturer
Posted: Thu Jan 08, 2015 8:10 pm
by hwctj
@stefani @cod3gen did you guys figure out how to display individual attributes?
Anyone know how to do this on version 1.5.6.4?
Re: [SOLVED] Display attributes on Category and Mnufacturer page
Posted: Fri Feb 14, 2020 11:29 pm
by bbrand
Hey Guys,
Here's a little fix for all of you using Opencart
3.0.3.2. I found that the fix was just slightly different then these instructions.
1) Modify the
catalog/controller/product/category.php exactly as the post describes with one small difference - you will find it under
add a comma at the end of the last line in the array or you will get a syntax error (should be line 206). On the next line add
Code: Select all
'attribute_groups' => $this->model_catalog_product->getProductAttributes($result['product_id'])
2) Open up
catalog/view/theme/default/template/product/category.twig file. cntl-f and search for
3) If you want to replace the description then delete <p>{{ product.description }}</p> and add the following in it's place. If you want to see the description followed by the attributes then add the following on the next line. You will notice that the syntax is slightly different than the original post.
Code: Select all
{% if product.attribute_groups %}
<table class="attribute">
{% for attribute_group in product.attribute_groups %}
<thead>
<tr>
<td colspan="2"><strong>{{ attribute_group.name }}</strong></td>
</tr>
</thead>
<tbody>
{% for attribute in attribute_group.attribute %}
<tr>
<td>{{ attribute.name }}</td>
<td>{{ attribute.text }}</td>
</tr>
{% endfor %}
</tbody>
{% endfor %}
</table>
{% endif %}