2013-12-17 30 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爲模塊添加一個按鈕。單擊按鈕時,添加一個腳本以清空數據庫中的源模型字段。

每次您需要禁用該模塊時,請點擊按鈕。

更重要的是當你想啓用模塊時,增加一個按鈕來在數據庫中添加源模型。

希望此解決方案能夠幫助解決此問題的人員。