0

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.

enter image description here

asked Sep 28, 2024 at 10:03

1 Answer 1

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);
answered Oct 1, 2024 at 14:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.