0

I have a console command class with constrcutor that looks like this:

namespace Vendor\Module\Console\Command;


use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ImportProduct extends Command
{

    const DUMMY_KEYBRAND_NAME = '-- Dummy Key Brand';
    const NAME_ARGUMENT = "name";
    const NAME_OPTION = "option";

    public function __construct(
      \Magento\Store\Model\StoreManagerInterface $storeManager,
      \Magento\Framework\File\Csv $csv,
      \Magento\Catalog\Model\ResourceModel\Product $productResource,
      \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory,
      \Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepositoryInterface,
      \Magento\Catalog\Model\Product\Action $productAction,
      \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory,
      \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
      \Magento\Catalog\Model\ProductFactory $productFactory,
      \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
      \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry 
    ){
      $this->_storeManager = $storeManager;
      $this->csv = $csv;
      $this->productResource = $productResource;
      $this->_attrOptionCollectionFactory = $attrOptionCollectionFactory;
      $this->eavAttributeRepository = $eavAttributeRepositoryInterface; 
      $this->productAction = $productAction;
      $this->categoryCollectionFactory = $categoryCollectionFactory;
      $this->productRepository = $productRepository;
      $this->stockRegistry = $stockRegistry;
      $this->indexerRegistry = $indexerRegistry; 
      parent::__construct();
    }

...
}

when i run php bin/magento setup:upgrade` , it always shows an error like this:

Type Error occurred when creating object: Vendor\Module\Console\Command\ImportProduct\Interceptor

6
  • I'm not sure where the issue might be. There are 2 things I propose you to check: 1. Empty the whole cache, generate di files (setup:di:compile), etc. I've seen this type error many times in my life. 2. Check this module which actually works fine (checked by myself :D): github.com/catgento/magento-2-category-importer/blob/master/… – PauGNU Apr 9 '20 at 7:25
  • @PauGNU still same error – jojo Apr 9 '20 at 7:38
  • In your example, $eavSetupFactury is missing in the construct function arguments. Add \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory to your construct arguments and check if that's it. – PauGNU Apr 9 '20 at 8:46
  • @PauGNU i've fixed it , but still get the same error – jojo Apr 9 '20 at 8:48
  • Most probably one of your dependencies cannot be instantiated. I don't have a solution but you can get more info in the method Magento\Framework\ObjectManager\Factory\AbstractFactory::createObject(). That's the one that throws the exception. On the catch block you can check how the $exception->getMessage() looks like. It should tell you more details about the problem. – Marius Apr 9 '20 at 8:54

Your Answer

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

Browse other questions tagged or ask your own question.