2

Hello I have created a module in accordance to the tutorial at Magento Docs

My InstallData class looks like this:

<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

 namespace Learning\ClothingMaterial\Setup;

 use Magento\Framework\Setup\InstallDataInterface;
 use Magento\Framework\Setup\ModuleContextInterface;
 use Magento\Framework\Setup\ModuleDataSetupInterface;

 /**
 * @codeCoverageIgnore
 */
 class InstallData implements InstallDataInterface
 {
     /**
      * Eav setup factory
      * @var EavSetupFactory
      */
     private $eavSetupFactory;

     /**
      * Init
      * @param CategorySetupFactory $categorySetupFactory
      */
     public function __construct(\Magento\Eav\Setup\EavSetupFactory $eavSetupFactory)
     {
        $timestamp = time();
        $myfile = fopen("install_log.txt", "a") or die("Unable to open file!");
        fwrite($myfile, $timestamp . " - Install construct start\n");
        fclose($myfile);
         $this->eavSetupFactory = $eavSetupFactory;
     }

     /**
      * {@inheritdoc}
      * @SuppressWarnings(PHPMD.CyclomaticComplexity)
      * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
      * @SuppressWarnings(PHPMD.NPathComplexity)
      */
     public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
     {
        $timestamp = time();
        $myfile = fopen("install_log.txt", "a") or die("Unable to open file!");
        fwrite($myfile, $timestamp . " - Install start\n");
        fclose($myfile);
         $eavSetup = $this->eavSetupFactory->create();
         $eavSetup->addAttribute(
             \Magento\Catalog\Model\Product::ENTITY,
             'clothing_material',
             [
                 'group' => 'General',
                 'type' => 'varchar',
                 'label' => 'Clothing Material',
                 'input' => 'select',
                 'source' => 'Learning\ClothingMaterial\Model\Attribute\Source\Material',
                 'frontend' => 'Learning\ClothingMaterial\Model\Attribute\Frontend\Material',
                 'backend' => 'Learning\ClothingMaterial\Model\Attribute\Backend\Material',
                 'required' => false,
                 'sort_order' => 50,
                 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
                 'is_used_in_grid' => false,
                 'is_visible_in_grid' => false,
                 'is_filterable_in_grid' => false,
                 'visible' => true,
                 'is_html_allowed_on_front' => true,
                 'visible_on_front' => true
             ]
         );
     }
 }

As you can see I added some write to file operations in order to check whether the class is actually called. The file never gets created. So the constructor and install method have never been called.

I already deleted the corresponding entry in the setup_module table and cleared caches, but it still dosen't get called when "php magento setup:upgrade" is executed.

What can be the reason?

1

1 Answer 1

0

This problem was solved in this other thread: Magento2: Setup Script not loaded

My particular problem was that I had more than one capital letters .. and the name of the folder wasn't the same of the module.

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.