I've create a module to add a custom attribute to my categories, however my code doesn't seem to be creating the attribute in my eav_attribute table, the field shows on my category pages but it doesn't save the values?
Can anyone advise why this isn't working.
/app/code/Auto/CategoryAttributes/Setup/InstallData.php
<?php
namespace Autosmart\CategoryAttributes\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;
use Magento\Catalog\Model\Category;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* @var EavSetupFactory
*/
private $eavSetupFactory;
/**
*
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
Category::ENTITY,
'category_short_description',
[
'type' => 'text',
'label' => 'Category Short Description',
'input' => 'textarea',
'visible_on_front' => true,
'required' => false,
'sort_order' => 1,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
]
);
}
}
/app/code/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="autosmart_additonal_content">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Autosmart Additonal Content</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">100</item>
</item>
</argument>
<field name="category_short_description">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">1</item>
<item name="dataType" xsi:type="string">string</item>
<item name="formElement" xsi:type="string">textarea</item>
<item name="label" xsi:type="string" translate="true">Category Short Description</item>
<item name="required" xsi:type="boolean">false</item>
</item>
</argument>
</field>
</fieldset>