I have a collection of products which I filter and show out of stock items only and it works fine. This is what I have:
$collection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*');
$collection->joinField('qty','cataloginventory/stock_item','qty','product_id=entity_id','{{table}}.stock_id=1','left')
->addAttributeToFilter('qty', array('eq' => 0));
I wanted to sort by Price so I added this:
$collection->setOrder('price', 'desc');
Unfortunately this does not work. and I get a blank page.
If I change the Filter on the Join to show in stock products it works and will show in the correct order
->addAttributeToFilter('qty', array('neq' => 0));
What am I missing?
Update:
I removed the filter completely and sorted the collection and it only shows in stock products. It refuses to show out of stock products after sorting.
Update:
If I show out of stock products on front end it works:
Admin >> System >> Configuration >> Catalog >> Inventory >> Stock Options
Display Out of Stock product -> Yes
I do not want to show out of stock products on the front end though, only in this collection.