Question

i try to add a new category attribute in Magento 2.3.6 and render an input in the category backend. Setup worked, attribute is created. But the category_form.xml seems to be ignored. Maybe someone can show me whats wrong here.

I used this explanation first: https://devdocs.magento.com/guides/v2.3/ui_comp_guide/howto/add_category_attribute.html

But i dont get the Attribute shown in backend. Module is enabled, setup creates the entries in eav_attribute and catalog_eav_attribute. I dont have errors in the logs.

Vendor/Module/Setup/InstallData.php

<?php
namespace Vendor\Module\Setup;

use Magento\Framework\Setup\{
    ModuleContextInterface,
    ModuleDataSetupInterface,
    InstallDataInterface
};

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;

class InstallData implements InstallDataInterface
{
    private $eavSetupFactory;
    
    public function __construct(EavSetupFactory $eavSetupFactory) {
        $this->eavSetupFactory = $eavSetupFactory;
    }
    
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
        $eavSetup->removeAttribute(\Magento\Catalog\Model\Category::ENTITY, 'product_group');
        $eavSetup->addAttribute(\Magento\Catalog\Model\Category::ENTITY, 'product_group', [
            'type'     => 'varchar',
            'label'    => 'Product Group',
            'default'  => null,
            'input'    => 'text',
            'visible'  => true,
            'required' => false,
            'global'   => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'group'    => 'general',
            'source' => '',
            'backend'  => '',
            'user_defined' => false,
            'sort_order'   => 100,
        ]);
    }
}

UI Component Vendor/Module/view/adminhtml/ui_component/category_form.xml

<?xml version="1.0" encoding="UTF-8"?>
<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="product_group">
            <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">100</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">Product Group</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

Would be great if someone can help me :)

Regards, Andreas

No correct solution

OTHER TIPS

Can you try my code

app/code/Mag/CategoryProduct/Setup/InstallData.php

<?php


namespace Mag\CategoryProduct\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,
            'category_product',
                [

                    'type' => 'text',
                    'label' => 'Category Product',
                    'input' => 'textarea',
                    'required' => false,
                    'sort_order' => 333,
                    'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                    'is_html_allowed_on_front' => true,
                    'group' => 'General Information',
                    'used_in_product_listing' => true, // for category pages
                    'visible_on_front' => true, // for frontend??
                    'is_used_in_grid' => true, // for category pages
                    'is_visible_in_grid' => true, // for category pages 
                    'note' => 'Only Five SKU Product Show in Frontend' //add this line

                ]
        );
    }
}

After Create input filed in admin section.

app/code/LR/CategoryProduct/view/adminhtml/ui_component/category_form.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- file: app/code/Atwix/CategoryAttribute/view/adminhtml/ui_component/category_form.xml -->
<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="category_product">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="class" xsi:type="string">Magento\Catalog\Ui\Component\Category\Form\Element\Wysiwyg</item>
                <item name="formElement" xsi:type="string">wysiwyg</item>
            <item name="label" xsi:type="string" translate="true">Category Product</item>
                <item name="wysiwygConfigData" xsi:type="array">
                    <item name="settings" xsi:type="array">
                        <item name="theme_advanced_buttons1" xsi:type="string">bold,italic,|,justifyleft,justifycenter,justifyright,|,fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code</item>
                        <item name="theme_advanced_buttons2" xsi:type="boolean">false</item>
                        <item name="theme_advanced_buttons3" xsi:type="boolean">false</item>
                        <item name="theme_advanced_buttons4" xsi:type="boolean">false</item>
                        <item name="theme_advanced_statusbar_location" xsi:type="boolean">false</item>
                    </item>
                    <item name="files_browser_window_url" xsi:type="boolean">false</item>
                    <item name="height" xsi:type="string">250px</item>
                    <item name="toggle_button" xsi:type="boolean">true</item>
                    <item name="add_variables" xsi:type="boolean">false</item>
                    <item name="add_widgets" xsi:type="boolean">false</item>
                    <item name="add_images" xsi:type="boolean">false</item>
                </item>
                <item name="template" xsi:type="string">ui/form/field</item>
                <item name="source" xsi:type="string">category</item>
                <item name="wysiwyg" xsi:type="boolean">true</item>
                <item name="dataScope" xsi:type="string">category_product</item>
                <item name="sortOrder" xsi:type="number">20</item>
                <item name="rows" xsi:type="number">8</item>
            </item>
        </argument>
    </field>
    </fieldset>
</form>

Output

enter image description here

THANKS.

I found the problem. There was a Namespace Error in the registration.php, so the module got installed, but did not work correct.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top