• Magento add product attribute and assign to all group


    $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);
        }
    
    }
    

      

    作者:冯亮
             
    能力有限,水平一般。如有错误,欢迎指正
  • 相关阅读:
    文件上传之断点续传方案
    WEB项目(B/S系统)打包安装(总结篇)
    FLEX4.0开发流媒体视频播放器(总结篇)
    mysql 从库出现system lock延迟
    mysql与oracle 不同
    操作系统运维查询命令
    centos ifconfig 命令找不到
    bit 与 byte的区别
    mysql 登录socket与TCP
    xhost +
  • 原文地址:https://www.cnblogs.com/fengliang/p/6477720.html
Copyright © 2020-2023  润新知