I created a module then use upgrade script to add a multiselect attribute. the attribute is using 'source' to get it values dynamically. the code is the following:
Add Attribute:
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->startSetup();
$productEntityId = $installer->getEntityTypeId('catalog_product');
$allAttributeSetIds = $installer->getAllAttributeSetIds($productEntityId);
$installer->addAttribute('catalog_product', 'badge',array(
'label' => 'Badge',
'type' => 'varchar',
'input' => 'multiselect',
'backend' => 'eav/entity_attribute_backend_array',
'frontend' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'source' => 'module/entity_attribute_source_superbadge_config',
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false ));
$attributeId= $installer->getAttributeId($productEntityId, 'badge');
//add to General Group of all attribute sets
foreach($allAttributeSetIds as $attributeSetId) {
$installer->addAttributeToSet($productEntityId, $attributeSetId, 'General', $attributeId);
}
$installer->endSetup();
The Source is:
class Module_Model_Entity_Attribute_Source_Superbadge_Config extends Mage_Eav_Model_Entity_Attribute_Source_Boolean
{
/**
* Retrieve all attribute options
*
* @return array
*/
public function getAllOptions()
{
if (!$this->_options) {
$superbadge = array();
$badges = Mage::getModel('module/rule')->getCollection()->getSuperBadge();
foreach ($badges as $badge){
$superbadge[] = array('label' => $badge->getName(),
'value' => $badge->getId());
}
$this->_options = $superbadge;
}
return $this->_options;
}
}
The code is working fine am able to retrieve the value dynamically but the problem when the module is disable it is throwing an error directory could not found when am creating a new product in admin.
error:
Warning: include(Mage\Module\Model\Entity\Attribute\Source\Superbadge\Config.php) [function.include]: failed to open stream: No such file or directory in C:\Sites\project\development\lib\Varien\Autoload.php on line 93
Is there a way to prevent this error when the module is disable? i dont want to do uninstall as i will lost all data in my db. Thanks for any guide or help you may provide me..