Hai
If i enabled flat category, attributeToSort(),addAttributeToSelect() is not working.Below is my code.It is happening in categories filter.
$storecats ->addAttributeToSort(‘featured_category_order’, ‘ASC’);
$storecats->addAttributeToSelect(‘image’);
$filterquery = new \Zend_Db_Expr(‘ISNULL(featured_category_order),featured_category_order ASC’);
$storecats->getSelect()->reset(‘order’)->order($filterquery);
Can you provide the solution?
Hai
If i enabled flat category, attributeToSort(),addAttributeToSelect() is not working.Below is my code.It is happening in categories filter.
$storecats ->addAttributeToSort(‘featured_category_order’, ‘ASC’);
$storecats->addAttributeToSelect(‘image’);
$filterquery = new \Zend_Db_Expr(‘ISNULL(featured_category_order),featured_category_order ASC’);
$storecats->getSelect()->reset(‘order’)->order($filterquery);
Can you provide the solution?
Use this collection factory,
public function __construct(
…
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
…
) {
…
$this->_categoryFactory = $categoryFactory;
…
}
public function getAllCategories()
{
$categoriesCollection = $this->_categoryFactory->create()->getCollection()->addAttributeToSelect(’*’)
->addAttributeToFilter(‘is_featured’,1)
->addAttributeToFilter(‘is_active’,1);
return $categoriesCollection;
}