Magento 1.9 : sql 脚本不是 运行

Magento 1.9 : sql script is not running

基本上我正在尝试做的事情:我想要客户实体的一些自定义属性。为了在数据库中添加这些字段,我正在执行脚本。

我尝试了很多调整和方法,但我无法解决 SQL 脚本错误。 其中重要的是:它在core_resourcetable.

中输入

我的脚本在 core_resource 中输入了条目。

我按照这个做了扩展 Alan storm Site .

非常感谢任何帮助。

我的扩展结构

这是我的编码部分。

模块配置文件

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange2_Customer>
            <version>0.1.0</version>
        </StackExchange2_Customer>
    </modules>
    <global>
        <resources>
            <stackExchange2_customer_setup>
                <setup>
                    <module>StackExchange2_Customer</module>
                    <class>StackExchange2_Customer_Model_Resource_Mysql4_Setup</class>
<!--                    <class>StackExchange2_Customer_Sql</class>-->
                </setup>
                <!--Mew node-->
                <connection> 
                    <use>core_setup</use>
                </connection>
            </stackExchange2_customer_setup>
            <!--as per sOverflow-->
            <stackExchange2_customer_write>
                    <connection>
                        <use>core_write</use>
                    </connection>
            </stackExchange2_customer_write>
            <stackExchange2_customer_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </stackExchange2_customer_read> 
        </resources>
    </global>   
</config>

Setup.php

<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//Mage_Eav_Model_Entity_Setup
class StackExchange2_Customer_Model_Resource_Mysql4_Setup extends Mage_Core_Model_Resource_Setup{

}

mysql4-install-0.1.0.php

<?php
//echo "in script";die;
$installer = $this;
echo "hi123";
$installer->startSetup();
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//attr1
$installer->addAttribute('customer','name_of_child', array(
                    'type'      => 'varchar',
                    'label'     => 'Name of child',
                    'input'     => 'text',
                    'position'  => 120,
                    'required'  => false,//or true
                    'is_system' => 0,
));

$attribute1 = Mage::getSingleton('eav/config')->getAttribute('customer', 'name_of_child');

//
$attribute1->setData('used_in_forms', array(
    'adminhtml_customer',
    'checkout_register',
    'customer_account_create',
    'customer_account_edit',
));

//
$attribute1->setData('is_user_defined', 0);

//
$attribute1->save();

Mage::log(__FILE__ . 'Update installed.');
$installer->endSetup();

非常感谢任何帮助

注意:在本地主机中它给出错误:我使用错误的 class 还是缺少任何东西?

( ! ) Fatal error: Call to undefined method StackExchange2_Customer_Model_Resource_Mysql4_Setup::addAttribute() in D:\xampp\htdocs\mykidscare\app\code\local\StackExchange2\Customer\sql\stackexchange2_customer_setup\mysql4-install-0.1.0.php on line 12

添加以下内容。

 <resources>
        <stackExchange2_customer_setup>
            <setup>
                <module>StackExchange2_Customer</module>
                <class>Mage_Eav_Model_Entity_Setup</class>
            </setup>
            <connection> 
                <use>core_setup</use>
            </connection>
        </stackExchange2_customer_setup>
        <stackExchange2_customer_write>
                <connection>
                    <use>core_write</use>
                </connection>
        </stackExchange2_customer_write>
        <stackExchange2_customer_read>
            <connection>
                <use>core_read</use>
            </connection>
        </stackExchange2_customer_read> 
    </resources>

您需要在设置中添加 Mage_Eav_Model_Entity_Setup class 才能添加任何属性。

终于解决了:) .

现在它在扩展适当的 class (Mage_Customer_Model_Entity_Setup) 后可以工作。

class StackExchange2_Customer_Model_Resource_Mysql4_Setup extends Mage_Customer_Model_Entity_Setup{ 
}