4

I have an import routine that needs to be run periodically to mass-import categories.

It processes a tree like structure of category data, and creates any categories that don't exist. The difficulty I face is that because flat catalog is enabled on the store, even after the category is created, it thinks it isn't as the index is set to manual.

I read to use the following when retrieving the category collection, to ensure the flat catalog is not used:

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

However, I can see that the returned resource is still a flat catalogue one - and my import again fails (it works if I disable the flat catalog in the admin area).

What can I do to resolve this issue?

1 Answer 1

3

I stumbled on the solution to the issue I was having. I had to change the line to the following:

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

So, I added setDisableFlat(true) to the getModel('catalog/category') call - this then returned a catalog/category_collection instead of the catalog/category_flat_collection object.

If I removed array('disable_flat' => true) then I get the following error:

Call to undefined method 
Mage_Catalog_Model_Resource_Category_Flat_Collection::setDisableFlat()

I read about programmatically disabling the flat category catalog from several sources and not once was the above info provided, so whether this a version specific issue or not, hopefully someone will find this answer useful.

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.