2012-07-26 126 views
3

編程添加新的分類名稱我剛剛創建了一個新的根類編程方式使用此代碼:的Magento沒有顯示在管理員

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

類別添加,但在管理分類頁面,它標籤沒有出現在菜單上: new category appears as (0) on menu 新菜單在菜單上顯示爲(0)。我該如何解決它?

+0

的方式......你應該使用'$類=法師:: getModel( '目錄/類別');' – Alex 2012-07-26 21:07:51

+0

嗨@Alex,我想這種方式。同樣的問題。當我到那裏並以管理員身份保存(0)時,它會修復。我仍在尋找解決方案。 – 2012-07-26 22:13:51

回答

0

檢查您是否在同一商店(管理員商店 - 代碼0)中查看後端的類別樹,或者可能是未設置標籤的其他商店。

+1

是的,它是爲不同的商店設置的。但是,既不改爲正確的,它仍然無法正常工作。無論如何,謝謝你的時間。 – 2012-07-26 21:58:47

-1

在Magento根文件夾中創建一個名爲somename.php的文件,並將以下代碼粘貼到文件中並保存。只需通過您的網頁瀏覽器運行腳本。它應該創建一個類別「Cars」 - 它在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(); 
}