Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento是';t显示在管理中以编程方式添加的新类别名称_Magento - Fatal编程技术网

Magento是';t显示在管理中以编程方式添加的新类别名称

Magento是';t显示在管理中以编程方式添加的新类别名称,magento,Magento,我刚刚使用以下代码以编程方式创建了一个新的根类别: $category = new Mage_Catalog_Model_Category(); $category->setStoreId(0); $category->setName('Storybloks6'); $category->setUrlKey('storyblocks6'); $category->setIsActive('1'); $category->setIncludeInMenu('0');

我刚刚使用以下代码以编程方式创建了一个新的根类别:

$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)或未设置标签的另一个存储中查看后端的类别树。

在Magento根文件夹中创建一个名为somename.php的文件,并将以下代码粘贴到该文件中并保存。只需通过webbrowser运行脚本。它应该创建一个类别“汽车”-它在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();
}

顺便说一下。。。您应该使用
$category=Mage::getModel('catalog/category')