Closed kandrejevs closed 4 years ago
Is there any solution to this?
any solution on this?
@choukalos can you have Oleh check into this if it may be caching related?
I am having the same problem, any update on this Magento?
@pboisvert @choukalos - Any update please? This has been going on for a while (sorry for asking again but this is proving to be pretty problematic).
@kandrejevs , @BenSpace48 Please, provide the used Magento version. Was it clear install or upgrade from some other version?
I do have 2.1 and the issue is still not resolved. (i use varnish too)
btw. disabling cache, but keeping varnish on = blocks will show up;
I was noticing similar issues where my private_content_version cookie (used for the AJAX fetching of private content) wasn't set, and requesting the page didn't recreate it for me. Interestingly, adding an item to cart recreates the cookie and I'm able to see these blocks again.
In \Magento\Framework\App\PageCache\Version::process
, you can see that the private_content_version cookie isn't actually set until the first POST request is made. I suspect this is probably a bug, since sessions can still need to load private content without this precondition being met.
Steps I've used to produce:
Expected result: widget appears Actual result: no such luck
Now, add a product to the cart and navigate back to the page where the widget appears and it will render as expected.
Internal issue MAGETWO-56062
The simple solution I've used is disable caching of the Recently Viewed block by PageCache module. I just set cacheable="false" for the block as below:
<block class="Magento\Reports\Block\Product\Widget\Viewed" cacheable="false" name="product.info.viewed" template="Magento_Reports::widget/viewed/content/viewed_grid.phtml" after="product.info.upsell" >
<arguments>
<argument name="page_size" xsi:type="number">9999</argument>
</arguments>
</block>
Update: It's just working for me, but it's a terrible solution, see below comment of @BenSpace48.
@dhduc Doesn't that stop the whole page from being cached though? I'm sure I've heard that a few times, and if so that is a terrible workaround as the side effect is potentially worse than the initial issue.
Edit: It does stop the whole page from being cached:
To create an uncacheable page, mark any block on that page as uncacheable in the layout using cacheable="false".
Source - http://devdocs.magento.com/guides/v2.1/config-guide/cache/cache-priv-over.html
@BenSpace48 Yes, you're right. It's my fault, so my teammate suggests me to using AJAX alternative. Is it a better solution?
@dhduc I only know about that because I did the exact same workaround 😱
Yeah I'd say so, I think hole punching that block so it isn't cached but the rest is is the best solution but that is more back-end which is not my speciality so take that with a pinch of salt.
@BenSpace48 (y) Thanks for letting me know about my solutions.
I resolved with bin/magento cache:clean after enabling cache. For me it worked. I'm using Magento 2.1.3 and I've only tested in developer mode.
@DonnieDi - Wouldn't the problem just come back once the block is cached though?
The issue has been fixed for 2.2
Hi @slavvka,
Please keep the 2.1.x
issues open until the fix is backported to 2.1-develop
If there isn't a backport scheduled via an internal MAGETWO task, please mark the issue with an up for grabs
label so that anyone from the community was able to notice it and make a backport PR voluntarily.
Internal ticket to track issue progress: MAGETWO-66615
what is wrong with using:
`<?php /**
namespace Magento\Reports\Block\Product;
use \Magento\Framework\DataObject\IdentityInterface;
/**
@author Magento Core Team core@magentocommerce.com */ class Viewed extends AbstractProduct implements IdentityInterface { protected function _construct() { $this->addData(array('cache_lifetime' => false)); }
/**
`
Unfortunately, this still appears to be an issue on 2.2.2
Still in 2.2.3
.
I'm running into a strange issue where sometimes the recently viewed block shows and other times it does not, this is in Magento 2.2.3
.
Where the block should show I'm seeing these tags:
The block was added with this XML:
<block class="Magento\Reports\Block\Product\Widget\Viewed" name="recently_viewed" template="widget/viewed/column/viewed_images_list.phtml" before="footer.social"/>
@dan-advantec and @crantron - Have you tried adding a product to bag?
For some weird reason recently viewed products will only load once a product has been added to bag, I can replicate this on two completely separate production websites.
Any update on this @magento-engcom-team? Should we create a new issue?
I'm running into a strange issue where sometimes the recently viewed block shows and other times it does not, this is in Magento
2.2.3
.Where the block should show I'm seeing these tags:
The block was added with this XML:
<block class="Magento\Reports\Block\Product\Widget\Viewed" name="recently_viewed" template="widget/viewed/column/viewed_images_list.phtml" before="footer.social"/>
Did u find a solution yet ? This behaviour is happening for me as well in 2.2.6
I fixed this via my custom script :
<script type="text/javascript">
(function(){
let sortable = [];
//Fetch recently viewed products from local storage. Magento keeps it there.
rvp = JSON.parse(localStorage.recently_viewed_product);
var limit=0;
for (let rv in rvp) {
sortable.push(rvp[rv]);
limit++;
if(limit>7){
break;
}
}
sortable.sort(function(o1,o2){return o2.added_at - o1.added_at;});
}());
//Now you can send this sortable array as an ajax to backend and fetch the product information accordingly.
</script>
issue is still exists in magento 2.3.1 when cache is enable then recently products is not showing Anyone know how to solve this ?
@sumeetmobiwebtech Did you check my above comment ?https://github.com/magento/magento2/issues/3890#issuecomment-500468475
@anupamyx
where i need to write that code ?
i am using that code -
myblock.php
protected $recentlyViewed;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Reports\Block\Product\Viewed $recentlyViewed,
array $data = []
)
{
$this->recentlyViewed = $recentlyViewed;
parent::__construct($context, $data);
}
public function getRecentlyProducts()
{
$collection = $this->recentlyViewed->getItemsCollection()->load();
return $collection->getData();
}
my.phtml
$recentlyProducts = $this->getRecentlyProducts();
foreach ($recentlyProducts as $product) {
echo $product['sku'];
echo "<br>";
}
When cache is disable then this code working but when cache is enable then it is not working. And when i write your above code in my.phtml then it will be work @anupamyx ?
Only use this https://github.com/magento/magento2/issues/3890#issuecomment-500468475 . Magento (2.3.0) puts recently viewed in browser's local storage. This uses that. Once you get the product ids you'll have to write a controller which sends you the product information from product ids
Sorry,i am not getting. It will be great if you write step by step.
Issue still exists on 2.3.4.
Some more info; the \Magento\Reports\Block\Product\Widget\Viewed
block ultimately extends the abstract block \Magento\Reports\Block\Product\AbstractProduct
. This class contains the \Magento\Framework\View\Element\AbstractBlock::$_isScopePrivate
property, which is set to true
.
However, the Magento DevDocs on Private Content states;
Do not use the $_isScopePrivate property in your blocks. This property is obsolete and will not work properly.
This appears to be the case in this core code. So the recently viewed block code should be rewritten to not rely on $_isScopePrivate
but instead use customer-data
JS library along with a block, a template and a UI component to render the recently viewed block on a per-customer basis.
Shouldn't this be closed since there was catalog_recently_viewed
widget introduced that uses Magento\Catalog\Block\Widget\RecentlyViewed
which doesn't seem to have same issue?
I agree with @Bartlomiejsz . If anyone want to show the recently viewed product then please use the below code
<block class="Magento\Catalog\Block\Widget\RecentlyViewed"
name="recently.viewed.product">
<arguments>
<argument name="uiComponent" xsi:type="string">widget_recently_viewed</argument>
<argument name="show_attributes" xsi:type="string">name,image,price</argument>
<argument name="show_buttons" xsi:type="string">add_to_cart</argument>
<argument name="template" xsi:type="string">product/widget/viewed/grid.phtml</argument>
</arguments>
</block>
@sidolov Can we close this issue? Thanks
Thanks @Bartlomiejsz , @konarshankar07 ! Closing the issue according to the comment above.
Steps to reproduce
<block class="Magento\Reports\Block\Product\Widget\Viewed" page_size="4" name="recently_viewed" template="widget/viewed/content/viewed_grid.phtml" cacheable="false" />
to catalog_product_view.xml in any containerExpected result: With enabled cache you should see recently viewed products block in product page.
Actual result: Block is visible only with disabled cache, when cache is enabled, it does not have output.