0

I am trying to sort a product collection by an attribute that is of the 'select' type with lots of option values, all of which have sort order positions set. My attribute is called 'style'.

When I set my product collection to sort by the attribute I do get it sorted by that attribute, albeit alphabetically, not as per the position values.

    $collection = $this->_addProductAttributesAndPrices($collection)
        ->addStoreFilter()
        ->addAttributeToSort('style', 'asc')
        ->setPageSize($this->getProductsCount())
        ->setCurPage(1)
    ;

This sorts the products alphabetically by style name (not style sort order values).

I have tried really hard to try to work out how to fix this.

As an added complication I am using 'flat tables' in the frontend.

Any ideas?

0

Try with style_value instead of style,if flat table is enable.

  • Thanks but the style_value is the option values, not the option sort order values, therefore it still sorts alphabetically. – Henry's Cat Apr 21 '16 at 13:07

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.