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?

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

1 Answer 1

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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