Post by monkeyplay » Mon Oct 31, 2011 11:05 pm

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

Newbie

Posts

Joined
Sun Sep 18, 2011 2:03 am

Post by wernerrenrew » Tue Nov 01, 2011 3:22 pm

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 ;D

Best regards Werner
Last edited by wernerrenrew on Fri Jan 20, 2012 12:56 am, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Thu Oct 27, 2011 9:48 pm
Location - Netherlands

Post by monkeyplay » Tue Nov 01, 2011 5:29 pm

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

Newbie

Posts

Joined
Sun Sep 18, 2011 2:03 am

Post by wernerrenrew » Tue Nov 01, 2011 11:09 pm

Good to hear,

Your welcome ::)

User avatar
Active Member

Posts

Joined
Thu Oct 27, 2011 9:48 pm
Location - Netherlands

Post by remcofaasse » Fri Dec 16, 2011 8:53 pm

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!

New member

Posts

Joined
Mon Dec 05, 2011 2:20 am

Post by w1nt » Sat Jan 21, 2012 2:35 am

Hi,
I'm also need this functionality on OC v1.5.13,
just try above tutorial and not working

please help...

thanks & regards

Newbie

Posts

Joined
Wed Jan 11, 2012 4:19 pm

Post by andreicon » Tue Jan 31, 2012 12:42 am

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!

Newbie

Posts

Joined
Mon Jan 30, 2012 2:14 am

Post by rajbrothers » Thu Apr 12, 2012 12:41 am

Thanks Bro! - This worked like a Charm!!

I was working for one of my client and your code saved my ASS ;D

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!

Newbie

Posts

Joined
Thu Apr 12, 2012 12:38 am

Post by remcofaasse » Fri Apr 13, 2012 12:09 am

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.

New member

Posts

Joined
Mon Dec 05, 2011 2:20 am

Post by pasha_st » Wed Apr 18, 2012 2:52 am

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 :-[

Newbie

Posts

Joined
Sat Aug 20, 2011 5:36 pm

Post by remcofaasse » Thu Apr 26, 2012 10:03 pm

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 ;D

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!

New member

Posts

Joined
Mon Dec 05, 2011 2:20 am

Post by newdepth27 » Wed May 09, 2012 12:17 am

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.

Newbie

Posts

Joined
Tue May 08, 2012 5:26 am

Post by modernmagic » Tue Mar 05, 2013 4:15 am

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

Joomla Web Site Designer at www.modernmagic.com


User avatar
New member

Posts

Joined
Sat Feb 09, 2013 4:55 am


Post by ssventerprises » Wed Aug 07, 2013 4:38 am

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.

Attachments

product with options in category view.png

Product with options in category view. - product with options in category view.png (139.47 KiB) Viewed 23970 times



Posts

Joined
Fri Aug 02, 2013 7:18 pm

Post by sant.battar » Thu Jan 02, 2014 7:40 pm

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

Newbie

Posts

Joined
Sun Jun 09, 2013 5:34 pm

Post by mousasoleymani » Fri Oct 31, 2014 3:15 pm

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


Posts

Joined
Fri Oct 31, 2014 2:19 am

Post by stefanl » Thu Nov 27, 2014 1:11 am

Did you manage to resolve your issue with a single attribute?

Newbie

Posts

Joined
Wed Apr 16, 2014 7:00 am

Post by cod3gen » Thu Jan 01, 2015 9:47 pm

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?

Newbie

Posts

Joined
Thu Jan 01, 2015 9:46 pm

Post by hwctj » Thu Jan 08, 2015 8:10 pm

@stefani @cod3gen did you guys figure out how to display individual attributes?
Anyone know how to do this on version 1.5.6.4?

Newbie

Posts

Joined
Thu Nov 21, 2013 1:17 am
Who is online

Users browsing this forum: No registered users and 6 guests