0

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;
1

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'));
$collection->setPageSize($this->getConfig('qty'))->setCurPage(1);

It's working for me.

Happy Codding. :)

  • 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
0

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');
$this->setCollection($collection);

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

$this->setCollection($collection);

Thanks everyone.

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.