Magento add product attribute and assign to all group
2024-10-09 13:56:05
$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);
} }
最新文章
- c/c++ 缓冲区的刷新
- HTTP参数中Etag的重要性
- SharePoint 中关于event receivers的讨论
- Web 在线文件管理器学习笔记与总结(6)jQuery UI 预览图片
- jdk的动态代理
- RAC的负载均衡有2种方式
- union以及一些扩展
- 如何使用Android中的OpenGL ES媒体效果
- git生成sshkey
- Sprite/MovieClip的Enter_Frame事件,不受addChild/removeChild影响
- C# Winform打包部署时添加注册表信息实现开机自启动
- 对python pickle的理解
- RxJava2学习笔记(2)
- 深入理解C++中public、protected及private用法
- linux apidoc的安装和使用
- send和sendmsg性能测试
- SET ANSI_NULLS ON,SET NOCOUNT ON,SET QUOTED_IDENTIFIER ON
- hadoop HA sshfen切换隔离时无法跳转ssh: bash: fuser: 未找到命令
- go语言基础之函数只有一个返回值
- UNIQLO
热门文章
- sscanf,sprintf(思修课的收获)
- 微服务迁移记(五):WEB层搭建(1)
- 字典内置函数&;方法
- PHP image_type_to_extension - 获取图片后缀
- PHP levenshtein() 函数
- AtCoder Beginner Contest 173 E Multiplication 4	分类讨论 贪心
- Docker技术入门与实战第2版-高清文字版
- docker安装gitlab并部署CICD
- 8、Builder 建造者模式 组装复杂的实例 创造型模式
- Go 中的动态作用域变量