Magento 1.4.2 : errors when saving custom customer Attributes
I can't save my custom customer attributes:
My Magento backend is blocked and I get this errors :
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
This is my module code: in file 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();
and here is my config.xml file:
<?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>
I use Magento 1.4.2
Please help to solve this problem.
Thanks a lot.
[edit]
Thanks a lot for help, the code of Nasaralla seems to be working, but I discover that my problem come from a YES/NO select: Here is the code for the select box:
$installe开发者_如何学运维r->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();
It will be very helpful if anyone help me to solve the really problem
[/edit]
Get rid of this part in install script
Mage::getSingleton( 'eav/config' )
->getAttribute( 'customer', 'kd_nr' )
->setData( 'used_in_forms', array( 'adminhtml_customer' ) )
->save();
In order to call eav_setup you do
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
and then you can updateAttribute like:
$setup->updateAttribute ($entityTypeId,$id,$field,$value = null,$sortOrder=null)
You can get the list of methods you can call in here:
Freegento-Eav-Model-entity-setup
Therefore your code, I think, will be replaced by:
$setup->updateAttribute('customer', 'kd_nr', 'used_in_forms', 'adminhtml_customer');
Ok if the above didn't work at all ... I think lets revert back to your original script and I think I can spot some fixes:
<?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();
For details check the upgrade script mysql4-data-upgrade-1.4.0.0.7-1.4.0.0.8.php at core/Mage/Customer
精彩评论