I am adding a condition to product listing in magento, Mage_Catalog_Block_Product_List

But when I've added the condition using getSelect, its not returning as collection as some of functions are missing like setCurrPage().

Basically I want to join catalog stock table to the product collection. Is there any other way around for this?

Note:: I am trying to override the file Mage_Catalog_Block_Product_List so the collection

$products = parent::_getProductCollection()->getSelect()->joinLeft( array('css'=> 'cataloginventory_stock_status'), 'css.product_id = e.entity_id', array('css.stock_status'));

return $products;

Just you need to add following line with your collection.

$collection = Mage::getResourceModel('catalog/product_collection');
$collection->getSelect()->joinLeft( array('css'=> cataloginventory_stock_status), 'css.product_id = main_table.entity_id', array('css.stock_status'));

It's working for me.

Happy Codding. :)

|improve this answer|||||
  • Didn't work for me.I am overriding the file Mage_Catalog_Block_Product_List, but once you applied the getSelect then its not a collection anymore. You won't get any collection properties from that output.I don't know what to do – Rinto George Mar 16 '16 at 12:26
  • can you share your code here? – Ajay Patel Mar 16 '16 at 12:33
  • hey. can you print $products?? its return data or not? – Ajay Patel Mar 16 '16 at 12:38
  • try updated answer. – Ajay Patel Mar 16 '16 at 12:42
  • I don't need to write the collection its already there , I just want to add some condition to collection, if you use getSelect, its not a collection anymore, it won't have any collection features – Rinto George Mar 16 '16 at 12:46

After doing research of 1 day I got the answer.

$collection->getSelect()->joinLeft( array('css'=> 'cataloginventory_stock_status'), 'css.product_id = e.entity_id', array('css.stock_status'))->where('css.stock_id=3')->where('css.stock_status=1')->group('e.entity_id');

So setCollection was making the select statement to collection object again.


Thanks everyone.

|improve this answer|||||

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.