Magento的错误时,禁用模块 [英] Magento Error when Disable module

查看:171
本文介绍了Magento的错误时,禁用模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个模块,然后使用升级脚本添加多选属性。属性是使用源,以让它动态值。在code是以下内容:

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:

添加属性:

$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是:

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

}

在code是工作的罚款时能够动态检索值,但问题当模块禁用它是扔的时候我在管理创建一个新产品的错误目录无法找到。

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.

错误:

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

有没有一种方法,以prevent当模块禁用此错误?我不想做卸载因为我将失去我的数据库的所有数据。感谢您的任何指导或帮助您可以提供我..

推荐答案

这个问题是因为它已经在数据库保存 - EAV属性表

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

这我实现的一个解决方案是增加使用系统的xml为模块的按钮。添加脚本来清空源模型领域在数据库中单击按钮时。

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.

这篇关于Magento的错误时,禁用模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆