1

I want to add some new category attributes along with a new category attribute group to group them all under.

The upgrade is being ran with no errors but it doesn't seem to run the code even though it looks perfect to me. Am I missing something?

UpgradeData.php

class UpgradeData implements UpgradeDataInterface

{
    private $eavSetupFactory;

    public function __construct(EavSetupFactory $eavSetupFactory) {
        $this->eavSetupFactory = $eavSetupFactory;
    }

    public function upgrade(ModuleDataSetupInterface $setup,ModuleContextInterface $context)
    {
        $setup->startSetup();

        if (version_compare($context->getVersion(), '1.0.4', '<')) {

            $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

            $eavSetup->addAttributeGroup(
                Category::ENTITY,
                $eavSetup->getDefaultAttributeSetId(Category::ENTITY),
                'Thirdlight Settings',
                99
            );

            $eavSetup->addAttribute(\Magento\Catalog\Model\Category::ENTITY, 'thirdlight_banner', [
                'type'     => 'string',
                'label'    => 'Thirdlight Banner',
                'input'    => 'text',
                'source'   => '',
                'visible'  => true,
                'default'  => '',
                'required' => false,
                'global'   => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'group'    => 'Thirdlight Settings',
            ]);

        $setup->endSetup();
    }

Module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Avery_Orderattribs" setup_version="1.0.4">
        <sequence>
            <module name="Magento_Sales"/>
        </sequence>
    </module>
</config>
1

For your attribute, the 'type' should be 'varchar'.

The documentation on https://devdocs.magento.com/videos/fundamentals/add-new-product-attribute/ is about product attributes but category attributes will behave in the same way.

If this does not work, you can use 'type'=>'text' but you will need to add either 'size'=>255 or 'length'=>255 (right now I don't remember which it should be).

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.