Click here to Skip to main content
15,895,370 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
                    }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900