php – Magento:在安装脚本中为分组产品添加新属性
我正在为分组产品开发一个小的Magento扩展.这个扩展需要另一个属性,所以我想我可以编写一个设置脚本,为分组产品添加一个新属性.但就像我在Magento尝试做的几乎所有事情一样,事实证明这比我预期的要复杂得多.官方Magento论坛没有真正的帮助,所以我希望在这里得到一些支持:)
新属性应仅出现在分组产品的“常规”选项卡中;简单的产品,可配置的产品,捆绑产品等应该保持不变.该属性应该独立于所选属性集,就像它是一个系统属性一样. 为此,我想我可以将属性添加到分组产品的实体中,但正如我所知,对于分组产品没有特殊实体,一般只有产品“catalog_product”.因此我的下一个想法是,我需要将属性添加到“catalog_product”实体,然后将其分配给正确的属性组,以便它仅适用于分组产品. 问题是我还没有那么深入Magento而且我完全不知道我应该如何找到相应的属性组,或者我的想法是否会起作用,也许我完全走错了轨道:/ 只是为了让你知道到目前为止我得到了什么: $installer = $this; $installer->startSetup(); $installer->addAttribute("catalog_product","my_attrib_name",array( /* just a placeholder */ )); $installer->endSetup(); 非常基本…… 解决方法
我现在想出了如何自己做.我的方法是正确的,我只需要找到相应的参数.
addAttribute() – 调用现在看起来如下: // ... $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 ) ); // ... 现在,安装程序添加的属性是系统属性,它会自动添加到每个属性集的“常规”组中,并且无法更改/移动.正如我所预期的那样,它也仅适用于分组产品. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |