Jump to content
pagineverdi

1.7.x - Display attributes (size and colors) of Product on Product List / Category Pages

Recommended Posts

Hi guys,
I need to print the product attributes (size / color) in the list of products in the category.

I have already edited the "posbestsellers", "posnewproducts" and "ps_categoryproducts" modules to display them, modifying their controllers by adding this:

foreach ($products as &$product) {
            $product_object = new Product((int)$product['id_product']);
            $groups = array();

            $attributes_groups = $product_object->getAttributesGroups($this->context->language->id);
            if (is_array($attributes_groups) && $attributes_groups) {
                foreach ($attributes_groups as $k => $row) {
                    if (!isset($groups[$row['id_attribute_group']])) {
                        $groups[$row['id_attribute_group']] = array(
                            'group_name' => $row['group_name'],
                            'name' => $row['public_group_name'],
                            'group_type' => $row['group_type'],
                            'default' => -1,
                        );
                    }

                    $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = array(
                        'name' => $row['attribute_name'],
                        'html_color_code' => $row['attribute_color'],
                        'texture' => (@filemtime(_PS_COL_IMG_DIR_.$row['id_attribute'].'.jpg')) ? _THEME_COL_DIR_.$row['id_attribute'].'.jpg' : '',
                        'selected' => (isset($product_for_template['attributes'][$row['id_attribute_group']]['id_attribute']) && $product_for_template['attributes'][$row['id_attribute_group']]['id_attribute'] == $row['id_attribute']) ? true : false,
                    );

                    if ($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1) {
                        $groups[$row['id_attribute_group']]['default'] = (int) $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']] += (int) $row['quantity'];
                }

                // wash attributes list (if some attributes are unavailables and if allowed to wash it)
                if (!Product::isAvailableWhenOutOfStock($product_object->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) {
                    foreach ($groups as &$group) {
                        foreach ($group['attributes_quantity'] as $key => &$quantity) {
                            if ($quantity <= 0) {
                                unset($group['attributes'][$key]);
                            }
                        }
                    }
                }
            }
            $product['groups'] = $groups;
        }

and printing in the theme template.

But I can't figure out how to make this change for the list of products in the categories.

Can someone help me?

Share this post


Link to post
Share on other sites

Did you find a solution?
This code can be use to call the single variants too? in product-variants.tpl I mean :( I don't know how to do it 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More