0

I have created a custom script to display products on home page filter by product ids.

$_productCollection = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('entity_id', array('in' => $product_ids))
                ->addAttributeToFilter('status', array('eq' => 1))
                ->addAttributeToFilter('visibility', 4);

But products showing on frontend in entity_id (ASC) orders. To order by product_ids array I found below code and it is working :

$_productCollection->getSelect()->order(new Zend_Db_Expr('FIELD(entity_id, ' . $product_ids.')'))

But whenever php shell/indexer.php -reindex catalog_product_flat index is in processing this line shows error on frontend there has been error processing your request.

This error still coming If catalog flat tables setting are disabled in admin panel and no index is in processing state.

Why this is happening?

0

Finally, I found the solution. The error was coming because of unknown column. Just changed entity_id to e.entity_id in order query as below :

$_productCollection->getSelect()->order(new Zend_Db_Expr('FIELD(e.entity_id, ' . $product_ids.')'))

And the code is working now.

Hope this will help someone.

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.