douran9707 2012-02-19 16:43
浏览 45
已采纳

Magento:在安装脚本中为分组产品添加新属性

I am developing a small Magento-extension for grouped products. This extension needs another attribute, so I figured I could just write a setup script which adds a new attribute to grouped products. But as pretty much everything I tried to do in Magento, that turned out to be way more complex than I expected. The official Magento forum is no real help, so I hope for some support here :)

The new attribute should only appear in the "General" tab of grouped products; simple products, configurable products, bundle products etc. should stay unaltered. The attribute should be there independently of the selected attribute set, just like it was a system attribute.

To do so I thought I could just add the attribute to the entity of grouped products, but as I found out, there's no special entity for grouped products, only the entity "catalog_product" for products in general. Thus my next thought was, I needed to add the attribute to the "catalog_product" entity and then assign it to the correct attribute group, so that it only applies to grouped products.

Problem is that I am not that deep into Magento yet and I have totally no clue how I am supposed to find the corresponding attribute group or if my idea is gonna work at all, maybe I'm totally on the wrong track here :/

Just to let you know what I got so far: I registerd my setup script in the extension's config file and it is being executed, only problem is the setup script itself, it looks like the following atm, because - as I said - I have no clue yet:

$installer = $this;
$installer->startSetup();
$installer->addAttribute("catalog_product", "my_attrib_name", array( /* just a placeholder */ ));
$installer->endSetup();

Pretty basic...

  • 写回答

1条回答 默认 最新

  • dtnat7146 2012-02-21 22:13
    关注

    I figured out how to do it on my own now. My approach was correct, I just needed to find the corresponding parameters.

    The addAttribute()-call looks like the following now:

    // ...
    $installer->addAttribute(
        "catalog_product", // Entity the new attribute is supposed to be added to
        "my_attrib_code", // attribute code
         array( // Array containing all settings:
            "type" => "varchar",
            "label" => "My attribute",
            "note" => "Insert additional information about the attribute here",
            "input" => "text",
            "global" => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
            // Dont know if this is really necessary, but it makes sure 
            // the attribute is created as a system attribute:
            "user_defined" => false,
            // This makes sure the attribute only applies to grouped products
            "apply_to" => Mage_Catalog_Model_Product_Type::TYPE_GROUPED
        )
    );
    // ...
    

    Now the attribute added by the installer is a system attribute, it gets automatically added to the "General" group of every attribute set and cannot be changed/moved. As I intended it also only applies to grouped products.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn