0

i am getting error on magento as:

[2019-10-21 09:13:37] main.CRITICAL: Exception: Item (Magento\Catalog\Model\Product\Interceptor) with the same ID "2015" already exists. in /home1/dtdemo/public_html/vdf/vendor/magento/framework/Data/Collection.php:406
Stack trace:
#0 /home1/dtdemo/public_html/vdf/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php(304): Magento\Framework\Data\Collection->addItem(Object(Magento\Catalog\Model\Product\Interceptor))
#1 /home1/dtdemo/public_html/vdf/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php(1119): Magento\Eav\Model\Entity\Collection\AbstractCollection->addItem(Object(Magento\Catalog\Model\Product\Interceptor))
#2 /home1/dtdemo/public_html/vdf/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php(910): Magento\Eav\Model\Entity\Collection\AbstractCollection->_loadEntities(false, false)
#3 /home1/dtdemo/public_html/vdf/vendor/magento/module-catalog/Model/ResourceModel/Product/Collection.php(727): Magento\Eav\Model\Entity\Collection\AbstractCollection->load(false, false)
#4 /home1/dtdemo/public_html/vdf/vendor/magento/framework/Interception/Interceptor.php(146): Magento\Catalog\Model\ResourceModel\Product\Collection->load(false, false)
#5 /home1/dtdemo/public_html/vdf/var/generation/Magento/Catalog/Model/ResourceModel/Product/Collection/Interceptor.php(26): Magento\Catalog\Model\ResourceModel\Product\Collection\Interceptor->___callPlugins('load', Array, Array)
#6 /home1/dtdemo/public_html/vdf/vendor/magento/framework/Data/Collection.php(831): Magento\Catalog\Model\ResourceModel\Product\Collection\Interceptor->load()
#7 [internal function]: Magento\Framework\Data\Collection->count()
#8 /home1/dtdemo/public_html/vdf/app/design/frontend/Mgs/adella/MGS_Mpanel/templates/widget/product_grid.phtml(24): count(Object(Magento\Catalog\Model\ResourceModel\Product\Collection\Interceptor))
#9 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/home1/dtdemo/p...')
#10 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Element/Template.php(255): Magento\Framework\View\TemplateEngine\Php->render(Object(MGS\Mpanel\Block\Widget\ProductList\Interceptor), '/home1/dtdemo/p...', Array)
#11 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Element/Template.php(279): Magento\Framework\View\Element\Template->fetchView('/home1/dtdemo/p...')
#12 /home1/dtdemo/public_html/vdf/app/code/MGS/Mpanel/Block/Widget/ProductList.php(54): Magento\Framework\View\Element\Template->_toHtml()
#13 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Element/AbstractBlock.php(659): MGS\Mpanel\Block\Widget\ProductList->_toHtml()
#14 /home1/dtdemo/public_html/vdf/vendor/magento/module-widget/Model/Template/Filter.php(117): Magento\Framework\View\Element\AbstractBlock->toHtml()
#15 /home1/dtdemo/public_html/vdf/vendor/magento/module-widget/Model/Template/Filter.php(128): Magento\Widget\Model\Template\Filter->generateWidget(Array)
#16 [internal function]: Magento\Widget\Model\Template\Filter->widgetDirective(Array)
#17 /home1/dtdemo/public_html/vdf/vendor/magento/framework/Filter/Template.php(141): call_user_func(Array, Array)
#18 /home1/dtdemo/public_html/vdf/vendor/magento/module-email/Model/Template/Filter.php(1011): Magento\Framework\Filter\Template->filter('<div>\t<div id="...')
#19 /home1/dtdemo/public_html/vdf/vendor/magento/module-cms/Block/Page.php(157): Magento\Email\Model\Template\Filter->filter('<div>{{widget t...')
#20 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Element/AbstractBlock.php(659): Magento\Cms\Block\Page->_toHtml()
#21 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Element\AbstractBlock->toHtml()
#22 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(518): Magento\Framework\View\Layout->_renderBlock('cms_page')
#23 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout->renderNonCachedElement('cms_page')
#24 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(570): Magento\Framework\View\Layout->renderElement('cms_page', false)
#25 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('content', false)
#26 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout->renderNonCachedElement('content')
#27 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(570): Magento\Framework\View\Layout->renderElement('content', false)
#28 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('main', false)
#29 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout->renderNonCachedElement('main')
#30 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(570): Magento\Framework\View\Layout->renderElement('main', false)
#31 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('columns', false)
#32 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout->renderNonCachedElement('columns')
#33 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(570): Magento\Framework\View\Layout->renderElement('columns', false)
#34 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('main.content', false)
#35 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout->renderNonCachedElement('main.content')
#36 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(570): Magento\Framework\View\Layout->renderElement('main.content', false)
#37 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('page.wrapper', false)
#38 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper')
#39 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(570): Magento\Framework\View\Layout->renderElement('page.wrapper', false)
#40 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('root', false)
#41 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(472): Magento\Framework\View\Layout->renderNonCachedElement('root')
#42 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Layout.php(939): Magento\Framework\View\Layout->renderElement('root')
#43 /home1/dtdemo/public_html/vdf/vendor/magento/framework/Interception/Interceptor.php(146): Magento\Framework\View\Layout->getOutput()
#44 /home1/dtdemo/public_html/vdf/var/generation/Magento/Framework/View/Layout/Interceptor.php(39): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array)
#45 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Result/Page.php(243): Magento\Framework\View\Layout\Interceptor->getOutput()
#46 /home1/dtdemo/public_html/vdf/vendor/magento/framework/View/Result/Layout.php(167): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#47 /home1/dtdemo/public_html/vdf/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#48 /home1/dtdemo/public_html/vdf/vendor/magento/framework/Interception/Chain/Chain.php(70): MGS\Mpanel\Block\Framework\Page\Interceptor->___callParent('renderResult', Array)
#49 /home1/dtdemo/public_html/vdf/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('MGS\\Mpanel\\Bloc...', 'renderResult', Object(MGS\Mpanel\Block\Framework\Page\Interceptor), Array, 'result-varnish-...')
#50 /home1/dtdemo/public_html/vdf/vendor/magento/module-page-cache/Model/Controller/Result/VarnishPlugin.php(74): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#51 /home1/dtdemo/public_html/vdf/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\PageCache\Model\Controller\Result\VarnishPlugin->aroundRenderResult(Object(MGS\Mpanel\Block\Framework\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
#52 /home1/dtdemo/public_html/vdf/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('MGS\\Mpanel\\Bloc...', 'renderResult', Object(MGS\Mpanel\Block\Framework\Page\Interceptor), Array, 'result-builtin-...')
#53 /home1/dtdemo/public_html/vdf/vendor/magento/module-page-cache/Model/Controller/Result/BuiltinPlugin.php(67): MGS\Mpanel\Block\Framework\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#54 /home1/dtdemo/public_html/vdf/vendor/magento/framework/Interception/Interceptor.php(142): Magento\PageCache\Model\Controller\Result\BuiltinPlugin->aroundRenderResult(Object(MGS\Mpanel\Block\Framework\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
#55 /home1/dtdemo/public_html/vdf/var/generation/MGS/Mpanel/Block/Framework/Page/Interceptor.php(39): MGS\Mpanel\Block\Framework\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#56 /home1/dtdemo/public_html/vdf/vendor/magento/framework/App/Http.php(140): MGS\Mpanel\Block\Framework\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#57 /home1/dtdemo/public_html/vdf/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#58 /home1/dtdemo/public_html/vdf/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#59 {main} [] []

Complete code of product_grid.phtml: https://pastebin.com/1RqSKE0U Please help me.

0

Duplicate entry in cataloginventory_stock_item is a common source for this error. It is possible to search for an ID if you have one. To find all duplicate product entity_ids, simply use the following SQL statement:

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 )
)

This will helps you out try This, If its work approve the Answer Thanks:)

| improve this answer | |
  • NO, there not showing any duplicate Ids – Shiv Singh Oct 21 '19 at 9:34
  • try Below solution! – Munesh Jalwani Oct 21 '19 at 9:38
0

To resolve this issue to to

lib/Varien/Data/Collection.php

public function addItem(Varien_Object $item)
    {
        $itemId = $this-&gt;_getItemId($item);

        if (!is_null($itemId)) {
            if (isset($this-&gt;_items[$itemId])) {
               // throw new Exception('Item ('.get_class($item).') with the same id "'.$item-&gt;getId().'" already exist');
            }
            $this-&gt;_items[$itemId] = $item;
        } else {
            $this-&gt;_addItem($item);
        }
        return $this;
    }

comment the throw exception line!

| improve this answer | |
  • Commenting this line will never solve issues, because that is only showing error – Shiv Singh Oct 21 '19 at 9:54
0

You a LEFT JOIN in you collection which is causing the error.

All collections in Magento need to have unique items, where the uniqueness of the items is added by id of the entity (entity_id in you case).

I would suggest you add a breakpoint to frontend/Mgs/adella/MGS_Mpanel/templates/widget/product_grid.phtml(24) and retrieve the (string)$collection->getSelect() in order to see the actual query going to the database.

Product with id 2015 is returned multiple times (at least 2 times) in your collection

| improve this answer | |
  • i have added complet code of product_grid.phtml: pastebin.com/1RqSKE0U – Shiv Singh Oct 21 '19 at 13:20
  • You can seed the select by adding on line 4 the following code: echo (string)$products->getSelect(); die; – bluscience Oct 21 '19 at 14:04

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.