1

when i try to insert new category in database no error appear and no category inserted here is my code what is wrong

not that the new categories are parent not child


$cat_arr have some categories

try{
                $category = Mage::getModel('catalog/category');
                foreach ($cat_arr as $cat ) {


                        $category->setName($cat['shortName']);
                        $category->setUrlKey($cat['localizedId']);
                        $category->setIsActive(1);
                        $category->setDisplayMode('PRODUCTS');
                        $category->setIsAnchor(1); //for active achor
                        $category->setDescription($cat['name']);

                        $category->setStoreId(Mage::app()->getStore()->getId());
                        $category->setAttributeSetId($category->getDefaultAttributeSetId());
                        // $parentCategory = Mage::getModel('catalog/category')->load($parentId);
                        // $category->setPath($parentCategory->getPath());

                        $category->save();
                    }
                    } catch(Exception $e) {
                        var_dump($e);
                    }
0

issue1:

 $category = Mage::getModel('catalog/category'); code inside for
loop

Issue2:

check list of attribute which is  in  category using
below code

 foreach ($category->getAttributes() as $attribute) 
}
  • code $category = Mage::getModel('catalog/category'); code inside for loop you mean that i should put it inside loop ?? – Mohamed Abdelrahman Oct 1 '14 at 16:35
  • Yea,,,............. – Amit Bera Oct 1 '14 at 16:39

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.