Атрибут пользовательской категории не отображается в magento2


Я создал пользовательский атрибут, используя приведенное здесь решение.

Создать пользовательскую категорию Да/Нет атрибута magento2

Атрибут создан, и я вижу запись в таблице атрибутов eav_attribute базы данных.

Но когда я открываю отдельную категорию в панели администратора. Созданный новый пользовательский атрибут не отображается. Пожалуйста, кто-нибудь, помогите мне, есть ли еще какие-нибудь настройки, которые мне нужно сделать?

Author: jafar pinjar, 2018-11-09

2 answers

enter image description here

Setup/InstallData.php

<?php


namespace Vendor\Module\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;

class InstallData implements InstallDataInterface
{

    private $eavSetupFactory;

    /**
     * Constructor
     *
     * @param \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory
     */
    public function __construct(EavSetupFactory $eavSetupFactory)
    {
        $this->eavSetupFactory = $eavSetupFactory;
    }

    /**
     * {@inheritdoc}
     */
    public function install(
        ModuleDataSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

        $eavSetup->addAttribute(
            \Magento\Catalog\Model\Category::ENTITY,
            'is_featured',
            [
                'type' => 'int',
                'label' => 'Is Home Category',
                'input' => 'boolean',
                'sort_order' => 333,
                'source' => '',
                'global' => 1,
                'visible' => true,
                'required' => false,
                'user_defined' => false,
                'default' => null,
                'group' => 'General Information',
                'backend' => ''
            ]
        );
    }
}

View/adminhtml/ui_component/category_form.xml

<?xml version="1.0" ?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="general">
        <field name="is_featured">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="required" xsi:type="boolean">false</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">false</item>
                    </item>
                    <item name="sortOrder" xsi:type="number">333</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="label" translate="true" xsi:type="string">Is Home Category</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>
 4
Author: Hassan Ali Shahzad, 2018-11-09 07:28:12

Вам нужно будет добавить это поле в форму категории, чтобы отобразить его. Создайте XML-файл по пути: app/code/Vendor/Module/view/adminhtml/ui_component/category_form.xml

Добавьте приведенный ниже код в форму category_form:

<field name="name-of-you-custom-field">
<argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
        <item name="sortOrder" xsi:type="number">10</item>
        <item name="dataType" xsi:type="string">boolean</item>
        <item name="formElement" xsi:type="string">checkbox</item>
        <item name="source" xsi:type="string">category</item>
        <item name="prefer" xsi:type="string">toggle</item>
        <item name="label" xsi:type="string" translate="true">Label of the field</item>
        <item name="valueMap" xsi:type="array">
            <item name="true" xsi:type="string">1</item>
            <item name="false" xsi:type="string">0</item>
        </item>
        <item name="validation" xsi:type="array">
            <item name="required-entry" xsi:type="boolean">false</item>
        </item>
        <item name="default" xsi:type="string">1</item>
    </item>
</argument>

 0
Author: Prachi Saxena, 2018-11-09 07:29:05