I want to display recently viewed products on product detail page in Magento 2. I am using Magento ver. 2.1.2. Please assist me how to display it. Thanks
In Magento 2 display recently viewed product on product detail page
7.2k views Asked by Jignesh Patel At
3
There are 3 answers
1
On
\Magento\Reports\Model\ResourceModel\Product\CollectionFactory
$_reportCollectionFactory
$this->_reportCollectionFactory = $_reportCollectionFactory;
$collection = $this->_reportCollectionFactory->create()
->addAttributeToSelect('*')
->addViewsCount()
->setStoreId($storeId)
->addStoreFilter($storeId)
->setPageSize(10);
1
On
We should not set cacheable="false"
. This will greatly impact the performance. The whole page will be uncacheable.
1) 2.1.x: seems that it's a Magento bug with FPC and Varnish: https://github.com/magento/magento2/issues/3890. In this case, I used Ajax.
2) 2.2.x or later: using UI component: https://magento.stackexchange.com/a/209658/33057
in your
catalog_product_view.xml
file add below block in