1

I want to get all products including disabled and enabled in one of my static page.

I am fetching product collection like

$videoProduct = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->addFieldToFilter('manufacturer_value', array('in' => array($brand)))
    ->addAttributeToFilter('is_option', 0);

Where $brand is an array of multiple ids'. To get all products I read somewhere to disable relation between product flat table.

It does not work for me to set "NO" to catalog flat table relation under magento admin panel.

Anyone let me know if I can get it via getCollection() method.

1
  • 1
    Could you update your answer with the output of the $videoProduct->getSelectSql(true)? Jun 6, 2017 at 14:18

2 Answers 2

1

$collection = Mage::getModel('catalog/product')->getCollection();

Note that for getting all the products including the Disabled product you have to

Change the config Use Flat Catalog Product to "NO".

You will find the settings in System -> Configuration -> Catalog -> Frontend

0

if you look to the core source code in app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php::_initSelect()

protected function _initSelect()
{
    if ($this->isEnabledFlat()) {
        $this->getSelect()
            ->from(array(self::MAIN_TABLE_ALIAS => $this->getEntity()->getFlatTableName()), null)
            ->where('e.status = ?', new Zend_Db_Expr(Mage_Catalog_Model_Product_Status::STATUS_ENABLED));
        $this->addAttributeToSelect(array('entity_id', 'type_id', 'attribute_set_id'));
        if ($this->getFlatHelper()->isAddChildData()) {
            $this->getSelect()
                ->where('e.is_child = ?', 0);
            $this->addAttributeToSelect(array('child_id', 'is_child'));
        }
    } else {
        $this->getSelect()->from(array(self::MAIN_TABLE_ALIAS => $this->getEntity()->getEntityTable()));
    }
    return $this;
}

you can see that the filter on enabled products is only present when the catalog flat product feature in enabled.

So, it is strange that disabling it is not working for you. (maybe the source code is not the same as mine or you have already a rewrite of this class)

But, in case you want to use this "catalog flat product" feature, I think the simple way is to use a rewrite of the class Mage_Catalog_Model_Resource_Product_Collection and change the method _initSelect().

Hope it will help.

Best Regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.