Jump to content

How to add attributes to product grid or list view in category


Recommended Posts

Hello,
I want to display attributes by v1.5x in product list view.
Has anyone done this before.

I've found a guide, but that does not work properly.

I thank you in advance....

 

i think about this module: list of attributes on product list view


 

For prestashop 1.5 blocklayered module overwrites the product list data so that's why the code is not working.
For demo purposes I left out getting the image of the color group attribute (the previous code is not displaying in product list anyway)
Also for simplicity I just modify core files

1. CategoryController.php
after:

$this->assignProductList();add:

foreach ($this->cat_products as $key => $product_item) {
$product = new Product($product_item['id_product'], false, self::$cookie->id_lang);
$colors = array();
$attributes = $product->getAttributeCombinations(self::$cookie->id_lang);
foreach ($attributes as $attribute_key => $attribute) {
if ($attribute['is_color_group'] > 0) {
$colors[$attribute['id_attribute']]['value'] = $attribute['attribute_name'];
}
}
$this->cat_products[$key]['colors'] = $colors;
}
2. modules/blocklayered/blocklayered.php
after:

$products = Product::getProductsProperties((int)$cookie->id_lang, $products);add:

foreach ($products as $key => $product_item) {
$product = new Product($product_item['id_product'], false, $cookie->id_lang);
$colors = array();
$attributes = $product->getAttributeCombinations($cookie->id_lang);
foreach ($attributes as $attribute_key => $attribute) {
if ($attribute['is_color_group'] > 0) {
$colors[$attribute['id_attribute']]['value'] = $attribute['attribute_name'];
}
}
$products[$key]['colors'] = $colors;
}
2. product-list.tpl:
inside:

<div class="center_block">add:

{if isset($product.colors)}{foreach from=$product.colors item=v}
<a style="background: {$v.value};" title="{$v.value}">&nbsp;&nbsp;&nbsp;&nbsp;</a>{/foreach}
{/if}
Link to comment
Share on other sites

  • 1 month later...

Hello;

I wonder if you could solve the problem of display attributes on the product list page, I have been looking for several days but I have not found anything that works on 1.5.4

thank you in advanceBonjour;

je me demande si tu as pu résoudre le problème d'affichage des attributs sur la page liste des produits, je cherche depuis plusieurs jours mais je n'ai rien trouvé qui fonctionne sur la 1.5.4

merci d'avance

Link to comment
Share on other sites

  • 4 weeks later...

It's not a simple task, even if you display the attributes on the product list page, there is a lot of Javascript code that needs to be added in order to properly handle all the combinations/ price impact / availability etc...

 

Check out the following module which makes it easy, and let you add attribute selection to any product on any page.

 

http://www.prestashop.com/forums/topic/79758-module-product-list-attributes-allow-customers-to-select-product-attributes-on-the-category-manufacturer-supplier-and-search-pages/

Link to comment
Share on other sites

Damn i dont want buy a module...

 

I now have product combinations and default combination ID on product-list.tpl but dunno how to get and change combination ID on change product attribute...

Link to comment
Share on other sites

We use product list attributes.

It works great.

It may not be cheap, but it's not an easy module to code either.

The main problem is not to show the attributes, but to correctly add them to the cart when the client clicks the button.

Link to comment
Share on other sites

Kerm: You can take a look at all the combination related Javascript code that is generated in product.tpl, and functions that are defined in product.js

 

You would basically need to replicate the code from product.tpl for every product in the product-list.tpl file, and create a modified version of the code from product.js, that will know to handle multiple products and not just one.

 

It is a pretty big job, which is not to say you should not have a go at it, just a friendly heads up about the complexity of the task.

  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...