---
title: "How to Fix Same ID already exists error in Magento 2"
url: "https://dolphinwebsolution.com/how-to-fix-same-id-already-exists-error-in-magento-2"
date: "2021-09-27T07:40:01+05:30"
modified: "2023-08-31T05:18:35+05:30"
author:
  name: "Jigar Patel"
categories:
  - "Magento"
word_count: 601
reading_time: "4 min read"
summary: "Item (Magento\\Catalog\\Model\\Product\\Interceptor) with the same \"ID\" ID already exists. A common source of this error is a duplicate entry in cataloginventory_stock_item. 

The mentioned ID was a..."
description: "Item (MagentoCatalogModelProductInterceptor) with the same \"ID\" ID already exists. A common source of this error is a duplicate entry in cataloginventory_sto..."
keywords: "id already exists,same id already exist,same id already exists error,same id already exists in magento,with the same id already exists magento 2, Magento"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to use custom variables in Magento 2"
    url: "https://dolphinwebsolution.com/how-to-use-custom-variables-in-magento-2"
  - title: "Top 9 Reasons to Choose Magento as Your eCommerce Platform"
    url: "https://dolphinwebsolution.com/blog/reasons-choose-magento-ecommerce-platform/"
  - title: "How to Set Custom Validation Message in Magento 2"
    url: "https://dolphinwebsolution.com/set-custom-validation-message-in-magento-2"
---

# How to Fix Same ID already exists error in Magento 2

_Published: September 27, 2021_  
_Author: Jigar Patel_  

![](https://dolphinwebsolution.com/wp-content/uploads/2023/02/How-to-Fix-Same-ID-already-exists-error-in-Magento-2-1024x536.png)

**Item (Magento\\Catalog\\Model\\Product\\Interceptor) with the same “ID” ID already exists**. A common source of this error is a duplicate entry in `cataloginventory_stock_item`.
The mentioned ID was a product that I manually deleted. I checked it twice (in backend and database) – there is no product with this entity\_id. I show you how to solve this error.

**See this entry in Exception Log :**

![AI Integration in Magento: Benefits, Use Cases and Business Impact](https://dolphinwebsolution.com/wp-content/uploads/2021/09/same-id-1024x136.png)

The best way to do that is by creating a Magento 2 plugin to extend the behavior of the public function **AddItem** of the class.

The plugin or Interceptor is a class the modifies the behavior of the public class method by interceptions. The plugin gives use three options to use After methods, Before methods and Around Method.

This issue occur if you delete a product in your backend and some information about its ID is not deleted. I had this problem in backend when I want to create a data feed of products. At first I was not able to find the problem, because a product with ID was not found and a direct connection to magento database confirms this. I supposed, that I deleted a wrong imported product a day before, but was not sure about its ID.

## How to Fix Same ID already exists error in Magento 2

You can use the module below to resolve the above error.
### Step 1: Create Registration
Create **registration.php** file in the **app/code/Dolphin/DuplicateEntry** folder with the following code.

```
<?php

\Magento\Framework\Component\ComponentRegistrar::register(
 \Magento\Framework\Component\ComponentRegistrar::MODULE,
 'Dolphin_DuplicateEntry',
 __DIR__
);
```

### Step 2: Create a module
Create a **module.xml** file in the **app/code/Dolphin/DuplicateEntry/etc** folder with the following 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="Dolphin_DuplicateEntry" setup_version="1.0.1"></module>
</config>
```

Also like to Read: [Add Product To Cart With Custom Price in Magento 2](https://dolphinwebsolution.com/magento-2-add-product-to-cart-with-custom-price)

### Step 3: Create Dependency injection
Create a **di.xml** file in the **app/code/Dolphin/DuplicateEntry/etc** folder with the following 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="Magento\Eav\Model\Entity\Collection\AbstractCollection">
    <plugin name="duplicate_entry_already_exists_bug" type="Dolphin\DuplicateEntry\Plugin\Eav\Model\Entity\Collection" sortOrder="10"/>
 </type>
</config>
```

### Step 4: Create plugin
Create a **Collection.php** file in the **app/code/Dolphin/DuplicateEntry/Plugin/Eav/Model/Entity** folder with the following code.

```
<?php
namespace Dolphin\DuplicateEntry\Plugin\Eav\Model\Entity;
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;
        }
    }
}
```

- **aroundAddItem:** **around** methods before and after their observed methods.Using these methods allow you to override an observed method. around methods must have the same name as the observed method with ‘around’ as the prefix.\[dt\_highlight color=”” text\_color=”” bg\_color=””\]If the around method does not call the `callable`, it will prevent the execution of all the plugins next in the chain and the original method call.\[/dt\_highlight\]

If you are facing any issues during implementation, use the comment section below!

If you are looking for a Magento developer to fulfill your [**Magento 2 development** ](https://dolphinwebsolution.com/magento-2-development/)needs, choose Dolphin Web Solution.

**Happy Coding!**


---

_View the original post at: [https://dolphinwebsolution.com/how-to-fix-same-id-already-exists-error-in-magento-2](https://dolphinwebsolution.com/how-to-fix-same-id-already-exists-error-in-magento-2)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-26 06:54:46 UTC_  
