我想在类别中添加新属性,并更新所有已创建类别的默认值。
我的代码是:
$installer = $this;
$installer->startSetup();
$installer->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'include_in_parent_navigation', array(
'group' => 'General Information',
'input' => 'select',
'type' => 'int',
'source' => 'eav/entity_attribute_source_boolean',
'label' => 'Include in Parent Navigation',
'required' => 0,
'unique' => 0,
'sort_order' => 11,
'user_defined' => 1,
'default' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));
$_categories = Mage::getModel('catalog/category')
->getCollection();
foreach($_categories as $category) {
$category->setData('include_in_parent_navigation', 1);
$category->save();
}
$installer->endSetup();
添加新属性但不更新现有类别。
答案 0 :(得分:0)
use this below code
$_categories = Mage::getModel('catalog/category')
->getCollection();
foreach($_categories as $category) {
$cat=Mage::getModel('catalog/category')->load($category->getId());
$cat->setData('include_in_parent_navigation', 1);
$cat->save();
}