Magento 1.4.2:保存自定义客户属性时出错

时间:2011-08-03 12:37:04

标签: magento

我无法保存自定义客户属性:

我的Magento后端被阻止,我收到了这个错误:

2011-08-03T12:27:36+00:00 ERR (3): Warning: include(Mage\Customer\Model\Attribute\Data\.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory  in C:\xampp\htdocs\magento_test142_3\lib\Varien\Autoload.php on line 93

2011-08-03T12:27:36+00:00 ERR (3): Warning: include() [<a href='function.include'>function.include</a>]: Failed opening 'Mage\Customer\Model\Attribute\Data\.php' for inclusion (include_path='C:\xampp\htdocs\magento_test142_3\app\code\local;C:\xampp\htdocs\magento_test142_3\app\code\community;C:\xampp\htdocs\magento_test142_3\app\code\core;C:\xampp\htdocs\magento_test142_3\lib;.;C:\xampp\php\PEAR')  in C:\xampp\htdocs\magento_test142_3\lib\Varien\Autoload.php on line 93

这是我的模块代码: 在文件mysql4-install-0.1.0.php中:

<?php
$installer=new  Mage_Customer_Model_Entity_Setup ('core_setup');
$installer->startSetup();


$installer->addAttribute('customer', 'kd_nr', array(
    'label'        => 'Kundennummer',
    'visible'      => true,
    'required'     => false,
    'position'     => 20,
   ));   
Mage::getSingleton( 'eav/config' )
->getAttribute( 'customer', 'kd_nr' )
->setData( 'used_in_forms', array( 'adminhtml_customer' ) )
->save();

$installer->endSetup();

这是我的config.xml文件:

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Newattcustomer>
            <version>0.1.1</version>
        </Mycompany_Newattcustomer>
    </modules>
    <global>


                <resources>
                    <newattcustomer_setup>
                        <setup>
                            <module>Mycompany_Newattcustomer</module>
                        </setup>
                        <connection>
                            <use>core_setup</use>
                        </connection>
                    </newattcustomer_setup>
                </resources>
         <fieldsets>
            <customer_account>
                        <kd_nr><create>1</create><update>1</update></kd_nr> 
            </customer_account>                
         </fieldsets>        

    </global>
</config>

我使用的是Magento 1.4.2

请帮助解决这个问题。

非常感谢。

[编辑]

非常感谢您的帮助,Nasaralla的代码似乎正在运行,但我发现我的问题来自于是/否选择:这是选择框的代码:

$installer->addAttribute('customer', 'in_search', array(
    'label'        => 'Appear in search',
    'type'         => 'int',
    'input'        => 'select',
    'source'       => 'eav/entity_attribute_source_boolean',
    'visible'      => true,
    'required'     => false,
   ));   
Mage::getSingleton( 'eav/config' )
->getAttribute( 'customer', 'in_search' )
->setData( 'used_in_forms', array( 'adminhtml_customer' ) )
->save();

如果有人帮我解决真正的问题,将会非常有帮助

[/编辑]

2 个答案:

答案 0 :(得分:1)

在安装脚本中删除此部分

Mage::getSingleton( 'eav/config' )
->getAttribute( 'customer', 'kd_nr' )
->setData( 'used_in_forms', array( 'adminhtml_customer' ) )
->save();

为了调用eav_setup,你可以

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

然后你可以更新像:

$setup->updateAttribute ($entityTypeId,$id,$field,$value = null,$sortOrder=null)

您可以在此处获取可以调用的方法列表:

Freegento-Eav-Model-entity-setup

因此,我认为您的代码将被替换为:

$setup->updateAttribute('customer', 'kd_nr', 'used_in_forms', 'adminhtml_customer');

答案 1 :(得分:0)

好的,如果上面的内容根本不起作用......我想让我们回到原来的脚本,我想我可以发现一些修复:

    <?php
$installer=new  Mage_Customer_Model_Entity_Setup ('core_setup');
$installer->startSetup();

$installer->addAttribute('customer', 'kd_nr', array(
    'label'           => 'Kundennummer',
    'is_visible'      => 1,
    'is_required'     => 0,
    'sort_order'      => 20,
   ));   

    $attr = Mage::getSingleton( 'eav/config' )->getAttribute( 'customer', 'kd_nr' );
$attr->setData( 'used_in_forms', array( 'adminhtml_customer' ) )
$attr->save();

$installer->endSetup();

有关详细信息,请查看core / Mage / Customer上的升级脚本mysql4-data-upgrade-1.4.0.0.7-1.4.0.0.8.php