Jump to content

Attributes in product-list section


Recommended Posts

Well, I figured out a starting point, at least I guess.


        /* colors */
foreach ( $cat_products as $key => $cat_product ) {
$product = new Product ( intval ( $cat_product[ 'id_product' ] ), true , intval ( $cookie -> id_lang ));
$colors = array();
$attributesGroups = $product -> getAttributesGroups ( intval ( $cookie -> id_lang ));
if ( Db :: getInstance ()-> numRows ())
{
foreach ( $attributesGroups AS $k => $row )
{
/* Color management */
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) OR 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;
               }


$smarty->assign(array(
                   'groups' => $groups,
                   'default_product_tax' => $tax_datas['rate'],
                   'combinaisons' => $combinations, /* Kept for compatibility purpose only */
                   'combinations' => $combinations,
                   'colors' => (sizeof($colors) AND $product->id_color_default) ? $colors : false,
                   'combinationImages' => $combinationImages));

}




I put that code to category.php in root directory on line 63.



Then I took this code:

{if isset($groups)}
           <!-- attributes -->

           {foreach from=$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}


           {/if}
           {/foreach}

           {/if}



And put it into product-list.tpl in center_block or whethever you like to put it. And it really shows attributes in product-list view. The problem is that it shows same group of attributes at every product. I didn't figure it out how to fix this. I really need some help with this stuff. Thanks.

Link to comment
Share on other sites

  • 2 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...