Magento 1.9:sql脚本没有运行

时间:2015-07-28 04:28:40

标签: php sql magento magento-1.9

基本上我想做的是:我想要一些Customer实体的自定义属性。并在db中添加这些字段我正在执行脚本。

我尝试过很多&很多调整,方法,但我无法解决SQL脚本错误。 其中最重要的是:它会在core_resource表中输入。

我的脚本在core_resource中输入。

我根据 Alan storm Site 进行了扩展。

非常感谢任何帮助。

我的扩展程序

set up

这是我的编码部分。

模块的配置文件

<?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安装-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();

非常感谢任何帮助

注意:在localhost中,它会出错:我使用的是错误的类还是丢失了什么?

enter image description here

( ! ) 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

2 个答案:

答案 0 :(得分:1)

添加以下内容。

 <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类才能添加任何属性。

答案 1 :(得分:0)

最后我解决了它。:)。

现在它在扩展适当的类(Mage_Customer_Model_Entity_Setup)后起作用。

class StackExchange2_Customer_Model_Resource_Mysql4_Setup extends Mage_Customer_Model_Entity_Setup{ 
}