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
在Magento中启用展开模式时以编程方式创建类别_Magento_Categories_Flat - Fatal编程技术网

在Magento中启用展开模式时以编程方式创建类别

在Magento中启用展开模式时以编程方式创建类别,magento,categories,flat,Magento,Categories,Flat,我想以编程方式在模块的数据文件夹中创建一个类别。“展开类别”选项已启用 当我尝试创建这样的类别时: $category ->setStoreId(0) ->setName('My category') ->setUrlKey('club-campaigns') ->setPath($rootCategory->getPath()) ->setIsActive(1) ->setIsAnchor(1)

我想以编程方式在模块的数据文件夹中创建一个类别。“展开类别”选项已启用

当我尝试创建这样的类别时:

$category
    ->setStoreId(0)
    ->setName('My category')
    ->setUrlKey('club-campaigns')
    ->setPath($rootCategory->getPath())
    ->setIsActive(1)
    ->setIsAnchor(1)
    ->setIncludeInMenu(1)
    ->addData($data)
    ->setCustomDesignApply(1)
    ->save();
我得到一个错误,说目录\类别\平面不存在。好的,所以我知道平面类别信息保存在catalog\u category\u flat\u store\u storenumber表中。我查看了数据库,得到了以下表格:

目录\类别\平面\商店\ 1
目录\类别\平面\商店\ 2
目录\类别\平面\商店\ 3
目录\类别\平面\商店\ 4
目录\类别\平面\商店\ 5
目录\类别\公寓\商店\ 6

我想为商店6创建一个类别。好,现在如果我喜欢这个:

$category
    ->setStoreId(6)
    ->setName('My category')
    ->setUrlKey('club-campaigns')
    ->setPath($rootCategory->getPath())
    ->setIsActive(1)
    ->setIsAnchor(1)
    ->setIncludeInMenu(1)
    ->addData($data)
    ->setCustomDesignApply(1)
    ->save();
创建的类别没有错误,它在catalog_category_flat_store_6中设置信息,但如果我转到admin>Manage Categories,却看不到创建的类别

我认为,当我创建一个类别时,我应该设置管理员(0)的te store id,这样我就可以在管理员面板中看到它,但是我得到了上面的错误,如果我使用store 6创建,我就不会在管理员面板中看到它。我真的卡住了


如何以编程方式正确创建类别而不会出现问题?

动态创建类别:

$category = Mage::getModel('catalog/category');
$category->setStoreId(Mage::app()->getStore()->getId());

$cat['name'] = "Custom Category Name here";
$cat['path'] = "1/2/30"; //parent relationship..
$cat['description'] = "categorie's description";
$cat['is_active'] = 1;
$cat['is_anchor'] = 0; //for layered navigation
$cat['page_layout'] = 'two_columns_left';
$cat['url_key'] = "custom-category"; //url to access this category
$cat['image'] = "custom-category.jpg";

$category->addData($cat);
$category->save();
$process = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_category_flat');
$process->reindexEverything();
然后动态重新索引目录\u类别\u平面:

$category = Mage::getModel('catalog/category');
$category->setStoreId(Mage::app()->getStore()->getId());

$cat['name'] = "Custom Category Name here";
$cat['path'] = "1/2/30"; //parent relationship..
$cat['description'] = "categorie's description";
$cat['is_active'] = 1;
$cat['is_anchor'] = 0; //for layered navigation
$cat['page_layout'] = 'two_columns_left';
$cat['url_key'] = "custom-category"; //url to access this category
$cat['image'] = "custom-category.jpg";

$category->addData($cat);
$category->save();
$process = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_category_flat');
$process->reindexEverything();

动态创建类别:

$category = Mage::getModel('catalog/category');
$category->setStoreId(Mage::app()->getStore()->getId());

$cat['name'] = "Custom Category Name here";
$cat['path'] = "1/2/30"; //parent relationship..
$cat['description'] = "categorie's description";
$cat['is_active'] = 1;
$cat['is_anchor'] = 0; //for layered navigation
$cat['page_layout'] = 'two_columns_left';
$cat['url_key'] = "custom-category"; //url to access this category
$cat['image'] = "custom-category.jpg";

$category->addData($cat);
$category->save();
$process = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_category_flat');
$process->reindexEverything();
然后动态重新索引目录\u类别\u平面:

$category = Mage::getModel('catalog/category');
$category->setStoreId(Mage::app()->getStore()->getId());

$cat['name'] = "Custom Category Name here";
$cat['path'] = "1/2/30"; //parent relationship..
$cat['description'] = "categorie's description";
$cat['is_active'] = 1;
$cat['is_anchor'] = 0; //for layered navigation
$cat['page_layout'] = 'two_columns_left';
$cat['url_key'] = "custom-category"; //url to access this category
$cat['image'] = "custom-category.jpg";

$category->addData($cat);
$category->save();
$process = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_category_flat');
$process->reindexEverything();

重新编制索引有用吗?我会尝试重新编制索引,但我认为应该在创建类别之前重新编制索引。因为我看到像catalog\u category\u flat\u store\u X这样的表是在重新索引过程之后创建的。重新索引是否有帮助?我将尝试重新索引,但我认为应该在创建类别之前重新索引。因为我看到像catalog_category_flat_store_X这样的表是在重新索引过程之后创建的。如何获取刚刚创建的category的ID?$category->getId();使用此获取当前插入的类别ID如何获取刚创建的类别ID?$category->getId();通过使用此项获取当前插入的类别id