I have tried this but it is not working. I am getting blank array. Suggestions please, i am stuck.
I want to display recently viewed product in owl carousel. But getting no products.
protected $recentlyViewed;
public function __construct(\Magento\Reports\Block\Product\Viewed $recentlyViewed ) {
$this->recentlyViewed = $recentlyViewed;
}
public function execute() {
$collection = $this->recentlyViewed->getItemsCollection()->load();
echo "<pre>";
print_r($collection->getData());
exit;
}
I also tried this, but still blank array.
protected $_viewProductsBlock;
public function __construct(\Magento\Reports\Block\Product\Widget\Viewed\Proxy $viewedProductsBlock) {
$this->_viewProductsBlock = $viewedProductsBlock;
}
public function execute() {
$_collection = $this->_viewProductsBlock->getItemsCollection();
echo "<pre>";
print_r($_collection->getData());
echo "</pre>";
die;
}