magento 2.2.5通过属性接口创建的属性禁用了“商店所有者的目录输入类型”

时间:2018-11-19 13:37:56

标签: magento interface attributes magento2.2

我已经成功使用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不会灰显,因此以前的版本可以完美运行。我需要从直接调用模型的先前版本切换到使用接口和存储库的新代码。但是,直到下拉列表正确显示,我才能切换。

有人知道如何解决这个问题吗?

0 个答案:

没有答案