我在Magento中創建了我的模塊,但它需要爲所有產品分配附加屬性。我做了安裝腳本,但它不工作:Magento:使用模塊安裝腳本添加產品屬性
<?php
$installer = $this;
$installer->startSetup();
$installer->run("
INSERT IGNORE INTO `{$installer->getTable('eav/attribute')}` (`attribute_id`, `entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_required`, `is_user_defined`, `default_value`, `is_unique`, `note`) VALUES
SELECT 1 + coalesce((SELECT max(attribute_id) FROM `{$installer->getTable('eav/attribute')}`),0),4,`is_accepted`,NULL,NULL,`int`,NULL,NULL,`boolean`,`Accepted`,NULL,`eav/entity_attribute_source_boolean`,1,1,'0',0,NULL);
");
$installer->endSetup();
Config.xml文件:
<adminhtml>
<acl>
<module_setup>
<setup>
<module>My_module</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</module_setup>
<module_write>
<connection>
<use>core_write</use>
</connection>
</module_write>
<module_read>
<connection>
<use>core_read</use>
</connection>
</module_read>
</resources>
</acl>
</adminhtml>
這裏有什麼問題?
好主意,但仍然得到一個錯誤,沒有方法addAttribute()在安裝程序中:'致命的錯誤:調用未定義的方法Mage_Core_Model_Resource_Setup :: addAttribute()'編輯:對不起,我忘了你寫了_代替Mage_Eav_Model_Entity_Setup你也可以使用你的自己的安裝類,但它應該繼承Mage_Eav_Model_Entity_Setup,所以你可以使用addAttribute,而不是手工僞造SQL查詢._ –
好吧,我在我的config.xml文件中添加了' Mage_Eav_Model_Entity_Setup ',它工作。謝謝! :) –