Magento错误时禁用模块

我创建了一个模块,然后使用升级脚本添加多选属性。 该属性使用“源”来动态获取它的值。 代码如下:

添加属性:

$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();

来源是:

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;
    }

}

代码工作正常,我能够动态地检索这个值,但是当模块禁用它的时候,问题是当我在管理中创建一个新产品时,抛出一个错误目录。

错误:

Warning: include(MageModuleModelEntityAttributeSourceSuperbadgeConfig.php) [function.include]: failed to open stream: No such file or directory  in C:SitesprojectdevelopmentlibVarienAutoload.php on line 93

有没有办法来防止这个错误,当模块被禁用? 我不想卸载,因为我将丢失我的数据库中的所有数据。 感谢您提供给我的任何指导或帮助。


这个问题是因为它已经保存在db-eav属性表中。

我实现的一个解决方案是使用系统xml为模块添加一个按钮。 单击按钮时,添加一个脚本以清空数据库中的源模型字段。

每次您需要禁用该模块时,请点击该按钮。

当您想要启用模块时,更重要的是添加一个按钮来在数据库中添加源模型。

希望这个解决方案能够帮助解决这个问题的人。


首先你在禁用模块后刷新了缓存?

或者,也许这是一个编译错误? 尝试一下。

尝试追踪问题出现/lib/Varien/Autoload.php on line 93mageDebugBacktrace()调用的mageDebugBacktrace()

让我知道如果上述一些为你工作!

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

上一篇: Magento Error when Disable module

下一篇: mkdir: cannot create directory : Protocol error : Virtualbox Shared folder