Magento通过addAttribute安装SQL脚本而不是工作客户

时间:2014-01-14 11:24:02

标签: magento

我无法创建自定义客户属性。

Xkey\
Xkey\Cadastros\
Xkey\Cadastros\etc\config.xml
Xkey\Cadastros\Helper\Data.php
Xkey\Cadastros\Model\
Xkey\Cadaestros\Model\Entity\
Xkey\Cadaestros\Model\Entity\Setup.php
Xkey\Cadaestros\sql\
Xkey\Cadaestros\sql\cadastros_setup\
Xkey\Cadaestros\sql\cadastros_setup\mysql4-install-0.1.0.php

Config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Xkey_Cadastros>
            <version>0.1.0</version>
        </Xkey_Cadastros>
    </modules>
    <global>
        <helpers>
          <cadastros>
            <class>Xkey_Cadastros_Helper</class>
          </cadastros>
        </helpers>
        <resources>
            <cadastros_setup>
                <setup>
                    <module>Xkey_Cadastros</module>
                    <class>Xkey_Cadastros_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </cadastros_setup>
            <cadastros_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </cadastros_write>
            <cadastros_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </cadastros_read>
        </resources>
    </global>
</config>

mysql4-install-0.1.0.php

<?php  
    $installer = $this;
    $installer->startSetup(); 

    //$setup = Mage::getModel('customer/entity_setup','core_setup');
    //$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

    $installer->addAttribute('customer','rede_grupo', array(
            'type' => 'varchar',
            'input' => 'text',
            'label' => 'Rede Grupo',
            'global' => true,
            'visible' => true,
            'required' => false,
            'user_defined' => true,
            'visible_on_front' => false,
            'default' => ''
        ));

    if(version_compare(Mage::getVersion(), '1.4.2', '>=')){
        Mage::getSingleton('eav/config')
        ->getAttribute('customer', 'rede_grupo')
        ->setData('used_in_forms',         array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register'))
        ->save();
    }

    $installer->endSetup(); 

这在mage_core_resource中创建'cadastros_setup'版本0.1.0但不创建字段。

我做错了什么? Magento版本:1.8.1.0

1 个答案:

答案 0 :(得分:0)

我在config.xml中做了一处更改

<global>
        <helpers>
          <cadastros>
            <class>Xkey_Cadastros_Helper</class>
          </cadastros>
        </helpers>
        <resources>
            <cadastros_setup>
                <setup>
                    <module>Xkey_Cadastros</module>
                    <class>Mage_Customer_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </cadastros_setup>
            <cadastros_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </cadastros_write>
            <cadastros_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </cadastros_read>
        </resources>
    </global>