magento-2-blog
magento-2-blog copied to clipboard
Create/edit post blank page if more post contains same product
If more posts contains the same related products, the admin crate/edit post is blank.
Preconditions
- Magento: 2.3.5-p1
- PHP: 7.2
- MySQL: 5.7
Steps to reproduce
- create a blog post with a related product
- create a second blog post with the same related product
- click on "Add New Post", the page don't load properly and you'll get the CRITICAL error on the sysyem.log
Expected result
- The new post page should load properly
Actual result
- in the system.log main.CRITICAL: Item (Magento\Catalog\Model\Product\Interceptor) with the same ID "1" already exists. [] []
Did you find a solution for this? We're facing the same problem.
Edit: I think I found it.
We're on Magento 2.3.4, Mageplaza_Blog 3.1.3.
In Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Product::_prepareCollection(), the join condition has to be changed when we're editing a post.
Old code:
$collection->getSelect()->joinLeft(
['mp_p' => $collection->getTable('mageplaza_blog_post_product')],
'e.entity_id = mp_p.entity_id',
['position']
);
New code:
$postId = $this->getRequest()->getParam('id');
$cond = $postId ? 'e.entity_id = mp_p.entity_id AND mp_p.post_id = ' . (int)$postId : 'e.entity_id = mp_p.entity_id';
$collection->getSelect()->joinLeft(
['mp_p' => $collection->getTable('mageplaza_blog_post_product')],
$cond,
['position']
);
Nope, I'm waiting for a solution or a temporary workaround. I'll try the solution you posted as soon as I can.
For the moment a very big "thank you" :)
@thaimageplaza can my fix be integrated in the next release please? Or are there side cases where it doesn't work?
The code fixed the problem for me but... it seems a new problem is facing. While search for related products, a JS error occures in grid.js at line 474
Uncaught TypeError: Cannot read property 'down' of null at g.bindFieldsChange (grid.js:474) at g.initGrid (grid.js:113) at g.initGridAjax (grid.js:132) at fire (jquery.js:3238) at Object.fireWith (jquery.js:3368) at done (jquery.js:9861) at XMLHttpRequest.callback (jquery.js:10317)
Hi @giacomopiva @simonrl I see that group by statement was removed in commit eaee6ccefb12630db3804fae121cd36ba53bd6e0 and bringing it back solves both above problems for me. This way I can open edit page and i do not have that grid.js error. I also kept extended left join by @simonrl
Above is PR so feel free to review. Hope it helps.
I did't check it in M2.4
I would recommend to merge the above PR from @nkajic . This is still an issue which has a big impact on webshops with a lot of blog posts. the fix with adding distinct(true) (#307 ) isn't enough to fix the problem.
@phutx Would you please look at this issue and PR?
Thanks
Hi @Alainvdz99,
Have you upgraded your Blog module to the latest version? I am pleased to let you know that the related product issue has been resolved in the newest version.
Thanks!
Hi @phutx,
I did upgrade the module to version 3.2 and we are using Magento 2.3. It did fix some blog posts but there were still a lot of blog post that gave a blank page if there were more posts with the same related product. The PR from @nkajic did fix it for me