Magento2-在管理中显示多选类别属性选项时遇到问题
在中,我尝试从安装程序脚本创建multiselect类别属性。属性被创建。但我在Magento 2-管理类别页面的选项值中遇到了问题。它只显示空白文本区域 我已使用以下安装程序脚本创建了此脚本:Magento2-在管理中显示多选类别属性选项时遇到问题,magento,magento2,entity-attribute-value,Magento,Magento2,Entity Attribute Value,在中,我尝试从安装程序脚本创建multiselect类别属性。属性被创建。但我在Magento 2-管理类别页面的选项值中遇到了问题。它只显示空白文本区域 我已使用以下安装程序脚本创建了此脚本: /** @var EavSetup $eavSetup */ $eavSetup = $this->_eavSetupFactory->create(['setup' => $setup]); /** * Add attributes to the eav/
/** @var EavSetup $eavSetup */
$eavSetup = $this->_eavSetupFactory->create(['setup' => $setup]);
/**
* Add attributes to the eav/attribute for Category
*/
$eavSetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'class',
[
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'type' => 'varchar',
'label' => 'Class',
'group' => 'General Information',
'input' => 'multiselect',
'source' => '',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => true,
'sort_order' => 100,
'option' => [
'value' => [
'SET' => ['SET'],
'HE' => ['HE'],
'HBR' => ['HBR'],
]
],
]
);
在数据库中,我可以看到,属性是在eav表中创建的,选项和值也在那个里
为了解决这个问题,我在自定义模块中添加了xml,该模块包含以下xml(..\view\adminhtml\ui\u component\category\u form.xml)
一串
多选
70
选课
您应该修复配置数组中的选项
键,如下所示:
“选项”=>[
'values'=>['SET','HE','HBR'],
],
values
键用于添加选项,而value
键用于更新已经存在的选项,因此请小心使用它们
有关完整的解释,请参见
Magento\Eav\Setup\EavSetup
类中的addAttributeOption
方法代码。谢谢您的回复。但问题是如何在管理类别面板中获取属性选项,这一问题同样没有得到解决。
source is blank thats why it showing blank in multi select use
'source' => 'modulename/modelname',
and in source file use
public function getAllOptions()
{
if (is_null($this->_options)) {
$this->_options = array(array(
'label' => Mage::helper('catalog')->__('Label'),
'value' => 'value'
));
}
return $this->_options;
}