magento2: Uncaught Error: Cannot instantiate interface Magento\Catalog\Model\Product\CopyConstructorInterface

Creating an upgrade script for cloning a product with \Magento\Catalog\Model\Product\Copier has a bug.

Preconditions

  1. Magento 2.1.0
  2. PHP 7.0.11

Steps to reproduce

The constructor looks like this:

public function __construct(
    \Magento\Catalog\Model\Product\Copier $productCopier,
    \Magento\Framework\App\State $appState
) {
    $this->productCopier = $productCopier;
    try {
        $appState->setAreaCode('frontend');
    } catch( \Magento\Framework\Exception\LocalizedException $e ) {
        // intentionally left empty
    }
}

Then in console run bin/magento/ setup:upgrade

Expected result

No failure

Actual result

PHP Fatal error: Uncaught Error: Cannot instantiate interface Magento\Catalog\Model\Product\CopyConstructorInterface in /var/www/m210/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:73 Stack trace: #0 /var/www/m210/vendor/magento/framework/ObjectManager/ObjectManager.php(71): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\Catalog...') #1 /var/www/m210/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(126): Magento\Framework\ObjectManager\ObjectManager->get('Magento\Catalog...') #2 /var/www/m210/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(53): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument(Array, 'Magento\Catalog...', NULL, 'copyConstructor', 'Magento\Catalog...') #3 /var/www/m210/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(82): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments('Magento\Catalog...', Array, Array) #4 /var/www/m210/vendor/magento/frame in /var/www/m210/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php on line 73

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 23 (5 by maintainers)

Most upvoted comments

Try the my solution : Create di.xml file in frontend folder with the content below <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\Model\Product\CopyConstructor\Composite"> <arguments> <argument name="constructors" xsi:type="array"> <item name="crossSell" xsi:type="string">Magento\Catalog\Model\Product\CopyConstructor\CrossSell</item> <item name="upSell" xsi:type="string">Magento\Catalog\Model\Product\CopyConstructor\UpSell</item> <item name="related" xsi:type="string">Magento\Catalog\Model\Product\CopyConstructor\Related</item> <item name="catalog_inventory" xsi:type="string">Magento\CatalogInventory\Model\Product\CopyConstructor\CatalogInventory</item> <item name="downloadable" xsi:type="string">Magento\Downloadable\Model\Product\CopyConstructor\Downloadable</item> </argument> </arguments> </type> <type name="Magento\Catalog\Model\Product\Copier"> <arguments> <argument name="copyConstructor" xsi:type="object">Magento\Catalog\Model\Product\CopyConstructor\Composite</argument> </arguments> </type> </config>

see image : image

Have you tried clearing cache before running upgrade?

@dziulius yes, i did. After running composer update i run all this commands.

composer update

rm -rf var/di var/generation php bin/magento cache:flush php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento indexer:reindex

Edit. i run again php bin/magento setup:di:compile then php bin/magento indexer:reindex and i have a new error.

$ php bin/magento indexer:reindex PHP Fatal error: Uncaught Error: Cannot instantiate interface Magento\Customer\Api\GroupManagementInterface in C:\xampp\htdocs\brementools\vendor\magento\framework\ObjectManager\Factory\Dynamic\Developer.php:50 Stack trace: #0 C:\xampp\htdocs\brementools\vendor\magento\framework\ObjectManager\ObjectManager.php(70): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create(‘Magento\Custome…’) #1 C:\xampp\htdocs\brementools\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(144): Magento\Framework\ObjectManager\ObjectManager->get(‘Magento\Custome…’) #2 C:\xampp\htdocs\brementools\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(230): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument(Array, ‘Magento\Custome…’, NULL, ‘groupManagement’, ‘Magento\Catalog…’) #3 C:\xampp\htdocs\brementools\vendor\magento\framework\ObjectManager\Factory\Dynamic\Developer.php(34): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime('Magento\Cata in C:\xampp\htdocs\brementools\vendor\magento\framework\ObjectManager\Factory\Dynamic\Developer.php on line 50

Edit2 i did this to solve the errors enabled Magento modules (bin/magento module:enable --all) compiled DI (bin/magento setup:di:compile) and bin/magento setup:upgrade

Edit3 Then i got two errors solved by removing data-requiremodule and making ignore remove exception.

Edit4 Now i have a 404 error / Refused to execute script from ‘<URL>’ because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled.

it’s like a never ending nightmare! Thanks for you time!

I guess this error associated with di.xml.

have this error. Fatal Error: 'Uncaught Error: Cannot instantiate interface Future\Test\Api\Data\ShopInterface in /var/www/magento2/lib/internal/Magento/Framework/ObjectManager/Factory/Dynamic/Developer.php:50

added this lines in di.xml <preference for="Future\Test\Api\Data\ShopSearchResultsInterface" type="Magento\Framework\Api\SearchResults" /> <preference for="Future\Test\Api\Data\ShopInterface" type="Future\Test\Model\Shop" /> <preference for="Future\Test\Api\ShopRepositoryInterface" type="Future\Test\Model\ShopRepository" />

and fixed my problem.

I had a similar issue. Please, check all files in app/etc/ folder. In my case I didn’t have any di.xml in app/etc

Fatal error: Uncaught Error: Cannot instantiate interface Fudu\HelloWorld\Api\Data\StudentsRepositoryInterface in C:\xampp\htdocs\magento\vendor\magento\framework\ObjectManager\Factory\Dynamic\Developer.php:50 Stack trace: #0

follow @vutrankien but doesn’t work here’s my di.xml after i follow alot of github, stackexchange, stackoverflow …:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Fudu\HelloWorld\Api\Data\StudentsRepo" type="Fudu\HelloWorld\Api\Data\StudentsRepositoryInterface" /> </config>

because StudentsRepositoryInterface is my class

I have the same problem “PHP Fatal error: Uncaught Error: Cannot instantiate interface Magento\Catalog\Model\Product\CopyConstructorInterface” And i can not find the solution. Mage 2.1.7

This code also has the same error $om = \Magento\Framework\App\ObjectManager::getInstance();
$productCopier = $om->create(‘\Magento\Catalog\Model\Product\Copier’);