我创建了一个模块,然后使用升级脚本添加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
是否有办法防止这种错误时,模块是禁用?我不想卸载,因为我将丢失我的数据库中的所有数据。感谢您提供的任何指南或帮助。
问题是因为它被添加到属性集中并且已经保存在数据库中。如果模块被禁用并且我们正在创建新产品,则magento正在搜索属性源以获取值。但它无法获得,因为模块本身已被禁用。 – vishant
@vishant如果您找到解决方案,请分享吗? –