add attribute to category

piaoling  2011-08-17 11:20:16

<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition License
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magentocommerce.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Bysoft
 * @package     Bysoft_CatalogCustom
 * @copyright   Bysoft
 */

/* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
$installer = $this;

$installer->startSetup();

//add group
$groups = array(
    'dynamicmenu'   => array(
        'name'  => Mage::helper('specific')->__('Dynamic Menu'),
        'sort'  => 100,
        'id'    => null
    ),
);

$entityTypeId     = $installer->getEntityTypeId('catalog_category');
$attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

foreach ($groups as $k => $groupProp) {
    $installer->addAttributeGroup($entityTypeId, $attributeSetId, $groupProp['name'], $groupProp['sort']);
    $groups[$k]['id'] = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, $groupProp['name']);
}



///////////////////////////////////////////////////////
$newAttrCode = 'top_dynamic_menu_dropdownlist_cms';
$newAttrAttr =  array(
    'type'              => 'int',
    'backend'           => '',
    'frontend'          => '',
    'label'             => Mage::helper('specific')->__('CMS Bloc'),
    'input'             => 'select',
    'class'             => '',
    'source'            => 'specific/options_cms',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'frontend_label'    => Mage::helper('specific')->__('CMS Bloc'),
    'user_defined'      => false,
    'default'           => '',
    'searchable'        => false,
    'filterable'        => false,
    'comparable'        => false,
    'visible_on_front'  => false,
    'unique'            => false,
);

$installer->addAttribute('catalog_category',$newAttrCode,$newAttrAttr);

$entityTypeId     = $installer->getEntityTypeId('catalog_category');
$attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);


//add attribute to group
$installer->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $installer->getAttributeGroupId($entityTypeId, $attributeSetId, 'Dynamic Menu'),
    $newAttrCode,
    '70'
);

$installer->endSetup();

类别 :  magento(258)  |  浏览(3772)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: