I've create a module to add a custom attribute to my categories,the field shows on my category pages but it doesn't save the values?
Working on Magento ver. 2.2.2
Can anyone advise why this isn't working.
/app/code/NameSpace/CategoryAttributes/Setup/InstallData.php
<?php
// File: Namespace/Module/Setup/InstallData.php
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->addAttribute(\Magento\Catalog\Model\Category::ENTITY, 'ss_category_color', [
'type' => 'varchar',
'label' => 'Category Color',
'input' => 'text',
'source' => '',
'visible' => true,
'default' => '',
'required' => false,
'user_defined' => false,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General Information',
]);
}
}
/app/code/NameSpace/CategoryAttributes/view/adminhtml/ui_component/category_form.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Namespace/Module/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_information">
<field name="ss_category_color">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<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" xsi:type="string" translate="true">Category Color</item>
<item name="required" xsi:type="boolean">false</item>
</item>
</argument>
</field>
</fieldset>
</form>