export category list

class Mage_Shell_ExportCategory extends Mage_Shell_Abstract
{

    /**
     * Run script
     *
     */
    public function run()
    {
	    ini_set("memory_limit","1000M");
	    umask(0);
	    $category = Mage::getModel ('catalog/category');
	    $tree = $category->getTreeModel();
	    $tree->load();
	    $ids = $tree->getCollection()->getAllIds();
	    $timestamp = time();
	    $file_path = BP.DS.'media'.DS.'export'.DS.'cate_' . $timestamp . '.csv';
	    $fp = fopen($file_path, 'w');
	    
	    if ($ids) {
		    $string='';
		    $heading = fputcsv($fp,array("store","categories","cat_id","is_active","meta_title","meta_keywords","meta_description","include_in_menu","is_anchor","description"));
		    foreach ($ids as $id) {
			    if($id>0)//start if removeroot category and default category .
			    {
				    $cate_cre = Mage::getModel('catalog/category');
				    $cate_cre->load($id);
				    $treeurl='';
				    $cate_cre1=Mage::getModel('catalog/category')->load($id);
				    $treeurl=$cate_cre->getName();
				    if($cate_cre1->getParentId()>0)
				    {
				    	for($i=0; ;$i++) {
				    		if($cate_cre1->getParentId()>0) {
				    			$abc=Mage::getModel('catalog/category')->load($cate_cre1->getParentId());
				    			$pCat=$abc->getName();
				    			if($abc->getId()>1){
				    				$treeurl=$pCat.'/'.$treeurl;
				   		 		}
				    			$cate_cre1=$abc;
			    			} else{
				    			break;
				    		}
				    	}
				    }
				    $store = "default";
				    $array_cate =array($store,$treeurl,$id,$cate_cre->getIsActive(),$cate_cre->getMetaTitle(),$cate_cre->getMetaKeywords(),$cate_cre->getMetaDescription(),$cate_cre->getIncludeInMenu(),$cate_cre->getIsAnchor(),$cate_cre->getDescription());
				    var_dump($array_cate);
				    
				    fputcsv($fp,$array_cate);
				    
			    }//endof if removeroot category and default category .
		    }
			fclose($fp);  
	    }
    }
}

$shell = new Mage_Shell_ExportCategory();
$shell->run();

 

你可能感兴趣的:(Export)