Creating an upgrade script for cloning a product with MagentoCatalogModelProductCopier has a bug.
1 2 3 4 5 6 7 8 9 10 11 |
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 have error when use product Copier function :
1 2 3 4 5 6 7 |
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 |
Simple try the our solution below :
Create di.xml file in frontend folder with the content below :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?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 :
This solution also applied for magento 2 issue 7056 : https://github.com/magento/magento2/issues/7056
Thank for reading this post, Hope it helps.