2

I am on a site magento 1.7.0.2

I created a module to add an attribute in the customer account. At first it worked, my field has been added and then I realized that I had made a spelling mistake.

so I deleted directly attribute from phpmyadmin.

And when I relaunched the website I get this error when I go to customer management:

Fatal error: Call to a member function getBackend() on a non-object

I tried many things but I have found no solution.

Here are my files :

$installer = $this;


$installer->startSetup();

$this->addAttribute('customer', 'demande', array(
    'type' => 'int', // varchar, text, int, static, datetime
    'input' => 'boolean', // text, select, date
    'label' => 'Demande de compte professionnel',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'visible_on_front' => 1
));


/**
 * Si attribut de type select :
 * 'type' => 'select',
 * 'source' => 'eav/entity_attribute_source_table',
 * 'option' => array('values' => array('Mon Option 1', 'Mon Option 2')),
 */

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


$installer->endSetup();

my config.xml file :

 <admin>
    <routers>
        <customfield>
            <use>admin</use>
            <args>
                <module>Digitgold_Demande</module>
                <frontName>customfield</frontName>
            </args>
        </customfield>
    </routers>
</admin>

<global>
    <fieldsets>
        <customer_account>
             <demande><create>1</create><update>1</update><name>1</name></demande>
        </customer_account>
    </fieldsets>
</global>
<global>
    <resources>
        <customfield_setup>
            <setup>
                <module>Digitgold_Customer</module>
                <class>Mage_Customer_Model_Entity_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </customfield_setup>
        <customfield_write>
            <connection>
                <use>core_write</use>
            </connection>
        </customfield_write>
        <customfield_read>
            <connection>
                <use>core_read</use>
            </connection>
        </customfield_read>
    </resources>
</global>

thanks

1 Answer 1

1

Your issue may have something to with used_in_forms keys didn't get deleted.

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

Take a look at database table customer_form_attribute and compare it with a older backup

To remove attribute the correct way

/* @var $installer Mage_Eav_Model_Entity_Setup */
$installer->startSetup();\
// Remove Product Attribute
$installer->removeAttribute('customer', 'product_attribute_code');

To fix your issue see Call to a member function getBackend() on a non-object

10
  • I mistake again. I tried the script also but it returns me a blank page. I do not know what to do
    – strauss
    Commented Feb 17, 2015 at 9:49
  • do you have a backup db to recreate the row you manually deleted? Commented Feb 17, 2015 at 14:49
  • my backups are created night and I create and delete the attribute in the day
    – strauss
    Commented Feb 17, 2015 at 14:51
  • I would try to create a new attribute (exactly the same except for the attribute code on a dev box). Then use it as a sample to recreate the row you manually deleted. Then try to delete both programmatically Commented Feb 17, 2015 at 14:56
  • it's just when I want to recreate an attribute that I come across this error.when i desactivate the module, I no longer have this error
    – strauss
    Commented Feb 17, 2015 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.