自定义类别属性已创建但未保存
-
12-12-2019 - |
题
我创建了一个自定义扩展,以便在产品类别上添加自定义属性。这是我用来创建它的代码:
$installer = $this;
$installer->startSetup();
$attribute = array(
'type' => 'int',
'label'=> 'Featured Author',
'input' => 'checkbox',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => 0,
'source' => "eav/entity_attribute_source_boolean",
'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'featured_author', $attribute);
$installer->endSetup();
该属性已创建并且在后端可见。我还检查了 eav_attribute 数据库表,该属性也在其中创建。
但是更改属性的值(选中/取消选中)然后保存类别根本没有效果。属性值未更新/保存。该复选框始终处于未选中状态。
我应该怎么做才能解决这个问题?
解决方案
使用字段是/否而不是复选框
$installer =new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup;
$installer = $this;
$installer->startSetup();
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$installer->addAttribute('catalog_category', 'featured_author', array(
'type' => 'int',
'label' => 'Featured Author',
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'required' => false,
'default' => 0
'group' => "General Information"
));
$installer->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'featured_author',
'10'
);
$attributeId = $installer->getAttributeId($entityTypeId, 'featured_author');
$installer->run("
INSERT INTO `{$installer->getTable('catalog_category_entity_int')}`
(`entity_type_id`, `attribute_id`, `entity_id`, `value`)
SELECT '{$entityTypeId}', '{$attributeId}', `entity_id`, '1'
FROM `{$installer->getTable('catalog_category_entity')}`;
");
$installer->endSetup();
. 其他提示
我已经检查了一个非常简单的解决方案,可以在 Magento 管理中以类别形式添加新属性。
我发现有 3 张桌子负责这个问题。
步骤1:- 从您的管理面板创建一个属性。
第2步:- 转到数据库并打开 eav_attribute
表,查找属性 attribute_code
. 。现在让 entity_type_id
4 至 3
步骤3:- 去 eav_entity_attribute
表插入一行 entity_type_id =3
, attribute_set_id = 3
, attribute_group_id=4
, attribute_id = your attribute id
.
步骤4:- 现在转到 catalog_eav_attribute
表放 is_global = 1
,
is_visible=1
.
现在刷新您的类别编辑页面,它就会出现