hi how to fix this error if i need to search on any product i get this error
1 exception(s): Exception #0 (Exception): Item (Magento\Catalog\Model\Product\Interceptor) with the same ID "2" already exists.
1 Answer 1
This typically means you have some duplicated records in database. However, this could happen too due to some 3rd party code in your project. It is hard to trace
Anyways, I always thought throwing an exception for this reason is a bit strict. You can avoid it by applying this patch
diff --git a/vendor/magento/framework/Data/Collection.php b/vendor/magento/framework/Data/Collection.php
index e69f7e7b..7d765283 100644
--- a/vendor/magento/framework/Data/Collection.php
+++ b/vendor/magento/framework/Data/Collection.php
@@ -402,12 +402,6 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll
$itemId = $this->_getItemId($item);
if ($itemId !== null) {
- if (isset($this->_items[$itemId])) {
- //phpcs:ignore Magento2.Exceptions.DirectThrow
- throw new \Exception(
- 'Item (' . get_class($item) . ') with the same ID "' . $item->getId() . '" already exists.'
- );
- }
$this->_items[$itemId] = $item;
} else {
$this->_addItem($item);