0

How do I add an attribute + it's sortorder (position) to the product list collection?

In the catalog category list we use 1 text attribute (brand) and 1 list attribute (size) .... for every product we have to use getAttribute() and getAttributetext() ....

BUt: how can I

  1. add the brand attribute to the list collection?
  2. add the size attribute + it's position (sort order) to the list collection?

Can this easily be added to the query? or how do I do this?

thanks!

0

Copy the file \app\code\core\Mage\Catalog\Block\Product\List.php to \app\code\local\Mage\Catalog\Block\Product\List.php

In the function _getProductCollection after the statement

$this->_productCollection = $layer->getProductCollection();

add below code.

$this->_productCollection->addAttributeToSelect('brand')->addAttributeToSelect('size')->setOrder('size','DESC');

You can also override the List class by adding below code into a custom module's config.xml.

<config>
    <global>
        <blocks>
            <catalog>
                <rewrite>
                    <product_list>Custom_Module_Block_Product_List</product_list>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>
  • Thx. This looks almost complete. But I don't see how we are retrieving the position column of the attribute – snh_nl Jan 7 '17 at 17:08
  • You mean you want to add position of options of the attribute size? – piyush_systematix Jan 7 '17 at 17:18
  • I eventually need to sort by the attribute position of the options. Yes. – snh_nl Jan 7 '17 at 17:21
  • Also does the query get the language specific version? And if not exist fallback to default/admin value. Seems difficult to do .... – snh_nl Jan 7 '17 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.