禁用模块时出现Magento错误

禁用模块时出现Magento错误,magento,module,attributes,Magento,Module,Attributes,我创建了一个模块,然后使用升级脚本添加了一个multiselect属性。该属性正在使用“源”动态获取其值。代码如下: 添加属性: $installer = Mage::getResourceModel('catalog/setup', 'catalog_setup'); $installer->startSetup(); $productEntityId = $installer->getEntityTypeId('catalog_product'); $allAttribut

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

添加属性:

$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(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
来源是:

$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(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
代码运行良好,我能够动态检索值,但当模块被禁用时,问题在于当我在admin中创建新产品时,它抛出了一个错误目录

错误:

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

当模块禁用时,是否有方法防止此错误?我不想卸载,因为我将丢失数据库中的所有数据。感谢您为我提供的任何指导或帮助。

首先,禁用模块后是否刷新缓存

或者可能是编译错误?试试看

在第93行的
/lib/Varien/Autoload.php中调用
mageDebugBacktrace()
,尝试追踪问题的确切位置


让我知道,如果上面的一些工作为你

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

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

每次需要禁用模块时,单击该按钮

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


希望此解决方案能帮助遇到此问题的人。

此问题是因为它已添加到属性集中,并已保存在数据库中。如果模块处于禁用状态,并且我们正在创建新产品,则magento将搜索属性源以获取值。但无法获取,因为模块本身已被禁用。@vishant如果找到解决方案,请与我们分享?