cancel
Showing results for 
Search instead for 
Did you mean: 

Help!!, I need to create/import 5000 categories

Help!!, I need to create/import 5000 categories

Hey

 

magento 1.9.3.7

 

I need to create 5000 categories, in 2 levels under Default category.

Also I need to import 180000 products into these categories. For importing products I use a script that generate csv file of the products to be imported. In this csv file I want to specify categories like this: Default Category, Sub Category, SubSub Category - Meaning each product is added to 3 categories.....

 

Now I have been googling and I found this script which I have modified a bit.. Not sure why but it gives no info on the screen when executed. Is it .htaccess issue?

<?php
	echo "step 1<br />";
  $file = fopen("audun_cat.csv","r");
  $mageFilename = 'app/Mage.php';
  require_once $mageFilename;
  Mage::setIsDeveloperMode(true);
  ini_set('display_errors', 1);
  error_reporting(E_ALL);
  umask(0);
  echo "step 2<br />";
  Mage::app('admin');
  Mage::register('isSecureArea', 1);
  $parentId = '2';*/
  echo "step 3<br />";
  while(! feof($file)) {
    	
    	$read = fgetcsv($file);
    	echo $read[0] . "<br>";    	
    	
      $category = Mage::getModel('catalog/category');
      $category->setName($read[0]);
      $category->setUrlKey(urlencode($read[0]));
      $category->setIsActive(1);
      $category->setDisplayMode('PRODUCTS');
      $category->setIsAnchor(1); //for active anchor
      $category->setStoreId(Mage::app()->getStore()->getId());
      $parentCategory = Mage::getModel('catalog/category')->load($parentId);
      $category->setPath($parentCategory->getPath());
      $category->save();

	}
?>

How do you recommend me do it? If I need to do it manually I can say good bye to Christmas Smiley Sad

1 REPLY 1

Re: Help!!, I need to create/import 5000 categories

Hi @Loginname,

 

Using Magento OOTB you can use the Dataflow. When you export products you'll get a category called: "category_ids"

 

You can import your products with the categories ID's on that field. For example: "3,4"