add attribute to eav attribute

piaoling  2011-08-16 16:36:50

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


$newAttrCode = 'top_dynamic_menu_dropdownlist_attribute_first';
$newAttrAttr =  array(
    'type'              => 'int',
    'backend'           => '',
    'frontend'          => '',
    'label'             => Mage::helper('dynamicmenu')->__('Product attribute 1'),
    'input'             => 'select',
    'class'             => '',
    'source'            => 'dynamicmenu/options_attribute',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'frontend_label'    => Mage::helper('dynamicmenu')->__('Product attribute 1'),
    'user_defined'      => false,
    'default'           => '',
    'searchable'        => false,
    'filterable'        => false,
    'comparable'        => false,
    'visible_on_front'  => false,
    'unique'            => false,
);

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

//add group
$groups = array(
    'dynamicmenu'   => array(
        'name'  => Mage::helper('dynamicmenu')->__('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']);
}

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

///////////////////////////////////////////////////////
$newAttrCode = 'top_dynamic_menu_dropdownlist_attribute_two';
$newAttrAttr =  array(
    'type'              => 'int',
    'backend'           => '',
    'frontend'          => '',
    'label'             => Mage::helper('dynamicmenu')->__('Product attribute 2'),
    'input'             => 'select',
    'class'             => '',
    'source'            => 'dynamicmenu/options_attribute',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'frontend_label'    => Mage::helper('dynamicmenu')->__('Product attribute 2'),
    '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,
    '44'
);

///////////////////////////////////////////////////////
$newAttrCode = 'top_dynamic_menu_dropdownlist_attribute_three';
$newAttrAttr =  array(
    'type'              => 'int',
    'backend'           => '',
    'frontend'          => '',
    'label'             => Mage::helper('dynamicmenu')->__('Product attribute 3'),
    'input'             => 'select',
    'class'             => '',
    'source'            => 'dynamicmenu/options_attribute',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'frontend_label'    => Mage::helper('dynamicmenu')->__('Product attribute 3'),
    '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,
    '56'
);

///////////////////////////////////////////////////////
$newAttrCode = 'top_dynamic_menu_dropdownlist_cms';
$newAttrAttr =  array(
    'type'              => 'int',
    'backend'           => '',
    'frontend'          => '',
    'label'             => Mage::helper('dynamicmenu')->__('CMS Bloc'),
    'input'             => 'select',
    'class'             => '',
    'source'            => 'dynamicmenu/options_cms',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'frontend_label'    => Mage::helper('dynamicmenu')->__('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)  |  浏览(4427)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: