take a look at this method Mage_Catalog_Model_Resource_Product_Collection::_construct
protected function _construct()
{
if ($this->isEnabledFlat()) {
$this->_init('catalog/product', 'catalog/product_flat');
}
else {
$this->_init('catalog/product');
}
$this->_initTables();
}
this means that the collection will use flat tables if the result of isEnabledFlat
is true.
If you look at the isEnabledFlat
you will see that it returns false for the admin otherwise it returns the status of the flat flag for each store. Actually it's more than that. even if the flag is enabled it may return false if the the flat index is not up to date.
So what you can do is add this at the top of your code:
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
This will make the collection use the admin store.
[EDIT]
If you use this on frontend you will get issues, because you will see the values from admin and you don't want that.
My second idea is to rewrite the product collection model and change the behavior of the method isEnabledFlat
and make it look like this:
public function isEnabledFlat()
{
//add this
if (Mage::registry('use_product_eav')) {
return false;
}
return parent::isEnabledFlat();
}
then all you have to do is add in your code this Mage::register('use_product_eav', true)
before instantiating your collection.
Make sure you call Mage::unregister('use_product_eav')
after instantiating it if you don't want the rest of the page to use eav tables.