3

このコードを使用して、プログラムで新しいルート カテゴリを作成しました。

$category = new Mage_Catalog_Model_Category();
$category->setStoreId(0);
$category->setName('Storybloks6');
$category->setUrlKey('storyblocks6');
$category->setIsActive('1');
$category->setIncludeInMenu('0');
$category->setDescription('Produtos que aparecem em destaque no carrossel da home');
$category->setDisplayMode('PRODUCTS');
$category->setIsAnchor('0');
$category->setLevel('1');
$category->setParentId('1');

$parentCategory = Mage::getModel('catalog/category')->load('1');
$category->setPath($parentCategory->getPath()); 
$category->save();

カテゴリが追加されますが、管理カテゴリ ページでは、ラベルがメニューに表示されません。 新しいカテゴリはメニューに (0) として表示されます 新しいカテゴリはメニューに (0) として表示されます。どうすれば修正できますか?

4

2 に答える 2

0

同じストア(adminストア-コード0)のバックエンドでカテゴリツリーを表示しているか、ラベルが設定されていない別のストアを表示しているかを確認してください。

于 2012-07-26T21:11:27.233 に答える
-1

Magento ルート フォルダーに somename.php という名前のファイルを作成し、次のコードをファイルに貼り付けて保存します。ウェブブラウザからスクリプトを実行するだけです。カテゴリ「車」を作成する必要があります-1.4.2.0で機能しました。

<?php
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'] = "Cars";
$general['path'] = "1/3"; // 1/3 is root catalog
$general['description'] = "Great new cars";
$general['meta_title'] = "Cars"; //Page title
$general['meta_keywords'] = "car, automobile";
$general['meta_description'] = "Some description to be found by meta search robots.";
$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['url_key'] = "cars";//url to be used for this category's page by magento.
$general['image'] = "cars.jpg";


$category->addData($general);

try {
    $category->save();
    echo "Success! Id: ".$category->getId();
}
catch (Exception $e){
    echo $e->getMessage();
}
于 2012-07-31T16:56:20.090 に答える