duanchu2607 2013-04-12 21:30
浏览 45
已采纳

将产品属性移动到magento admin中的新组

I created an attribute like so...

$installer = $this;
$installer->startSetup();

/* $installer Services_Issue_Model_Mysql4_Setup */
$installer->addAttribute('catalog_product', 'alice_id', array(
    'backend'                       => '',
    'frontend'                      => '',
    'type'                          => 'text',
    'visible'                       => true,
    'label'                         => 'Alice Id',
    'note'                          => 'Alice Id.',
    'input'                         => 'text',
    'unique'                        => true,
    'source'                        => '',
    'global'                        => true,
    'visible'                       => true,
    'required'                      => true,
    'user_defined'                  => true,
    'default'                       => '',
    'visible_on_front'              => true,
    'apply_to'                      => 'simple,configurable,default',
    'group'                         => 'Special Attributes',
    'used_in_product_listing'       => true,
    'frontend_class'                => '',
    'class'                         => '',
    'is_html_allowed_on_front'      => true,
    'searchable'                    => true
));

$installer->endSetup();

Now I need to move it to another group within the product information page. So I've tried this without any success.

$installer = $this;
$installer->startSetup();

/* $installer Services_Issue_Model_Mysql4_Setup */

$installer->updateAttribute('catalog_product', 'alice_id', 'note', 'Product SKU for Alice.com third-party cart & checkout.');

/* - move between groups not possible with updateAttribute - */

$installer->updateAttribute('catalog_product', 'alice_id', 'group', 'Additional Attributes');
$installer->endSetup();

Can anyone tell me how I can accomplish this?

  • 写回答

2条回答 默认 最新

  • duanbi1983 2013-04-15 15:16
    关注

    You can use the addAttributeToGroup($entityType, $attributeSetId, $attributeGroupId, $attributeId, $sortOrder) method in Mage_Eav_Model_Entity_Setup to move an attribute to a different group. First, you'll need to get the set ID and group ID.

    // ... start setup 
    
    // get default set id
    $setId = $installer->getDefaultAttributeSetId('catalog_product');
    
    // get group id by name "Additional Attributes"
    $attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_group_collection');
    foreach ($attributeSetCollection->getData() as $attributeGroupIndex) {
        foreach ($attributeGroupIndex as $key => $value) {
            if ($key === "attribute_group_name" and $value === "Additional Attributes") {
                $groupId = $attributeGroupIndex["attribute_group_id"];
                break 2;
            }
        }
    }
    
    // move attribute 'alice_id' to group 'Additional Attributes'
    if (isset($setId) and isset($groupId)) {
        $installer->addAttributeToGroup('catalog_product', $setId, $groupId, 'alice_id', 1000);
    }
    
    // ... end setup
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 懂Matlab的人,可以帮我看看第四题和第五题应该怎么才能运行出来,或者可以提供一点相关的思路
  • ¥15 cv2.fisheye.stereoCalibrate报错
  • ¥20 求自动化运维语料数据集
  • ¥30 广告检测流量作弊案例 IDEA运行代码报错 连接不上metastore 检测了环境配置没有问题 请求远程解决加VX问细节问题 不加的不回复
  • ¥15 matlab图像融合代码被嫌弃太简单,求改进。第一步改成直接读取三张图片,不读取文件夹
  • ¥20 微处理器原理与应用(私有偿)
  • ¥50 8051单片机关于ADC0809的应用
  • ¥15 有没有能拿来练练手写完发给我
  • ¥15 禁止修改windows系统时间
  • ¥50 kinect连接win11笔电导致音视频设备消失