protected $recentlyViewed;
public function __construct( ... \Magento\Reports\Block\Product\Viewed $recentlyViewed ) { ... $this->recentlyViewed = $recentlyViewed; }
/**
- Get recently viewed products for the customer
*/ public function getMostRecentlyViewed(){
protected $recentlyViewed;
public function __construct(
...
\Magento\Reports\Block\Product\Viewed $recentlyViewed
) {
...
$this->recentlyViewed = $recentlyViewed;
}
/**
* Get recently viewed products for the customer
*
*/
public function getMostRecentlyViewed(){
return $this->recentlyViewed->getItemsCollection();
}
}
This code is working and it'll return according to customer session.
If you disabled Full Page cache then it'll display recently viewed prdocuts.
You need to set cacheable="false" for custom block. Please let me know if you still face same issue.