2014-03-05 55 views
0

我想从一个magento商店导出类别并导入到另一个。如何以编程方式向Magento添加类别和类别路径?

以下信息是必须在商店中插入的类别的一部分。

Default Category 2 
All Categories 2/30 
Electronics 2/30/12 
TV & Video 2/30/12/13 

我试试以下脚本导入一个类别,但不起作用。该脚本不会导入该类别。

require_once 'app/Mage.php'; 
Mage::app('default'); // Default or your store view name. 

//get a new category object 
$category = Mage::getModel('catalog/category'); 
$category->setStoreId(0); // 0 = default/all store view. If you want to save data for a specific store view, replace 0 by Mage::app()->getStore()->getId(). 

//if update 
if ($id) { 
    $category->load($id); 
} 

$general['name'] = "All Categories"; 
$general['path'] = "2/30"; // catalog path 
$general['description'] = ""; 
$general['meta_title'] = ""; //Page title 
$general['meta_keywords'] = ""; 
$general['meta_description'] = ""; 
$general['landing_page'] = ""; //has to be created in advance, here comes id 
$general['display_mode'] = "PRODUCTS_AND_PAGE"; //static block and the products are shown on the page 
$general['is_active'] = 1; 
$general['is_anchor'] = 0; 
$general['page_layout'] = 'two_columns_left'; 

$category->addData($general); 

try { 
    $category->save(); 
    echo "Success! Id: ".$category->getId(); 
} 
catch (Exception $e){ 
    echo $e->getMessage(); 
} 
+0

您现在面临哪个错误? – Chiragit007

+0

该类别未插入且脚本已成功完成。 – dido

回答

1

我复制了您的确切代码并进行了测试。当你悲伤的时候,脚本是成功的,但在magento后端没有分类......但是在数据库中有一个,只需检查表catalog_category_entity

问题是,你传错了路径属性。顶级类别是总部ID = 1。安装后,当你创建你的目录最高类别时,它会大于1.在我的情况下,它是ID = 3。

所以订购下面根类别我创建(ID = 3)的新的类别,我必须设置值1/3路径

$general['path'] = "1/3"; // catalog path 

在你的情况下,我客串它应该使用以下值

$general['path'] = "1/2/30"; // catalog path 
相关问题