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 VendorModuleSetup;
use MagentoFrameworkSetup{
ModuleContextInterface,
ModuleDataSetupInterface,
InstallDataInterface
};
use MagentoEavSetupEavSetup;
use MagentoEavSetupEavSetupFactory;
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(MagentoCatalogModelCategory::ENTITY, 'product_group');
$eavSetup->addAttribute(MagentoCatalogModelCategory::ENTITY, 'product_group', (
'type' => 'varchar',
'label' => 'Product Group',
'default' => null,
'input' => 'text',
'visible' => true,
'required' => false,
'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::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