Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Custom Customer Entity Attribute
 
Vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

Hi,

I’m adding a new attribute to customers. But when I try to read it I get the Error:

Failed to load node from config.

The Error is raised in /var/www/vinai/netzarbeiter.de/ot/htdocs/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Config.php, where $this->_configNodePath is not set.

Where do I have to continue to add to?

Here is how I added the attribute (sql/customeractivation_setup/mysql4-install-0.1.0.php):

<?php
$read 
Mage::getSingleton('core/resource')->getConnection('core_read');

// load id for customer entity
$eid $read->fetchRow("select entity_type_id from {$this->getTable('eav_entity_type')} where entity_type_code = 'customer'");
$customer_type_id $eid['entity_type_id'];

$installer $this;
$installer->startSetup();

$c = array(
    
'entity_type_id' => $customer_type_id,
    
'attribute_code' => 'customer_activated',
    
'backend_type' => 'int',
    
'frontend_input' => 'boolean',
    
'is_global' => 1,
    
'is_visible' => 0,
    
'is_required' => 1,
    
'is_user_defined' => 1,
);

// save attribute
$attribute = new Mage_Eav_Model_Entity_Attribute();
$attribute->loadByCode($c['entity_type_id']$c['attribute_code'])
    ->
setStoreId(0)
    ->
addData($c);
$attribute->save();

$installer->endSetup();

Here is my test code, called using php-cli:

#!/usr/bin/php
<?php

chdir
(dirname(__FILE__) . '/../../../../..');
require_once 
'app/Mage.php';
umask(0);
error_reporting(E_ALL E_NOTICE);
Mage::app();

$customer Mage::getModel('customer/customer');
$customer->loadByEmail('test1@example.com');
$attributes $customer->getAttributes();

foreach (
$attributes as $attribute{
    printf
("%s > "$attribute->getName());
    try 
{
        $value 
$attribute->getFrontend()->getValue($customer);
        
var_dump($value);
    
catch (Exception $e{
        
echo $e->getMessage() . "\n";
        
$customer->setData($attribute->getName(), '1');
        
printf("new value for %s: %s\n"$attribute->getName(), $attribute->getFrontend()->getValue($customer));
    
}
}

What do Ii have to do next?

Lost,
Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
 
DraconPern
Jr. Member
 
Total Posts:  12
Joined:  2008-04-08
Texas, USA
 

My example uses a static in the eav model, see http://www.magentocommerce.com/boards/viewthread/15497/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

Hi DraconPern, thanks for your reply.
I’m getting further here, but have stumbled over an odd behaviour that might be related to why you can’t install the patch before the installation.

Here is my revised test code (it now cycles through all customers and prints out only the new customer attribute):

#!/usr/bin/php
<?php

chdir
(dirname(__FILE__) . '/../../../../..');
require_once 
'app/Mage.php';
umask(0);
error_reporting(E_ALL E_NOTICE);
Mage::app();

$customers Mage::getModel('customer/customer')->getCollection();
$customers->load();

foreach (
$customers as $id => $customer{
    
if (! $customer || ! $customer->getId()) {
        
echo "ERROR: unable to load customer with id $id\n";
        continue;
    
}
    $attribute 
$customer->getAttribute('customer_activated');
    
printf("Customer entity id: %d\n"$customer->getId());
    
printf("%s > "$attribute->getName());
    try 
{
        $value 
$attribute->getFrontend()->getValue($customer);
        
var_dump($value);
    
catch (Exception $e{
        
echo $e->getMessage() . "\n";
        
//$customer->setData($attribute->getName(), '0');
        //printf("new value for %s: \"%s\"\n", $attribute->getName(), $attribute->getFrontend()->getValue($customer));
    
}

    
echo "\n-------------------------------------------------\n\n";
}

Here is the output:

$ ./test.php
Customer entity id
2
customer_activated 
Failed to load node  from config.

-------------------------------------------------

Customer entity id3
customer_activated 
string(2"No"

-------------------------------------------------

Customer entity id5
customer_activated 
string(2"No"

-------------------------------------------------

The loading of the first customer always brings this error.
If I delete the first customer using the adminhtml interface, the error occurs on the next first customer (in this case the one with the id 3).

Has anybody got an explanation for this strange behaviour?
I can’t find a reason in the db tables or in the code.

Thanks, Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
 
DraconPern
Jr. Member
 
Total Posts:  12
Joined:  2008-04-08
Texas, USA
 

Hum.. it should be a seperate issue since my patch works with the first customer. btw, did you edit your setup.php file?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

Yes, setup in sql/customeractivation_setup/mysql4-install-0.1.0.php works fine.

Small update: The first call to

$attribute->getFrontend()->getValue($customer);
triggers the error.
A second call straight away brings the correct result without throwing a new error:

try {
        $value 
$attribute->getFrontend()->getValue($customer);
    
catch (Exception $e{
        $value 
"second try: " $attribute->getFrontend()->getValue($customer);
}
var_dump
($value);

*sigh* time to look at when the model loads this “config” nodes…

Strange.
Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

OMG, a reply to a thread after 5 years ^^

OK, a bit of background. 
The error message is part of the source model class Mage_Eav_Model_Entity_Attribute_Source_Config
This class can’t be used on its own, it always has to be extended, and the extending source model class only needs to set the $_configNodePath property to where the options are stored in the configuration, and the superclass will then do the rest.

The probably cause is that this class is set as the default source model in Mage_Eav_Model_Entity, and returned by Mage_Eav_Model_Entity_Attribute_Abstract::getSource() if no source model is set on a select or multi select frontend_input attribute.

So the first thing to do would be to check that all your (multi)select attributes of customers on your site have a source model defined.

If that isn’t the reason, then probably the answer is that you are using a source model for a customer attribute which extends from Mage_Eav_Model_Entity_Attribute_Source_Config, but doesn’t point $_configNodePath to a valid configuration node.
To fix it, check all customer source models if the extend from eav/entity_attribute_source_config, and if so, if the specified xpath is valid.

Hope that helps,
Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

Vinai, I don’t know if this is the same situation, but I have a customer database that I am trying to export and I either get Failed to load node from config or I get 0 records?

Image Attachments
Screen Shot 2014-03-10 at 9.04.38 PM.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

Vinai, I don\’t know if this is the same situation, but I have a customer database that I am trying to export and I either get Failed to load node from config or I get 0 records?

Image Attachments
Screen Shot 2014-03-10 at 9.04.38 PM.png
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top