1


Ive added my own color attribute for categories following this guide:
Magento 2 DevDocs: How to add a Category Attribute

But when I save my category my field is not saved.

First I created a 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, 'color', [
            'type'     => 'varchar(5)',
            'label'    => 'Color',
            'input'    => 'text',
            'source'   => 'Magento\Eav\Model\Entity\Attribute\Source\Text',
            'visible'  => true,
            'default'  => '',
            'required' => false,
            'global'   => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'group'    => 'Display Settings',
        ]);
    }
}


Then Ive added my 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="display_settings">
        <field name="color" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataType" xsi:type="string">color</item>
                    <item name="label" xsi:type="string" translate="true">Farbe</item>
                    <item name="default" xsi:type="string"></item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>


Then I run:

php bin/magento setup:upgrade
php bind/magento setup:di:compile

The Field is showing up in the backend at the right place but when I enter a value and click save the value is not saved.

So can anyone tell me whats wrong with my script?

1
  • Enter only 4 character into input and check is value save or not? Oct 16, 2017 at 8:50

1 Answer 1

0

you have added data type 'type' => 'varchar(5)', in your script, so please try to add less then 5 character into input and then check your value is save or not.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.