2013-10-13 8 views
-1

이 코드를 사용하여 카테고리 및 하위 카테고리를 생성하고 있습니다. 이 코드는 제대로 작동하지만 문제는 내 자신의 범주 코드를 만들 수 없다는 것입니다. 그리고 그것을 requeriments에 사용하는 것이 필요합니다. 사용자 정의 코드로 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']를

$로 변경하십시오. [ 'entity_id'] = $ myCustomId;

+0

오케이! 효과가 있습니다. 고맙습니다! – 1ry

관련 문제