我有以下安装脚本-当我试图运行它时,我得到以下Magento错误:
Error in file: "/vagrant/site.com/public_html/app/code/local/SS/Raptor/sql/raptor_setup/install-0.0.1.php" - Wrong entity ID
安装脚本如下:
$installer = new Mage_Eav_Model_Entity_Setup();
$installer->startSetup();
$installer->addAttribute('customer', 'organisation_id', array(
'input' => 'select', //or select or whatever you like
'type' => 'int', //or varchar or anything you want it
'label' => 'Organisation ID',
'visible' => 1,
'required' => 0, //mandatory? then 1
));
$installer->addAttribute('quote', 'organisation_id', array(
'input' => 'select', //or select or whatever you like
'type' => 'int', //or varchar or anything you want it
'label' => 'Organisation ID',
'visible' => 1,
'required' => 0, //mandatory? then 1
));
$installer->addAttribute('order', 'organisation_id', array(
'input' => 'select', //or select or whatever you like
'type' => 'int', //or varchar or anything you want it
'label' => 'Organisation ID',
'visible' => 1,
'required' => 0, //mandatory? then 1
));
$installer->endSetup();
你知道为什么会这样吗?
您使用了错误的设置类。您可以使用Mage_Customer_Model_Entity_Setup
以这种方式添加属性。查看这个答案,使用Mage_Eav_Model_Entity_Setup来添加客户属性。
额外的引用属性需要一个不同的设置类。此处可以使用Mage_Sales_Model_Resource_Setup
作为模型
Magento2修复:
你需要在ModuleName/etc/module.xml文件中包含你的依赖项。我正在为产品添加一个自定义属性,并且必须包含:
<sequence>
<module name="Magento_Catalog" />
</sequence>
当您尝试为两个不同的实体创建属性时,请在config.xml
中使用以下代码 <config>
<modules>
<Namespace_Module>
<version>0.1.1</version>
</Namespace_Module>
</modules>
---
---
<resources>
<namespace_module_setup>
<setup>
<module>Namespace_Module</module>
<class>Namespace_Module_Model_Resource_Setup</class>
</setup>
</namespace_module_setup>
</resources>
在Setup.php文件中写入以下代码:
class Namespace_Module_Model_Resource_Setup extends Mage_Customer_Model_Resource_Setup
{
}
然后创建两个独立的安装程序&升级文件
install-0.1.0.php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('customer', 'organisation_id', array(
'input' => 'select', //or select or whatever you like
'type' => 'int', //or varchar or anything you want it
'label' => 'Organisation ID',
'visible' => 1,
'required' => 0, //mandatory? then 1
));
$installer->endSetup();
upgrade-0.1.0-0.1.1.php
$installer = $installer = new Mage_Sales_Model_Resource_Setup('core_setup');;
$installer->startSetup();
// now here write your code to create attribute
$installer->endSetup();