我已经使用Attribute接口成功创建了一个新属性,但当我在magento后端检查我的属性时,“商店所有者的目录输入类型”下拉列表显示为灰色 . 如果我从后端创建属性,则不会禁用下拉列表,因此用户可以随时更改类型 .

这是使用禁用的下拉列表创建属性的代码:

$attribute = $this->_attributeInterface; // \Magento\Eav\Api\Data\AttributeInterface
$attribute->setEntityTypeId(4);
$attribute->setIsUserDefined(1);
$attribute->setAttributeCode($newAttribute);
$attribute->setDefaultFrontendLabel(strtolower($newAttribute));
$attribute->setFrontendInput('text');
$attribute->setBackendType('varchar');
$attribute->setScope("global");
$attribute->setIsRequired(false);
$attribute->setIsUnique(false);
$attribute->setIsSearchable(false);
$attribute->setIsComparable(false);
$attribute->setIsVisibleOnFront(true);
$attribute->setIsFilterable(false);
$attribute->setUsedInProductListing(false);
$attribute->setIsVisible(true); // ?
// \Magento\Eav\Api\AttributeRepositoryInterface
$this->_attributeRepositoryInterface->save($attribute);

我使用magento 2.1的代码是这样的:

$newattribute = $eavsetup->addAttribute('catalog_product', $attributecode, [
        'type' => $type,
        'backend' => '',
        'frontend' => '',
        'label' => $label,
        'input' => $input,
        'class' => '',
        'source' => '', 
        'global' => $scope, 
        'visible' => true,
        'required' => false,
        'user_defined' => true, 
        'default' => '',
        'searchable' => false,
        'filterable' => false,
        'comparable' => false,
        'visible_on_front' => true,
        'used_in_product_listing' => false,
        'unique' => false,
        //'apply_to' => ''
    ]);

使用此代码,创建的属性具有“商店所有者的目录输入类型”drowpdown不会显示为灰色,因此以前的版本可以正常工作 . 我需要从直接调用模型的先前版本切换到使用接口和存储库的新代码 . 但是,我无法切换,直到下拉列表正确显示 .

谁知道怎么解决这个问题?