0

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;
  }
 }

?>

2 Answers 2

1

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

4
  • this works..but the values are not inserted in eav_attribute_option and eav_attribute_option_value table for the particular attribute
    – Sayali
    Commented Sep 13, 2013 at 10:00
  • This is normal behavior. The values in eav_attribute_option_value are for attributes with the default source model eav/entity_attribute_source_table
    – Marius
    Commented Sep 13, 2013 at 10:25
  • I want to filter product collection using products brand_pro attribute .Can you please tell how to do the same
    – Sayali
    Commented Sep 13, 2013 at 10:47
  • the same as any other attribute: ->addAttributeToFilter('brand_pro', $value);
    – Marius
    Commented Sep 13, 2013 at 11:50
0

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>

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.