3

I want to disable the flat_catalog on run time for my collection. I am adding the filters but they are causing the problem because of flat_catalog. I want to disable the flat catalog on processing time.

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('*')
    ->addFieldToFilter('configurator_product_category', array('notnull' => true))
    ->addFieldToFilter('conf_diepte', array('in', $SelectedOptionId));
8
  • It can be done - you need to extend the product collection model and allow the use flat tables setting to be passed as a constructor or setter argument
    – scrowler
    Jul 27, 2016 at 7:46
  • 2
    why not just make your attributes be used in product listing? you solve the problem without workarounds.
    – Marius
    Jul 27, 2016 at 7:52
  • 2
    Well what is the original problem you're facing With flat catalog enabled ? I reckon it'd be better to fix it than over passing it ;) Jul 27, 2016 at 7:57
  • @Marius i will try that.. Jul 27, 2016 at 8:02
  • @RaphaelatDigitalPianism filter not working ->addFieldToFilter('conf_diepte', array('in', $SelectedOptionId)); disabled the flat_catalog is doing trick. Jul 27, 2016 at 8:21

1 Answer 1

4

No need to extend product collection model you can do it on run time by

For Products

$process = Mage::helper('catalog/product_flat')->getProcess();
$status = $process->getStatus();
$process->setStatus(Mage_Index_Model_Process::STATUS_RUNNING);
/** @var $collection Mage_Catalog_Model_Resource_Product_Collection */
$collection = Mage::getModel('catalog/product')->getCollection();
    $collection->addAttributeToSelect('*')
               ->addFieldToFilter('configurator_product_category', array('notnull' => true))
               ->addFieldToFilter('conf_diepte', array('in', $SelectedOptionId));
// ... custom stuff
$process->setStatus($status);

For Category

$collection = Mage::getModel('catalog/category', array('disable_flat' => true))->getCollection();

Reference

Your Answer

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

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