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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化