Magento – Source model “” not found for attribute “industry”

customercustomer-attributeeav

created an install script to add two fields to customer using the script below.

But I get this error.

Source model "" not found for attribute "industry"

My installer is

    $installer = $this;

    $installer->startSetup();

    $this->addAttribute('customer_address', 'industry', array(
    'type' => 'int',
    'input' => 'select',
    'label' => 'Industry',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'visible_on_front' => 1,
    'source'=>'address/entity_resourse',
    'option'=> array(
    'values' => array(
                0 => 'College & University',
                1 => 'Hotel & Motels',
                2 => 'Small/Medium Bussiness',
                3 => 'Correctional Facilities',
                4 => 'Goverment/NPOs',
                5 => 'Retail Security',
                6 => 'Homeowness',
                7 => 'Other',
            ),
        ),
    ));


$this->addAttribute('customer_address', 'resourse', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'How you heard about us?',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'visible_on_front' => 1
)); 
Mage::getSingleton('eav/config')
    ->getAttribute('customer_address', 'industry')
    ->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','adminhtml_checkout'))
    ->save();
/*
if (version_compare(Mage::getVersion(), '1.6.0', '<='))
{
    $customer = Mage::getModel('customer/address');
    $attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
    $this->addAttributeToSet('customer_address', $attrSetId, 'General', 'industry');
}
*/
if (version_compare(Mage::getVersion(), '1.6.0', '<='))
{
    $customer = Mage::getModel('customer/address');
    $attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
    $this->addAttributeToSet('customer_address', $attrSetId, 'General', 'resourse');
}
/*
if (version_compare(Mage::getVersion(), '1.4.2', '>='))
{
    Mage::getSingleton('eav/config')
    ->getAttribute('customer_address', 'industry')
    ->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))
    ->save();
}
*/
if (version_compare(Mage::getVersion(), '1.4.2', '>='))
{
    Mage::getSingleton('eav/config')
    ->getAttribute('customer_address', 'resourse')
    ->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))
    ->save();
}

$tablequote = $this->getTable('sales/quote_address');
$installer->run("ALTER TABLE  $tablequote ADD  `industry` varchar(255) NOT NULL"); 

$tablequote = $this->getTable('sales/quote_address');
$installer->run("ALTER TABLE  $tablequote ADD  `resourse` varchar(255) NOT NULL"); 


$tablequote = $this->getTable('sales/order_address');
$installer->run("ALTER TABLE  $tablequote ADD  `industry` varchar(255) NOT NULL");

$tablequote = $this->getTable('sales/order_address');
$installer->run("ALTER TABLE  $tablequote ADD  `resourse` varchar(255) NOT NULL");

$installer->endSetup(); 

resourse.php

        class Excellence_Address_Model_Entity_Resourse extends Mage_Eav_Model_Entity_Attribute_Source_Abstract

    { 
        public function getAllOptions()
        {
        if (!$this->_options) {
        $this->_options = array(
        array(
            'value' => '',
            'label' => '',
        ),
        array(
            'value' => '0',
            'label' => 'College & University',
        ),
        array(
            'value' => '1',
            'label' => 'Hotel & Motels',
        ),
        array(
            'value' => '2',
            'label' => 'Small/Medium Bussiness',
        ),
        array(
            'value' => '3',
            'label' => 'Correctional Facilities',
        ),
        array(
            'value' => '4',
            'label' => 'Goverment/NPOs',
        ),
        array(
            'value' => '5',
            'label' => 'Retail Security',
        ),
        array(
            'value' => '6',
            'label' => 'Homeowness',
        ),
        array(
            'value' => '7',
            'label' => 'Other',
        )

        );
        }
   }

config.xml

        <?xml version="1.0"?>
        <config>
            <modules>
                <Excellence_Address>
                    <version>0.2.0</version>
                </Excellence_Address>
            </modules>
            <frontend>
                <routers>
                    <address>
                        <use>standard</use>
                        <args>
                            <module>Excellence_Address</module>
                            <frontName>address</frontName>
                        </args>
                    </address>
                </routers>
                <layout>
                    <updates>
                        <address>
                            <file>address.xml</file>
                        </address>
                    </updates>
                </layout>
            </frontend>
            <global>
                <models>
                    <address>
                        <class>Excellence_Address_Model</class>
                        <resourceModel>address_mysql4</resourceModel>
                    </address>
                    <address_mysql4>
                        <class>Excellence_Address_Model_Mysql4</class>
                        <entities>
                            <address>
                                <table>address</table>
                            </address>
                        </entities>
                    </address_mysql4>
                </models>
                <resources>
                    <address_setup>
                        <setup>
                            <module>Excellence_Address</module>
                            <class>Mage_Customer_Model_Entity_Setup</class>
                        </setup>
                        <connection>
                            <use>core_setup</use>
                        </connection>
                    </address_setup>
                    <address_write>
                        <connection>
                            <use>core_write</use>
                        </connection>
                    </address_write>
                    <address_read>
                        <connection>
                            <use>core_read</use>
                        </connection>
                    </address_read>
                </resources>
                <blocks>
                    <address>
                        <class>Excellence_Address_Block</class>
                    </address>
                </blocks>
                <helpers>
                    <address>
                        <class>Excellence_Address_Helper</class>
                    </address>
                </helpers>
             </global>
             <global>
                <fieldsets>
                    <sales_convert_quote_address>
                        <industry>
                            <to_order_address>*</to_order_address>
                            <to_customer_address>*</to_customer_address>
                        </industry>
                        <resourse>
                            <to_order_address>*</to_order_address>
                            <to_customer_address>*</to_customer_address>
                        </resourse>
                    </sales_convert_quote_address>
                    <customer_address>
                        <industry>
                            <to_quote_address>*</to_quote_address>
                        </industry>
                        <resourse>
                            <to_quote_address>*</to_quote_address>
                        </resourse>
                    </customer_address>
                </fieldsets>
            </global>
        </config>

I have also spend many hours, What is the best way to find the error?? Any Idea?

Best Answer

Your industry attribute is of type select. Hence Magento looking for source file that is using to render the options of this select attribute. So you need to specify this source file using the property source. It seems that you have already set that file 'source'=>'address/entity_resourse', for industry attribute.

Now Magento will look for this file in app/code/local (or community)/Younamespace/Yormodule/Model/entity/Resource.php. I think you didnt created that file. It's content should look like

class Yournamespace_Yourmodule_Model_Entity_Resource 
{
    public function toOptionArray()
    {
        //this method returns an array which will use to render option of your attribute
    }
}