2

I have csv flat file with the items and with the category and subcategories attached to this item. Using this file i have to create a categories tree. I have this piece of code:

there is a loop here and some code to get data from file line by line{        
$category = Mage::getModel('catalog/category');
           $category->setName($level);
           $category->setUrlKey(strtolower($level));
           $category->setIsActive(1);
           $category->setDisplayMode('PRODUCTS');
           $category->setIsAnchor(1);
           $category->setStoreId(1);
           $category->setPath($parent_path);
           $category->save();
}

and generally it works fine but because of save() method in loop it takes ages... how could I optimize it? I tried to move save() outside the loop but it doesn't work also saveAttribute() method doesn't work.

2

There is no other build in way for categories.
and calling saveAttribute does not work because the category does not exist yet.
You can try to create something similar to the product import that bypasses the save method and writes directly in the tables, but I have no idea on how you can start on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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