Question

I have created one custom module for product attribute.I am getting this error.Can anybody tell why is this error coming?? below i have given all the files that are required.I am not getting the error please can some one help me out with this .. My code id as follows config.xml

   <?xml version="1.0"?>
  <config>
  <modules>
    <AdminModules_Brandattr>
        <version>1.0.0</version>
    </AdminModules_Brandattr>
</modules>
<global>
    <models>
        <brandattr>
            <class>AdminModule_Brandattr_Model</class>
        </brandattr>
    </models>
    <resources>
        <brandattr_setup>
            <setup>
                <module>AdminModules_Brandattr</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </brandattr_setup>

        <brandattr_write>
            <connection>
                <use>core_write</use>
            </connection>
        </brandattr_write>

        <brandattr_read>
            <connection>
                <use>core_read</use>
            </connection>
        </brandattr_read>
    </resources>
</global>

<adminhtml>
    <events>
        <catalog_product_prepare_save>
            <observers>
                <brandattr>
                    <class>brandattr/observer</class>
                    <method>productSave</method>
                </brandattr>
            </observers>
        </catalog_product_prepare_save>
    </events>
</adminhtml>

installer file

  $installer = $this;
  $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
  $installer->startSetup();

 $setup->addAttribute('catalog_product', 'brand_pro', array(
'group'         => 'General',
'input'         => 'select',
'type'          => 'text',
'label'         => 'Brand',
'source'        => 'brandattr/product_attribute_source_unit',
'backend'       => '',
'visible'       => 1,
'required'      => 0,
'user_defined'  => 1,
'searchable'    => 1,
'filterable'    => 0,
'comparable'    => 1,
'visible_on_front' => 1,
'visible_in_advanced_search'  => 0,
'is_html_allowed_on_front' => 0,
 'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,

));

$installer->endSetup();

unit.php

 <?php


   class AdminModules_Brandattr_Model_Product_Attribute_Source_Unit extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
 {
public function getAllOptions()
{
    if ($this->_options === null) {
        $this->_options = array(
            array(
                'value' => '',
                'label' => '',
            ),
            array(
                'value' => '1',
                'label' => 'Only',
            ),
            array(
                'value' => '2',
                'label' => 'Vero Moda',
            ),

        );
    }
    return $this->_options;
  }
 }

?>
Was it helpful?

Solution

The problem is here (most probably):

<brandattr>
   <class>AdminModule_Brandattr_Model</class>
</brandattr>

It should be

<brandattr>
   <class>AdminModules_Brandattr_Model</class>
</brandattr>

Notice the s at the end of AdminModules. It should be there since your module is AdminModules_Brandattr not AdminModule_Brandattr

OTHER TIPS

This tutorial I am explain how to set custom source type for an attribute.

In my tutorial I am explaining the file structure and step by step explanation of code please check.

http://www.pearlbells.co.uk/how-to-create-custom-attribute-source-type-in-magento/

 <global>
    <models>
        <categoryattr>
            <class>Addpeople_Categoryattr_Model</class>
        </categoryattr>
    </models>
    <resources>
        <addpeople_categoryattr_setup>
            <setup>
                <module>Addpeople_Categoryattr</module>
                <class>Mage_Eav_Model_Entity_Setup</class>
            </setup>
        </addpeople_categoryattr_setup>
    </resources>
</global>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top