2

I am having a strange problem with my Magento installation. As soon as I add a product to my wishlist (any customer), I am getting the following error in the browser's console:

Item (Magento\Wishlist\Model\Item) with the same ID X already exists.

Due to which the mini cart is not showing cart items count.

I tried to truncate the tables related to wishlist:

  • wishlist
  • wishlist_item
  • wishlist_item_option
  • email_wishlist

But every time an item is added to the wishlist, the error appears in the console.

One more (maybe related) error I noticed is in customer-data.js

customer-data.js

Maybe this is also a relevant clue:

wishlist-items-count

Update: I have tried to disable the custom modules which are overriding customer-data.js.

Thanks for your kind help in advance.

1

1 Answer 1

1

this message

'..with the same ID X already exists'

typically happens when a collection is created and a wishlist item model is assigned to the collection twice

--> the reason often is that the wishlist collection has been altered via a customisation from a third-party module. To troubleshoot, I would start directly in the collection class: \Magento\Wishlist\Model\ResourceModel\Wishlist\Collection

for instance, you can add a temporary function protected function _beforeLoad in this class and put some log that output the query:

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/wishlistquery.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info($this->getSelect()->__toString()); 

then you can run the query in mysql and if the query returns duplicate id, that's a winner..

If this method does not work, you may have to track more closely the ajax call. I'd start then to look in the network panel and try to find a place where you can pinpoint what calls the wishlist collection.

1
  • Thanks @herve-tribouilloy for your time. However, I checked and found that the class Magento\Wishlist\Model\ResourceModel\Wishlist\Collection is not being overridden. can you please guide more? Jul 10, 2020 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.