9

I'm following many articles but i'm not able create multi select attribute. and i'm getting following error.

a:5:{i:0;s:50:"Source model "" not found for attribute "exinent1"";i:1;s:3008:"#0 C:\wamp\www\magento8\app\code\core.

and my script is:

<?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', 'exinent1', array(
 'input' => 'multiselect', 
 'type' => 'varchar', 
 'backend' => 'eav/entity_attribute_backend_array',
 'label' => 'exinent1',
 'visible' => 1,
 'required' => 0,
 'user_defined' => 1,
 'option' => array (
 'value' => array('optionone' => array('First Option'),
 'optiontwo' => array('Second Option'),
 'optionthree' => array('Third Option'),
 )
 ),
));
$setup->addAttributeToGroup(
 $entityTypeId,
 $attributeSetId,
 $attributeGroupId,
 'exinent1',
 '100'
);
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'exinent1');
$oAttribute->setData('used_in_forms', array('adminhtml_customer')); 
$oAttribute->save();
$setup->endSetup();

and config.xml is:

<?xml version="1.0"?>
<config>
 <modules>
 <Exinent_Cusatt>
 <version>3.1.5.6</version>
 </Exinent_Cusatt>
 </modules>
 <global>
 <resources>
 <exinent_cusatt_setup>
 <setup>
 <module>Exinent_Cusatt</module>
 </setup>
 </exinent_cusatt_setup>
</resources>
 </global>
</config>
Manashvi Birla
8,8739 gold badges29 silver badges53 bronze badges
asked Jul 1, 2014 at 10:48
2
  • You have to setup EAV resource model ... Commented Jul 1, 2014 at 10:52
  • can you refer any article? Commented Jul 1, 2014 at 11:01

2 Answers 2

10

I think you made lot of mistakes ..Here you go,

etc/config.xml

<?xml version="1.0"?>
<config>
 <modules>
 <Exinent_Cusatt>
 <version>0.1.0</version>
 </Exinent_Cusatt>
 </modules>
 <global>
 <helpers>
 <cusatt>
 <class>Exinent_Cusatt_Helper</class>
 </cusatt>
 </helpers>
 <models>
 <cusatt>
 <class>Exinent_Cusatt_Model</class>
 <resourceModel>cusatt_mysql4</resourceModel>
 </cusatt>
 </models>
 <resources>
 <customerattribute1404212233_setup>
 <setup>
 <module>Exinent_Cusatt</module>
 <class>Mage_Customer_Model_Entity_Setup</class>
 </setup>
 <connection>
 <use>core_setup</use>
 </connection>
 </customerattribute1404212233_setup>
 <customerattribute1404212233_write>
 <connection>
 <use>core_write</use>
 </connection>
 </customerattribute1404212233_write>
 <customerattribute1404212233_read>
 <connection>
 <use>core_read</use>
 </connection>
 </customerattribute1404212233_read>
 </resources>
 </global>
</config> 

Helper/Data.php :

<?php
class Exinent_Cusatt_Helper_Data extends Mage_Core_Helper_Abstract
{
}

Mode/Eav/Entity/Attribute/Source/Customeroptions14042122330.php

<?php
class Exinent_Cusatt_Model_Eav_Entity_Attribute_Source_Customeroptions14042122330 extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
 /**
 * Retrieve all options array
 *
 * @return array
 */
 public function getAllOptions()
 {
 if (is_null($this->_options)) {
 $this->_options = array(
 array(
 "label" => Mage::helper("eav")->__("Myoption-1"),
 "value" => 1
 ),
 array(
 "label" => Mage::helper("eav")->__("Myoption-2"),
 "value" => 2
 ),
 array(
 "label" => Mage::helper("eav")->__("Myoption-3"),
 "value" => 3
 ),
 array(
 "label" => Mage::helper("eav")->__("Myoption-4"),
 "value" => 4
 ),
 );
 }
 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);
 }
}

sql/customerattribute1404212233_setup/mysql4-install-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("customer", "exinent", array(
 "type" => "text",
 "backend" => "",
 "label" => "exinent1",
 "input" => "multiselect",
 "source" => "cusatt/eav_entity_attribute_source_customeroptions14042122330",
 "visible" => true,
 "required" => false,
 "default" => "",
 "frontend" => "",
 "unique" => false,
 "note" => ""
 ));
 $attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "exinent");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
 $attribute->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)
 ;
 $attribute->save();
$installer->endSetup();

Thats it.. Just enable your module declare your code pool, And dont confuse with the numbers.. <customerattribute1404212233_setup> Its just random no for you attribute identity, for prevent duplicate entry. ..Cheers ..!

answered Jul 1, 2014 at 11:07
1
  • Actually My multiselect attribute is shipping terms.And I'm creating one module which contain entity with two columns(shipping term,enable/disable).So i need to map this entity to created shipping terms attribute options.Please give some direction to this. Commented Jul 1, 2014 at 11:52
1

Hi Elavarasan and Sivakumar ,

It is not good idea to call option code in static..... You just need to fetch using Eav table

$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('customer','exinent1');
 $collection =Mage::getResourceModel('eav/entity_attribute_option_collection')
 ->setPositionOrder('asc')
 ->setAttributeFilter($attributeId)
 ->setStoreFilter(0)
 ->load();

Surcemodel getAllOptions() should be

 public function getAllOptions()
 {
 if (is_null($this->_options)) {
 attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('customer','attribute_name');
 $collection =Mage::getResourceModel('eav/entity_attribute_option_collection')
 ->setPositionOrder('asc')
 ->setAttributeFilter($attributeId)
 ->setStoreFilter(0)
 ->load();
 $this->_options = $collection->toOptionArray()
 }
 }
answered Jul 1, 2014 at 11:27
3
  • Actually My multiselect attribute is shipping terms.And I'm creating one module(using ultimate module creator) which contain entity with two columns(shipping term,enable.disable).So i need to map this entity to created shipping terms attribute options.Please give some direction to this. Commented Jul 1, 2014 at 11:51
  • i have tell you .Need some change Elavaras answer.Just change the code in source model code Commented Jul 1, 2014 at 11:55
  • ok thank you.for example get all options is dynamic(getting options from shipping terms table).after installing script i disable some records(shipping terms).so it will reflect in customer account information ? Commented Jul 1, 2014 at 12:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.