nughett Posted February 15, 2011 Posted February 15, 2011 Here's non-paid solution, that's still in development. When I was looking for solution I realized how many people are asking for this feature, so I was trying hard to find out how it works, and I'm happy that I can share this solution. There's a little problem that I still cannot fix. If you click on Add to cart in category view, it ignores attribute you selected. This is solved quite well for quantity in category view (hyperlink included at the bottom of this post) but I still cannot fix this for attributes, any help would be appreciated. Here's the solution:category.php - add this on line 63: foreach ( $cat_products as $key => $cat_product ) { $product = new Product ( intval ( $cat_product[ 'id_product' ] ), true , intval ( $cookie -> id_lang )); $colors = array(); $groups = array(); $attributesGroups = $product -> getAttributesGroups ( intval ( $cookie -> id_lang )); if ( Db :: getInstance ()-> numRows ()) { foreach ( $attributesGroups AS $k => $row ) { if (isset( $row[ 'attribute_color' ] ) AND $row[ 'attribute_color' ] AND $row[ 'id_attribute_group' ] == $product -> id_color_default ) { $colors[$row[ 'id_attribute' ]][ 'value' ] = $row[ 'attribute_color' ] ; $colors[$row[ 'id_attribute' ]][ 'name' ] = $row[ 'attribute_name' ] ; $colors[$row[ 'id_attribute' ]][ 'id_image' ] =(( $row[ 'id_image' ] != NULL ) ? intval ( $row[ 'id_image' ] ) : - 1 ); } $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name']; $groups[$row['id_attribute_group']]['name'] = $row['public_group_name']; $groups[$row['id_attribute_group']]['is_color_group'] = $row['is_color_group']; if ($row['default_on']) $groups[$row['id_attribute_group']]['default'] = intval($row['id_attribute']); if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0; $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += intval($row['quantity']); $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes'][] = intval($row['id_attribute']); $combinations[$row['id_product_attribute']]['price'] = floatval($row['price']); $combinations[$row['id_product_attribute']]['ecotax'] = floatval($row['ecotax']); $combinations[$row['id_product_attribute']]['weight'] = floatval($row['weight']); $combinations[$row['id_product_attribute']]['quantity'] = intval($row['quantity']); $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; $combinations[$row['id_product_attribute']]['id_image'] = isset($combinationImages[$row['id_product_attribute']][0]['id_image']) ? $combinationImages[$row['id_product_attribute']][0]['id_image'] : -1; } } //wash attributes list (if some attributes are unavailables and if allowed to wash it) if (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) { foreach ($groups AS &$group) foreach ($group['attributes_quantity'] AS $key => &$quantity) if (!$quantity) unset($group['attributes'][$key]); foreach($groups AS &$group) natcasesort($group['attributes']); foreach ($combinations AS $id_product_attribute => $comb) { $attributeList = ''; foreach ($comb['attributes'] AS $id_attribute) $attributeList .= '\''.intval($id_attribute).'\','; $attributeList = rtrim($attributeList, ','); $combinations[$id_product_attribute]['list'] = $attributeList; } } $cat_products[$key][ 'colors' ] = $colors; $cat_products[$key][ 'groups' ] = $groups; $cat_products[$key][ 'combinations' ] = $combinations; $cat_products[$key][ 'combinationImages' ] = $combinationImages; } To be continued in the next post. 1 Share this post Link to post Share on other sites More sharing options...
nughett Posted February 15, 2011 Posted February 15, 2011 product-list.tpl - add this to whatever column you want, I added it to center_column {if !empty($product.groups)} <!-- attributes --> {foreach from=$product.groups key=id_attribute_group item=group} {if $group.attributes|@count} {$group.name|escape:'htmlall':'UTF-8'} : {assign var='groupName' value='group_'|cat:$id_attribute_group} 0}$('#wrapResetImages').show('slow');{/if}"> {foreach from=$group.attributes key=id_attribute item=group_attribute} {$group_attribute|escape:'htmlall':'UTF-8'} {/foreach} <input type="hidden" name="id_product_attribute" id="idCombination" value="" /> {/if} {/foreach} {/if} {if !empty($product.colors)} {foreach from=$product.colors key=id_attribute item=color } {/foreach} {/if} And the promised hyperlink: http://www.prestashop.com/forums/viewthread/28136/ Share this post Link to post Share on other sites More sharing options...
SoloWeb Posted March 2, 2011 Posted March 2, 2011 nice job man , thanks Share this post Link to post Share on other sites More sharing options...
asenik Posted June 15, 2011 Posted June 15, 2011 not working for me ((( in which folder lying a file category.php? after which code in category.php should I insert code from the first post?And after which code in product-list.tpl should I insert code from the second post? Share this post Link to post Share on other sites More sharing options...
buzuchok Posted August 2, 2011 Posted August 2, 2011 1.4 version, doesn't work. Here I made changes in CategoryController.php (lines 142-232). Any suggestions? CategoryController.php Share this post Link to post Share on other sites More sharing options...
freeset Posted August 4, 2011 Posted August 4, 2011 1.4 version, doesn't work. Here I made changes in CategoryController.php (lines 142-232). Any suggestions? Any luck getting this to work buzochok? Share this post Link to post Share on other sites More sharing options...
Nikpro Posted October 27, 2011 Posted October 27, 2011 how to change controller ? Share this post Link to post Share on other sites More sharing options...
NithyaStephen Posted February 21, 2012 Posted February 21, 2012 can you find the solution for this same problem in version 1.4.7.0 Share this post Link to post Share on other sites More sharing options...
groenroos Posted May 28, 2012 Posted May 28, 2012 I used this code, and got it working with slight modifications. Replace this; $attributesGroups = $product->getAttributesGroups(intval($cookie->id_lang)); With this; $attributesGroups = $product->getAttributesGroups(intval($cookie->id_lang), $product->id); -- Replace this; foreach ($group['attributes_quantity'] AS $key => &$quantity) if (!$quantity) unset($group['attributes'][$key]); With this; foreach ($group['attributes_quantity'] AS $key2 => &$quantity) if (!$quantity) unset($group['attributes'][$key2]); -- Replace this; $cat_products[$key][ 'colors' ] = $colors; $cat_products[$key][ 'groups' ] = $groups; $cat_products[$key][ 'combinations' ] = $combinations; $cat_products[$key][ 'combinationImages' ] = $combinationImages; With this; $this->cat_products[$key][ 'colors' ] = $colors; $this->cat_products[$key][ 'groups' ] = $groups; $this->cat_products[$key][ 'combinations' ] = $combinations; $this->cat_products[$key][ 'combinationImages' ] = $combinationImages; -- In classes/Product.php, find the getAttributesGroups function (line 2204), and replace the whole function with this; public function getAttributesGroups($id_lang, $product_id = NULL) { if($product_id == NULL) $product_id = (int)($this->id); if($id_lang == 0) $id_lang = 1; return Db::getInstance()->ExecuteS(' SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, pa.* FROM `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group` LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON a.`id_attribute` = al.`id_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON ag.`id_attribute_group` = agl.`id_attribute_group` WHERE pa.`id_product` = '.$product_id.' AND al.`id_lang` = '.(int)($id_lang).' AND agl.`id_lang` = '.(int)($id_lang).' ORDER BY agl.`public_name`, al.`name`'); } I don't know if all these modifications are actually necessary, since I tried a lot of things and I'm not a Prestashop [spam-filter] or anything, but this got it working for me. 1 Share this post Link to post Share on other sites More sharing options...
Andrii Posted June 23, 2012 Posted June 23, 2012 product-list.tpl - add this to whatever column you want, I added it to center_column It is difficult to copy the code, so http://srcboard.com/dfox72 1 Share this post Link to post Share on other sites More sharing options...
josal Posted November 23, 2012 Posted November 23, 2012 Anyone to explain a little better the final modifications? At last, the place to do them is not clear at all... I've tested some places but it's not working. Thanks in advance!! Share this post Link to post Share on other sites More sharing options...
domrod Posted March 23, 2013 Posted March 23, 2013 Same here Anyone to explain? Thanks! Share this post Link to post Share on other sites More sharing options...
tomerg3 Posted March 23, 2013 Posted March 23, 2013 This is not a simple change, certainly not in PS 1.5, and by taking a quick look at the code that was posted in this thread, I don't see any way it would be working, as there is no Javascript anywhere, and a lot of it is required for proper use. You can see the following module, which lets you add attributes in category pages (or any other product on any page) at http://www.prestashop.com/forums/index.php?/topic/79758-module-product-list-attributes-allow-customers-to-select-product-attributes-on-the-category-manufacturer-supplier-and-search-pages/ Share this post Link to post Share on other sites More sharing options...
killerkhan Posted May 19, 2013 Posted May 19, 2013 Hello tomerg3, I am also looking for solution of the same. But your module is so costly. Any help in this regard is much appreciated. Thanks 1 Share this post Link to post Share on other sites More sharing options...
rik79 Posted November 11, 2014 Posted November 11, 2014 Ciao vorrei poter aggiungere gli attributi prodotto, il campo quantità con + e - oltre al tasto Acquista all'interno della tab Accessori utilizzo la versione Prestashop 1.6.0.9, qualche suggerimento? Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now