0

我正在尝试使用脚本导入类别

 $cat = Mage::getModel('catalog/category')
                            ->setPath('1/2')
                            ->setName($name)
                            ->setIsActive(1)
                            ->setIsAnchor(1)
                            ->setIsParent(1)
                            ->setIncludeInMenu(1)
                            ->save();
               echo $catId = $cat->getId();

使用此代码类别被导入,但它们不是活动的,也不是锚定的。请帮助我。

4

2 回答 2

0

Amit 的回答有效,同样的基本思想是方法是 setIsActive()。

所以:

$category
    ->setStoreId(0)
    ->setPath("1/{$root_category_id}" . ($parents ? "/{$parents}" : ''))
    ->setStoreId(0)
    ->setName($category_name)
    ->setIsActive(1)
    ->save();
于 2013-05-21T16:18:02.920 回答
0

试试这个。。

require_once 'app/Mage.php'; 法师::app('默认'); /* 默认或您的商店视图名称。*/

/* 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(). */


$general['name'] = "My Category";
$general['path'] = "1/2/23"; /* catalog path */
$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_AND_PAGE"; /* 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->save();
    echo "Success! Id: " . $category->getId();
} catch (Exception $e) {
        echo $e->getMessage();
}
于 2012-12-20T21:15:28.690 回答