Magento Error when Disable module

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(MageModuleModelEntityAttributeSourceSuperbadgeConfig.php) [function.include]: failed to open stream: No such file or directory  in C:SitesprojectdevelopmentlibVarienAutoload.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..


The issue is because it is already save in db - eav attribute table.

One solution that i implemented is to add a button using system xml for the module. add a script to empty the source model field in the database when click the button.

click on the button everytime you need to disable the module.

the more important is to add one more button to add the source model in the database when you want to enable the module.

hope this solution will help someone who come accross this issue.


First of all did you flush the cache after you disabled the module?

Or maybe it's an compilation error? Try this out.

Try to track down where exactly the issue is coming up with a call of mageDebugBacktrace() in /lib/Varien/Autoload.php on line 93 .

Let me know if some of the above worked for you!

链接地址: http://www.djcxy.com/p/22488.html

上一篇: 如何检查Python中的列表是否为空?

下一篇: Magento错误时禁用模块