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 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败