2013-12-17 29 views
1

我创建了一个模块,然后使用升级脚本添加multiselect属性。该属性使用“源”来动态获取它的值。代码如下: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(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 

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

回答

0

首先,您是否在禁用模块后清空缓存?

或者这可能是一个编译错误?试试this出来。

尝试追踪/lib/Varien/Autoload.php on line 93拨打mageDebugBacktrace()的问题。

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

+2

问题是因为它被添加到属性集中并且已经保存在数据库中。如果模块被禁用并且我们正在创建新产品,则magento正在搜索属性源以获取值。但它无法获得,因为模块本身已被禁用。 – vishant

+0

@vishant如果您找到解决方案,请分享吗? –

1

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

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

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

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

希望此解决方案能够帮助解决此问题的人员。