Skip to main content
2 of 2
added 303 characters in body
Asad Khan
  • 1.5k
  • 12
  • 38

How to get Recently Viewed Product Widget without using widget or static block. Magento 2.3.1

I want to get the Recently Viewed Products without using Widget or static Block I tried this

namespace PME\Hideprice\Block;

class getTestingData extends \Magento\Framework\View\Element\Template
{
    protected $recentlyViewed;

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Reports\Block\Product\Viewed $recentlyViewed,
        array $data = []
    ) {
        $this->recentlyViewed = $recentlyViewed;
        parent::__construct( $context, $data );
    }

    public function testing(){
        return $this->recentlyViewed->getItemsCollection()->getData();
        //return "Asad Khan";
    }
}

I also tried

<?php echo $this->getLayout()->createBlock("Magento\Reports\Block\Product\Widget\Viewed")->setDisplayType("recently.view.products")->setProductsCount("5")->setTemplate("widget/viewed/content/viewed_list.phtml")->toHtml(); ?>

but both of these does not return me anything

but these classes does not return me anything. How to get all the recently viewed product?

Asad Khan
  • 1.5k
  • 12
  • 38