I have entity
\Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection
And I'm trying following
$categoryCollection->addAttributeToSelect('image');
but this doesn't work for me. Any ideas?
I have entity
\Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection
And I'm trying following
$categoryCollection->addAttributeToSelect('image');
but this doesn't work for me. Any ideas?
I've done a small debug and found out that addAttributeToSelect have the second parameter
public function addAttributeToSelect($attribute, $joinType = false)
In my case catalog/frontend/flat_catalog_category configuration option was disabled. So I think for disabled flat category joinType should be true. I've added the following
\Magento\Catalog\Model\Indexer\Category\Flat\State $flatState
to the constructor. And this works for me like a charm
if ($this->flatState->isAvailable()) {
$this->categoryCollection->addAttributeToSelect('image');
} else {
$this->categoryCollection->addAttributeToSelect('image', true);
}
public function __construct( .... \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $catalogCategoryCollectionFactory, .... ) { $this->catalogCategoryCollectionFactory= $catalogCategoryCollectionFactory; } public function getMyCategoryCollection() { $categoryCollection =$this->catalogCategoryCollectionFactory->create(); $categoryCollection->addAttributeToSelect('image'); }– Amit Bera Aug 03 '18 at 17:39