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

      

    作者:冯亮
             
    能力有限,水平一般。如有错误,欢迎指正
  • 相关阅读:
    【HDU6609】Find the answer【线段树】
    【HDU6602】Longest Subarray【线段树+分治】
    PCIe
    NVMe Windows 支持情况
    PCIe/NVMe Soft Protocol Analyzer
    I am coming..
    hibernate自动建表技术_采用数据库反向生成技术
    struts2的执行流程
    oracle中scott用户下四个基本表SQL语句练习
    SQL语句中的having和where的区别
  • 原文地址:https://www.cnblogs.com/fengliang/p/6904938.html
Copyright © 2011-2022 走看看