cancel
Showing results for 
Search instead for 
Did you mean: 

Product Categoy creation

SOLVED

Product Categoy creation

Hey again,

at the moment i'm trying to import product categories to my magento installation, but it's not working properly. I'm able to save the created category, without any Magento errors. Rows with my data were created in the database tables catalog_category_entity_text, catalog_category_entity_varchar and catalog_category_entity_int, but my new categories are not visible in the backend.
I'm trying to add them as root categories.

 

 

$mCat = Mage::getModel('catalog/category');
$mCat
	->setName($vmCat['category_name'])
	->setParentId(1)
	->setLevel(1)
	->setAvailableSortBy('name')
	->setDefaultSortBy('name')
	->setIsActive(true)
	->setPosition($vmCat['list_order']);
			
try {
	$mCat->save();
}
catch (Exception $e) {
	Zend_Debug::dump($e->getMessage());
}

 

 

Help would be very  appreciated. Smiley Happy

Thanks
Nik

3 REPLIES

Re: Product Categoy creation

parent_id and level are set automatically by path, so it will be like this

$mCat = Mage::getModel('catalog/category');
$mCat
	->setName($vmCat['category_name'])
	->setPath(1)
	->setAvailableSortBy('name')
	->setDefaultSortBy('name')
	->setIsActive(true)
	->setPosition($vmCat['list_order']);
			
try {
	$mCat->save();
}
catch (Exception $e) {
	Zend_Debug::dump($e->getMessage());
}

Re: Product Categoy creation

My reply with links to the simply gets disappear. It gets posted but when I re-look it its missing in the follow-up. Group admin please look into the issue.

Re: Product Categoy creation

Thanks for your reply @KuafuSoft,

 

you were right about the path, setting the parent category ID automatically.

 

$storeId = $this->store->getId();
$mCat = Mage::getModel('catalog/category');
$mCat
	->setStoreId($storeId)
	->setName($vmCat['category_name'])
	->setDescription($vmCat['category_description'])
	->setPath( Mage::getModel('catalog/category')->load($mCatParentId)->getPath() )
	->setAvailableSortBy('name')
	->setDefaultSortBy('name')
	->setIsActive(true)
	->setPosition($vmCat['list_order']);
	
try {
	$mCat->save();
} catch (Exception $e) {
	echo Mage::log( $e->getMessage() );
}

Regards

Nik