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;
}
}
}
It's Work for me.
Reference Link