3

I am creating a custom attribute for categories using this resource.

The attribute field "Tagline - Category Head" is shown fine in the backend, but when I type a value and save the category, the value is not saved (it stays blank). I also searched the database for any field named "tagline" and nothing came up.

Here is the code

Setup/InstallData.php (just the install function)

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    /** @var EavSetup $eavSetup */
    $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

    /**
     * Add attributes to the eav/attribute
     */

    $eavSetup->addAttribute(
    \Magento\Catalog\Model\Category::ENTITY, 'tagline1', 
        [
            'type' => 'text',
            'label' => 'Tagline - Category Head',
            'input' => 'text',
            'source' => '',
            'visible_on_front' => true,
            'required' => false,
            'sort_order' => 100,
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'group' => 'General Information',
        ]
    );
}

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="taglines">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Taglines</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="sortOrder" xsi:type="number">100</item>
            </item>
        </argument>
        <field name="tagline1">
            <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">input</item>
                    <item name="label" xsi:type="string" translate="true">Tagline - Category Head</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>
2

Attribute type "Text" doesn't working as you need to change it as varchar.

You are not getting value in even database just because of it, check in eav_attribute as your attribute length is 0.

  • what about checkbox.? – Sarfaraj Sipai Dec 8 '17 at 9:35
  • smallint use for checkbox – Ronak Chauhan Dec 8 '17 at 9:47
  • till not saved checkbox value... – Sarfaraj Sipai Dec 8 '17 at 9:55
  • set length 6 to smallint – Ronak Chauhan Dec 8 '17 at 10:28
  • till not working.. May share my code with you ? – Sarfaraj Sipai Dec 8 '17 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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