1

Please read description carefully before marking it as duplicate

I want to get recently viewed product collection from Model instead of Block

I have check similar post but no one answered it correctly How to get recently viewed product collection in magento2?

  • do you need this for admin or frontend? And for login customer? – Dhiren Vasoya May 15 at 10:11
  • I need it on frontend for all customers combined list of recently viewed products – Shoaib Munir May 15 at 10:13
  • But generally Magento show current customer recently view products. – Dhiren Vasoya May 15 at 10:14
  • Yes, but is it possible that I can get all recently viewed combined data? – Shoaib Munir May 15 at 10:16
0

Got the solution of this

In my Class

public function __construct(
    ...
    \Magento\Reports\Model\Product\Index\Viewed $recentlyViewedModel,
    ...
)
{
    ...
    $this->recentlyViewedModel = $recentlyViewedModel;
    ...
}

public function getRecentlyViewedCollection()
{
    $collection = $this->recentlyViewedModel->getCollection();
    $collection->setPageSize(20)
        ->setCurPage(1);

    return $collection->load();
}

It is working fine and I am getting whole customers combined recently viewed products collection from Model.

  • this is not working for me... i am getting All products.. – Waqar Ali Jun 12 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.