-1

このコードを使用して、カテゴリとサブカテゴリを作成しています。このコードは正常に動作しますが、問題は、独自のカテゴリ コードを作成できないことです。そして、私はそれを要求に使用する必要があります。

$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;

しかし、それは機能していません。

4

1 に答える 1

1

キーは、entity_id である列ヘッダーをマップする必要があります。$general['id'] を

$general['entity_id'] = $myCustomId;

于 2013-10-13T14:22:54.713 に答える