3

I've created a new product attribute 'brand'. This attribute is within my default attribute set. Now I'm trying to get all brands from a product collection within a category.

I'm fetching the product collection:

$products = $this->_productCollectionFactory ->addAttributeToSelect('brand') ->addCategoryFilter($activeCategory) ->load(); 

But the brand is not displayed? The attribute brand is just a simpel text attribute. How can I fetch all brands from this collection?

Thanks

2
  • did you rebuild the indexes? If you have flat catalog enabled, did you mark the attribute as "used in product listing"? Commented Feb 29, 2016 at 15:58
  • Marius, thanks a lot. The option 'Used in product listing' was the fix! Commented Feb 29, 2016 at 17:10

1 Answer 1

8

Based on the comments...
when using an attribute in a product collection, if the flat catalog is enabled, the attribute must be marked as Used in product listing in order to be picked up by the collection.

6
  • What if flat catalog isn't enabled? Commented May 17, 2017 at 21:27
  • @SteveRobbins with flat catalog disabled it should work with out any additional actions. Commented May 18, 2017 at 6:01
  • Update for 2019: Flat Catalog is considered a performance drag. It should be disabled. Commented Dec 11, 2019 at 17:35
  • Hello @Marius, I have disabled Flat Catalog, And in my custom collection I want few attributes like: $collection->addAttributeToSelect(['special_discount', 'special_discount_value', 'special_offer']);. But this is not working. Once I enabled Flat Catalog it's working. How can I achieve this with Flat Catalog disabled value. Can you please suggest. Commented Feb 25, 2020 at 10:01
  • with flat catalog disabled it should work as you do it. I have no idea why it doesn't Commented Feb 25, 2020 at 11:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.