2

i have added below code but i get above error: Source model "unidesign/myoption" not found for attribute "catcustomergroup"

i have added custom field to category add i am using below installer script:

it works fine but i want to show customer group dropdown here , i am stucked u how can i do it

app\code\local\Devshree\Unidesing\etc\config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Devshree_Unidesing>
      <version>0.1.0</version>
    </Devshree_Unidesing>
  </modules>
  <global>

    <resources>
      <customcatattrb_setup>
        <setup>
          <module>Devshree_Unidesing</module>
          <class>Mage_Eav_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>default_setup</use>
        </connection>
      </customcatattrb_setup>
    </resources>
  </global>
</config> 

app\code\local\Devshree\Unidesing\sql\customcatattrb_setup\mysql4-install-0.0.1.php

<?php
$installer = $this;
$installer->startSetup();
$attribute  = array(
    'type' => 'select',
    'label'=> 'Customer Group',
    'input' => 'select',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => true,
    'required' => false,
     'source' => "unidesign/myoption",
    'user_defined' => true,
    'default' => "",
    'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'catcustomergroup', $attribute);
$installer->endSetup();
?>

app\code\local\Devshree\Unidesing\Model\Myoption.php

<?php
  Class MyNameSpace_Mymodule_Model_Myoption
 extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    /**
     * Retrieve all options array
     *
     * @return array
     */
   public function getAllOptions()
{
    if (is_null($this->_options)) {

     $options = Mage::getResourceModel('directory/country_collection')->load()->toOptionArray();
    array_unshift($options, array('value'=>'', 'label'=>Mage::helper('customer')->__('Select')));
        $this->_options =$options;
    }
    return $this->_options;
}
    /**
     * Retrieve option array
     *
     * @return array
     */
    public function getOptionArray()
    {
        $_options = array();
        foreach ($this->getAllOptions() as $option) {
            $_options[$option["value"]] = $option["label"];
        }
        return $_options;
    }

    /**
     * Get a text for option value
     *
     * @param string|integer $value
     * @return string
     */
    public function getOptionText($value)
    {
        $options = $this->getAllOptions();
        foreach ($options as $option) {
            if ($option["value"] == $value) {
                return $option["label"];
            }
        }
        return false;
    }

    /**
     * Retrieve Column(s) for Flat
     *
     * @return array
     */
    public function getFlatColums()
    {
        $columns = array();
        $columns[$this->getAttribute()->getAttributeCode()] = array(
            "type"      => "tinyint(1)",
            "unsigned"  => false,
            "is_null"   => true,
            "default"   => null,
            "extra"     => null
        );

        return $columns;
    }

    /**
     * Retrieve Indexes(s) for Flat
     *
     * @return array
     */
    public function getFlatIndexes()
    {
        $indexes = array();

        $index = "IDX_" . strtoupper($this->getAttribute()->getAttributeCode());
        $indexes[$index] = array(
            "type"      => "index",
            "fields"    => array($this->getAttribute()->getAttributeCode())
        );

        return $indexes;
    }

    /**
     * Retrieve Select For Flat Attribute update
     *
     * @param int $store
     * @return Varien_Db_Select|null
     */
    public function getFlatUpdateSelect($store)
    {
        return Mage::getResourceModel("eav/entity_attribute")
            ->getFlatUpdateSelect($this->getAttribute(), $store);
    }
}

problem i that i want to customer group drop down here how can i do this please help

3 Answers 3

4

First you have to fix a couple of problems with your module. You need to define the model in your config.xml and you have declared your class incorrectly in your Myoption.php file.

In app\code\local\Devshree\Unidesing\Model\Myoption.php change:

Class MyNameSpace_Mymodule_Model_Myoption
extends Mage_Eav_Model_Entity_Attribute_Source_Abstract

To:

class Devshree_Unidesing_Model_Myoption
extends Mage_Eav_Model_Entity_Attribute_Source_Abstract

In app\code\local\Devshree\Unidesing\etc\config.xml replace it with this:

<?xml version="1.0"?>
<config>
  <modules>
    <Devshree_Unidesing>
      <version>0.1.0</version>
    </Devshree_Unidesing>
  </modules>
  <global>
    <models>
        <unidesign>
            <class>Devshree_Unidesing_Model</class>
        </unidesign>
    </models>
    <resources>
      <customcatattrb_setup>
        <setup>
          <module>Devshree_Unidesing</module>
          <class>Mage_Eav_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>default_setup</use>
        </connection>
      </customcatattrb_setup>
    </resources>
  </global>
</config> 
1

These error due to the source file structure and file names.Please enter the model class name in the config.xml

<?php
 $this->startSetup();
 $this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'custom_dropdown', array(
'group'         => 'General Information',
'input'         => 'select',
'type'          => 'text',
'label'         => 'Custom Dropdown',
'backend'       => '',
'visible'       => true,
'required'      => false,
'visible_on_front' => true,
'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'source' => 'customfeaturedattribute/source_custom',
));

$this->endSetup();

And enter the class name in the config.xml file.

 <models>
        <customfeaturedattribute>
            <class>Addpeople_CustomFeaturedAttribute_Model</class>
        </customfeaturedattribute>
    </models>

Please my tutorial as well which explains the file structure and how to add custom options.

http://www.pearlbells.co.uk/how-to-add-custom-dropdown-attribute-to-magento-category-section/

0

Please add the source to the installer script. You must add the following line.

'source' => 'eav/entity_attribute_source_table'

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.