magento2: Exception #0 (Exception): Item (Magento\Wishlist\Model\Item) with the same ID "1" already exists.

Preconditions (*)

  1. 2.3.4 community

Steps to reproduce (*)

  1. add products to wishlist with same wishlist_id

Expected result (*)

Showing all products in wishlist

Actual result (*)

  1. SELECT main_table.* FROM wishlist_item AS main_table WHERE (wishlist_id = ‘1’) AND (main_table.store_id IN(‘1’))1 exception(s): Exception #0 (Exception): Item (Magento\Wishlist\Model\Item) with the same ID “1” already exists.

Exception #0 (Exception): Item (Magento\Wishlist\Model\Item) with the same ID “1” already exists.

#1 Magento\Framework\Data\Collection\AbstractDb->loadWithFilter() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:565]
#2 Magento\Framework\Data\Collection\AbstractDb->load() called at [vendor/magento/framework/Data/Collection.php:849]
#3 Magento\Framework\Data\Collection->count() called at [vendor/magento/module-wishlist/Model/Wishlist.php:634]
#4 Magento\Wishlist\Model\Wishlist->getItemsCount() called at [vendor/magento/module-wishlist/Block/AbstractBlock.php:276]
#5 Magento\Wishlist\Block\AbstractBlock->getWishlistItemsCount() called at [generated/code/Magento/Wishlist/Block/Customer/Wishlist/Interceptor.php:297]
#6 Magento\Wishlist\Block\Customer\Wishlist\Interceptor->getWishlistItemsCount() called at [vendor/magento/module-wishlist/Block/AbstractBlock.php:301]
#7 Magento\Wishlist\Block\AbstractBlock->hasWishlistItems() called at [generated/code/Magento/Wishlist/Block/Customer/Wishlist/Interceptor.php:323]
#8 Magento\Wishlist\Block\Customer\Wishlist\Interceptor->hasWishlistItems() called at [vendor/magento/module-wishlist/view/frontend/templates/view.phtml:20]
#9 include() called at [vendor/magento/framework/View/TemplateEngine/Php.php:59]
#10 Magento\Framework\View\TemplateEngine\Php->render() called at [vendor/magento/framework/View/Element/Template.php:271]
#11 Magento\Framework\View\Element\Template->fetchView() called at [generated/code/Magento/Wishlist/Block/Customer/Wishlist/Interceptor.php:726]
#12 Magento\Wishlist\Block\Customer\Wishlist\Interceptor->fetchView() called at [vendor/magento/framework/View/Element/Template.php:301]
#13 Magento\Framework\View\Element\Template->_toHtml() called at [vendor/magento/module-wishlist/Block/Customer/Wishlist.php:276]
#14 Magento\Wishlist\Block\Customer\Wishlist->_toHtml() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1099]
#15 Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1103]
#16 Magento\Framework\View\Element\AbstractBlock->_loadCache() called at [vendor/magento/framework/View/Element/AbstractBlock.php:673]
#17 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [generated/code/Magento/Wishlist/Block/Customer/Wishlist/Interceptor.php:1051]
#18 Magento\Wishlist\Block\Customer\Wishlist\Interceptor->toHtml() called at [vendor/magento/framework/View/Layout.php:564]
#19 Magento\Framework\View\Layout->_renderBlock() called at [vendor/magento/framework/View/Layout.php:540]
#20 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#21 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:495]
#22 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#23 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:592]
#24 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:542]
#25 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#26 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:495]
#27 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#28 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:592]
#29 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:542]
#30 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#31 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:495]
#32 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#33 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:592]
#34 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:542]
#35 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#36 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:495]
#37 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#38 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:592]
#39 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:542]
#40 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#41 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:495]
#42 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#43 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:592]
#44 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:542]
#45 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#46 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:495]
#47 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#48 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:592]
#49 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:542]
#50 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#51 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:495]
#52 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#53 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:961]
#54 Magento\Framework\View\Layout->getOutput() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#55 Magento\Framework\View\Layout\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#56 Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#57 Magento\Framework\View\Layout\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:494]
#58 Magento\Framework\View\Layout\Interceptor->getOutput() called at [vendor/magento/framework/View/Result/Page.php:258]
#59 Magento\Framework\View\Result\Page->render() called at [vendor/magento/framework/View/Result/Layout.php:171]
#60 Magento\Framework\View\Result\Layout->renderResult() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#61 Magento\Framework\View\Result\Page\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#62 Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#63 Magento\Framework\View\Result\Page\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Result/Page/Interceptor.php:130]
#64 Magento\Framework\View\Result\Page\Interceptor->renderResult() called at [vendor/magento/framework/App/Http.php:120]
#65 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:24]
#66 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:261]
#67 Magento\Framework\App\Bootstrap->run() called at [index.php:41]

Related lines

  1. vendor\magento\module-wishlist\Block\Customer\Wishlist.php
    /**
     * Retrieve Wishlist Product Items collection
     *
     * @return \Magento\Wishlist\Model\ResourceModel\Item\Collection
     * @since 101.1.1
     */
    public function getWishlistItems()
    {
        if ($this->_collection === null) {
            $this->_collection = $this->_createWishlistItemCollection();
            $this->_prepareCollection($this->_collection);
            $this->paginateCollection();
        }
        echo $this->_collection->getSelect();
        return $this->_collection;
    }

Anyone knows how to fix this?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (7 by maintainers)

Most upvoted comments

Stacked with same problem. For me helped to override class with preference Magento\Wishlist\Model\Wishlist and change getItemCollection function to:

public function getItemCollection()
{
    return parent::getItemCollection()->load();
}

Point is to add load() function when creating collection with filters.