2013-10-13 21 views
-1

我使用此代碼來創建類別和子類別。此代碼正常工作,但問題是我無法創建我自己的類別代碼。我需要它將它用於請求。如何使用自定義代碼創建Magento?

$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'] = "My Category"; 
$general['path'] = "1/3/"; // catalog path here you can add your own ID 
$general['description'] = "Great My Category"; 
$general['meta_title'] = "My Category"; //Page title 
$general['meta_keywords'] = "My , Category"; 
$general['meta_description'] = "Some description to be found by meta search robots. 2"; 
$general['landing_page'] = ""; //has to be created in advance, here comes id 
$general['display_mode'] = "PRODUCTS"; //static block and the products are shown on the page 
$general['is_active'] = 1; 
$general['is_anchor'] = 0; 
$general['page_layout'] = 'two_columns_left'; 

//$general['url_key'] = "cars";//url to be used for this category's page by magento. 
//$general['image'] = "cars.jpg"; 


$category->addData($general); 

try { 
    $category->setId(255); // Here you cant set your own entity id 
    $category->save(); 
    echo "Success! Id: ".$category->getId(); 
} 
catch (Exception $e){ 
    echo $e->getMessage(); 
} 

我試圖做這樣的事情:

$general['id'] = $myCustomId; 

但它不工作。

回答

1

關鍵需要映射列標題,即entity_id。因此,將$ general ['id']更改爲

$ general ['entity_id'] = $ myCustomId;

+0

好的!它正在工作。謝謝! – 1ry

相關問題