I'm trying to order products by position in category
public function __getProductCollection($category_id_array) {
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addCategoriesFilter(['in' => $category_id_array]);
$collection->addAttributeToFilter('visibility', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);
$collection->addAttributeToFilter('status', \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
//$collection->addAttributeToSort('position');
$collection->setOrder('position','ASC');
return $collection;
}
I got this error
Unknown column 'cat_index_position' in 'order clause'
I tried also
$collection->setOrder('cat_index_position','ASC');
$collection->setOrder('cat_index.position','ASC');
But the ordering is not working
PS: i'm using Magento 2.2.4
$collection->getSelect()->reset(Zend_Db_Select::ORDER)->order('position', 'ASC');
if it helps!