如何从Magento的前端创建类别?

时间:2014-02-07 06:23:07

标签: php magento

我想从前端创建一个类别,我有一个代码

 <?php
     $category = Mage::getModel('catalog/category');
     $category->setName('mobiles')
     setIsActive(1)                       //activate your category
     setIsAnchor(0)
     setCustomDesignApply(1)
     setDisplayMode( 'PRODUCTS' )
     setAttributeSetId($category->getDefaultAttributeSetId());
     $parentCategory = Mage::getModel('catalog/category')->load("2");
     $category->setPath($parentCategory->getPath());
     $category->save();
     unset($category);
  ?>

此代码在单个商店中正常运行,但在多商店中,该类别未处于活动模式。 请大家帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

对于多店铺,您必须设置store_id

$category->setStoreId(0); // 0 =默认/所有商店视图。

如果要保存特定商店视图的数据,请使用store_id

替换0
Mage::app()->getStore()->getId()