$attributes = array( 'product_type' => array( 'type' => 'int', 'input' => 'select', 'source_model' => 'mcatalog/source_eav_attribute_product_type', 'frontend_label' => '产品类型', 'is_global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 'frontend_input' => 'select', 'backend_type' => 'int', 'used_in_product_listing' => false, 'is_visible_on_front' => false, 'is_required' => true, 'user_defined' => true, 'searchable' => false, 'filterable' => false, 'comparable' => false, 'position' => 15, 'is_unique' => false, ) ); $productEntityId = $installer->getEntityTypeId(Mage_Catalog_Model_Product::ENTITY); $productAttributeSets = Mage::getModel('eav/entity_attribute_set')->getCollection() ->addFieldToFilter('entity_type_id', $productEntityId); foreach($attributes as $attributeCode=>$attribute) { try{ $attributeModel = Mage::getModel('catalog/resource_eav_attribute'); $attributeModel->addData($attribute); $attributeModel->setAttributeCode($attributeCode); $attributeModel->setEntityTypeId($productEntityId); $re = $attributeModel->save(); foreach ($productAttributeSets as $attributeSet){ $generalAttributeGroupId = $installer->getAttributeGroupId($productEntityId,$attributeSet->getId(),'General'); Mage::getModel('eav/entity_attribute') ->setAttributeSetId($attributeSet->getId()) ->setAttributeGroupId($generalAttributeGroupId) ->setEntityTypeId($productEntityId) ->setAttributeId($re->getId()) ->save(); } }catch (Exception $e){ Mage::logException($e); } }