1

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?

1 Answer 1

1

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
    }
}
6
  • programmer_rkt , Please see the above. I has update of my question. Jul 15, 2014 at 6:58
  • @Supravat : can you show your config file of your module ? Jul 15, 2014 at 7:22
  • programmer_rkt , I had update config.xml file. Jul 15, 2014 at 7:36
  • your files look ok for me. are you sure you have source model file name Resource.php ? Jul 15, 2014 at 7:42
  • try to use $installer instead of $this at addAttribute section Jul 15, 2014 at 8:03

Your Answer

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

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