zoukankan      html  css  js  c++  java
  • Magento1.9 add attribute to catalog product & assign to all attribute set general group

    $installer = $this;
    
    $attributes = array(
        'region'      =>   array(
            'type'   => 'int',
            'input' => 'select',
            'source_model'       => 'evebit_catalog/entity_attribute_source_region',
            'frontend_label' => 'Region',
            'is_global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
            'frontend_input' => 'select',
            'backend_type' => 'int',
            'used_in_product_listing' => true,
            'is_visible_on_front' => true,
            'is_required' => false,
            'is_user_defined' => true,
            'searchable' => true,
            'filterable' => true,
            'comparable' => false,
            'visible_in_advanced_search'=>true,
            'position' => 15,
            'is_unique' => false,
        )
    );
    
    $productEntityId = $installer->getEntityTypeId(Mage_Catalog_Model_Product::ENTITY);
    $allAttributeSetIds = $installer->getAllAttributeSetIds($productEntityId);
    
    foreach($attributes as $attributeCode=>$attribute)
    {
        $attributeModel =   Mage::getModel('catalog/resource_eav_attribute');
        $attributeModel->addData($attribute);
        $attributeModel->setAttributeCode($attributeCode);
        $attributeModel->setEntityTypeId($productEntityId);
    
    
        try
        {
            $attributeModel->save();
    
        }catch (Mage_Core_Exception $e)
        {
            Mage::logException($e);
        }
    
        try
        {
            foreach ($allAttributeSetIds as $attributeSetId){
    
                $generalAttributeGroup = $installer->getAttributeGroupId($productEntityId,$attributeSetId,'General');
                $attributeModel->setAttributeSetId($attributeSetId);
                $attributeModel->setAttributeGroupId($generalAttributeGroup);
                $attributeModel->save();
            }
    
        }catch (Mage_Core_Exception $e)
        {
            Mage::logException($e);
        }
    }
    
    $installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, 'country_of_manufacture', 'frontend_label', 'Country');
    
    $installer->endSetup();
    

      

    作者:冯亮
             
    能力有限,水平一般。如有错误,欢迎指正
  • 相关阅读:
    vs2005 水晶报表横向打印Bug
    petshop4.0 详解之七(PetShop表示层设计)
    petshop4.0 详解之八(PetShop表示层设计)
    在VS2005中使用VSS2005
    用DataFormatString格式化GridView
    GridView的高级用法
    水晶报表 打印时出现错误提示:出现通信错误。将停止打印
    POJ1182 食物链[并查集]
    并查集的基础知识
    HDOJ1269 迷宫城堡[强连通分量]
  • 原文地址:https://www.cnblogs.com/fengliang/p/6904938.html
Copyright © 2011-2022 走看看