Magento 2 – Item with the same ID already exists
Another error message I fixed was “Item (Magento\Catalog\Model\Product\Interceptor) with the same ID already exists“. You see it in the screenshot attached to this post. The mentioned ID was a product that I manually deleted. I checked it twice (in shop backend and database) – there is no product with this entity_id. I show you how to solve this error.
Magento 2 – Item with the same ID already exists
This problem occur if you delete a product in your shop 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 14231 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.
Suggested solution from community
A commond source for this error is a duplicate entry in cataloginventory_stock_item. You can search for an ID if you have one. If you want to find all duplicate product entity_ids then simply use this SQL statement:
1 2 3 4 5 6 7 | SELECT * FROM cataloginventory_stock_item WHERE product_id in ( SELECT product_id FROM cataloginventory_stock_item GROUP BY product_id HAVING ( COUNT(product_id) > 1 ) ) |
If it finds duplicates, than you need to delete it.
My solution
My solution was a bit different, because I got the error without any duplicate stocks. I had no idea about this ID, so I used a good MySQL database tool (in my case Navicat) and search all tables for this id. The output looked as follows:
My deleted product was assigned to a category. The fix was to delete this wrong line. It appears as if there is a Magento 2 bug for deleting products and category assignments.
Conclusion
I was able to fix “Item with the same ID already exists” error. I hope you can fix it too with my tutorial and hints.
**Facing an issue (redirecting to 404 pages) while opening Product details page after data migration from 1.9 to 2.2.1**
## Preconditions
1) we migrated our project from 1.9 to 2.2.1 using data migration tool.
2) Cleared/clean the CACHE and run the INDEXING also.
3) Catalog & Category Pages are displayed properly and products are displaying as expected in Category Page.
## Steps to reproduce
1) Go to Category page and click on any displayed products.
2) It is redirecting to 404 pages.
5) throwing the below exceptions in “exceptions.log” file:-**
## Actual Result
**- clicking on product links is redirecting to 404 pages.**
**- Throws the below exception:-**
[2017-12-23 12:55:42] main.CRITICAL: Item (Magento\CatalogInventory\Model\Stock\Status) with the same ID "16523" already exists. {"exception":"[object] (Exception(code: 0): Item (Magento\\CatalogInventory\\Model\\Stock\\Status) with the same ID \"16523\" already exists. at C:\\wamp64\\www\\otcdeal2\\vendor\\magento\\framework\\Data\\AbstractSearchResult.php:269)"} []
[2017-12-23 12:59:00] main.CRITICAL: Item (Magento\CatalogInventory\Model\Stock\Status) with the same ID "153" already exists. {"exception":"[object] (Exception(code: 0): Item (Magento\\CatalogInventory\\Model\\Stock\\Status) with the same ID \"153\" already exists. at C:\\wamp64\\www\\otcdeal2\\vendor\\magento\\framework\\Data\\AbstractSearchResult.php:269)"} []
## Expected Result
– clicking on products (displayed in Category Pages) should take to product details page.
– It should not give any exception/error in the backend.
**Can someone please help me in fixing this.**
**Thanks in advance.**