1

Hi I'm creating column/field for Customer Activate which is option column/field. it's created from eva_attribute and showing customer admin grid also when I click on edit particular customer record it's returning an error.

Error is: Source model "customer/source_option" not found for attribute "customeractivate"

my code is:

C:\xampp\htdocs\magento\app\code\local\Easylife\Customattribute\sql\customattribute_setup\upgrade-0.1.1-0.1.2.php

<?php
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$setup->addAttribute('customer', 'customeractivate', array(
    'label'             => 'Customer Activate',
    'type'              => 'int',
    'input'             => 'select',
    'backend'           => 'eav/entity_attribute_backend_array',
    'frontend'          => '',
    'source'            => 'customer/group_collection',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible'           => true,
    'required'          => true,
    'user_defined'      => true,
    'searchable'        => false,
    'filterable'        => false,
    'comparable'        => false,
    'option'            => array ('value' => array('optionone' => array('Yes'),
                                                   'optiontwo' => array('No'),)),
    'visible_on_front'  => false,
    'visible_in_advanced_search' => false,
    'unique'            => false
));
$setup   = Mage::getSingleton("eav/config")->getAttribute("customer", "customeractivate");
$used_in_forms=array();

$used_in_forms[]="adminhtml_customer";
$setup->setData("used_in_forms", $used_in_forms)
    ->setData("is_used_for_customer_segment", true)
    ->setData("is_system", 0)
    ->setData("is_user_defined", 1)
    ->setData("is_visible", 1)
    ->setData("sort_order", 100)
;
$setup->save();
$installer->endSetup();

C:\xampp\htdocs\magento\app\code\core\Mage\Adminhtml\Block\Customer\Grid.php

<?php
class Mage_Adminhtml_Block_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
...
 protected function _prepareColumns()
    {
 $this->addColumn('customeractivate',
            array(
                'header'=> Mage::helper('customer')->__('Customer Active'),
                'width' => '70px',
                'index' => 'status',
                'type'  => 'options',
                'options' => Mage::getResourceModel('customer/group_collection')->getOptionArray(),
            ));
     }
..
}

C:\xampp\htdocs\magento\app\code\core\Mage\Customer\Model\Resource\Group\Collection.php

<?php

class Mage_Customer_Model_Resource_Group_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{

    const STATUS_ENABLED    = 1;
    const STATUS_DISABLED   = 2;

...
  static public function getOptionArray()
    {
        return array(
            self::STATUS_ENABLED    => Mage::helper('customer')->__('Yes'),
            self::STATUS_DISABLED   => Mage::helper('customer')->__('No')
        );
    }
...
}

Can you please tell me where I went wrong?

thanks in advance.

3
  • not sure what the error is, but I saw something wrong. 'type' => 'option' should be 'type' => 'int' or 'type' => 'varchar'. Probably int.
    – Marius
    Commented Apr 17, 2014 at 9:29
  • @Marius, I have updated my code as your tip. now error is Source model customer/group_collection not found for attribute customeractivate. Commented Apr 17, 2014 at 9:33
  • 1
    The new error appears because you placed your source model inside the resource folder. Based on the values you set for the attribute, magento is looking for the class in Mage_Customer_Model_Group_Collection
    – Marius
    Commented Apr 17, 2014 at 10:44

1 Answer 1

1

Based on the comments the error occurs because the source model of the attribute is placed in the wrong folder.
It should be Mage_Customer_Model_Group_Collection instead of Mage_Customer_Model_Resource_Group_Collection

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.