When you get error like: Item (MagentoCatalogModelProductInterceptor) with the same ID “<id>” already exists.
Then you can use below module to resolve above error.
1. Create new folders Magemonkey/DuplicateEntry in app/code magento folder.
2. add new file registration.php in DuplicateEntry folder and put below code.
<?php MagentoFrameworkComponentComponentRegistrar::register( MagentoFrameworkComponentComponentRegistrar::MODULE, 'Magemonkey_DuplicateEntry', __DIR__ );
3. add new file etc/module.xml in DuplicateEntry folder and put below code.
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Magemonkey_DuplicateEntry" setup_version="1.0.1"></module> </config>
4. add new file etc/di.xml in DuplicateEntry folder and put below code.
<?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="MagentoEavModelEntityCollectionAbstractCollection">
<plugin name="find_duplicate_entry" type="MagemonkeyDuplicateEntrypluginCollection" sortOrder="20"/>
</type>
</config>
5. add new file plugin/Collection.php in DuplicateEntry folder and put below code.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
*/
namespace MagemonkeyDuplicateEntryplugin;
use MagentoFrameworkDataCollectionEntityFactoryInterface;
use MagentoFrameworkOptionArrayInterface;
class Collection
{
/**
* @param MagentoEavModelEntityCollectionAbstractCollection $subject
* @param Closure $process
* @param MagentoFrameworkDataObject $dataObject
* @return $this
*/
public function aroundAddItem(MagentoEavModelEntityCollectionAbstractCollection $subject, Closure $process, MagentoFrameworkDataObject $dataObject)
{
try{
return $process($dataObject);
}catch ( Exception $e){
return $this;
}
}
}

