Magento 2: How to resolve Item with the same ID “ID” already exists error?

Rahul Shukla
1 min readDec 18, 2019

Magento2 product errors: Item (Magento\Catalog\Model\Product\Interceptor) with the same ID “<id>” already exists.

Then you can use the below module to resolve the above error.

  • Create new folders RSCoder/DuplicateEntry in app/code Magento folder.
  • registration.php
<?php\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'RSCoder_DuplicateEntry',
__DIR__
);
  • etc/module.xml
<?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="RSCoder_DuplicateEntry" setup_version="1.0.1"></module>
</config>
  • etc/di.xml
<?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\Eav\Model\Entity\Collection\AbstractCollection">
<plugin name="find_duplicate_entry" type="RSCoder\DuplicateEntry\plugin\Collection" sortOrder="20"/>
</type>
</config>
  • plugin/Collection.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
*/
namespace RSCoder\DuplicateEntry\plugin;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\Option\ArrayInterface;
class Collection
{
/**
* @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $subject
* @param \Closure $process
* @param \Magento\Framework\DataObject $dataObject
* @return $this
*/
public function aroundAddItem(\Magento\Eav\Model\Entity\Collection\AbstractCollection $subject, \Closure $process, \Magento\Framework\DataObject $dataObject)
{
try{
return $process($dataObject);
}catch ( \Exception $e){
return $this;
}
}
}

Now enable the above module & It’s working fine.

Reference Link: http://www.rscoder.com/2019/12/magento-2-how-to-resolve-item-with-same.html

--

--