2

I have the following InstallData.php in my Setup directory in my module. The script does not seem to execute at all. I have tried throwing an Exception at the beginning, dumping and dying, etc. Nothing seems to stop the script or output and information while running setup:upgrade.

NB: I have removed the module's row from the setup_module table before each run. I've also tried with EavSetupFactory - no luck there either.

Any thoughts would be appreciated.

<?php

namespace Tridum\Thumbnail\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\Catalog\Setup\CategorySetupFactory;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;

/**
 * @codeCoverageIgnore
 */
class InstallData implements InstallDataInterface
{
    /**
     * @var EavSetupFactory
     */
    private $categorySetupFactory;

    /**
     *
     * @param CategorySetupFactory $categorySetupFactory
     */
    public function __construct(CategorySetupFactory $categorySetupFactory)
    {
        $this->categorySetupFactory = $categorySetupFactory;
    }

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

        /** @var EavSetup $eavSetup */
        $eavSetup = $this->categorySetupFactory->create(['setup' => $setup]);

        $eavSetup->addAttribute(
            Category::ENTITY,
            'thumbnail',
            [
                'type' => 'varchar',
                'label' => 'Category Thumbnail',
                'input' => 'image',
                'backend' => 'Magento\Catalog\Model\Category\Attribute\Backend\Image',
                'required' => false,
                'sort_order' => 9,
                'global' => ScopedAttributeInterface::SCOPE_STORE,
                'group' => 'General Information',
                'default' => null,
            ]
        );

        $setup->endSetup();
    }
}
1

try this code.

<?php
namespace Tridum\Thumbnail\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface
{

    private $eavSetupFactory;


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

    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

        $eavSetup->addAttribute(
            \Magento\Catalog\Model\Category::ENTITY,
            'thumbnail',
            [
                 'group'        => 'General Information',
                 'label'        => 'Category Thumbnail',
                 'type'         => 'varchar',
                 'input'        => 'image',
                 'required'     => false,
                 'sort_order'   => 9,
                 'backend'      => '\Magento\Catalog\Model\Category\Attribute\Backend\Image',
                 'global'       => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            ]
        );

        $setup->endSetup();
    }
}
  • Thanks for posting. I pasted in your code, deleted the row for the module from the setup_module table, and then ran "magento setup:upgrade". Still no thumbnail eav_attribute. I must be missing something else? – TomWilsonFL Jan 17 '18 at 11:21
  • Can you please check that you are put proper code and run command, because I already used same code to create attibute and it working fine. – Dhiren Vasoya Jan 17 '18 at 12:47
  • Yes, the code is exact. Are there other steps I am missing? Is there a good way to debug these install scripts? There is no output anywhere saying whether these scripts are running or not. If I throw an Exception on the first line of the install method, I never see the Exception. – TomWilsonFL Jan 17 '18 at 16:58
  • You can cross verify the code from magento root. You can try to run the script from there, so you get idea script is working. – Dhiren Vasoya Jan 18 '18 at 4:13
  • I'm not sure what you mean by "magento root" or "run the script from there." Where is there? Are you saying move InstallData.php to /pub and access the script from the browser? – TomWilsonFL Jan 20 '18 at 12:50

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.