How to programmatically get the most viewed products for a particular category?

Can we get Most viewed products from this ?

I added
\Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory $collectionFactory,
\Magento\Reports\Model\ResourceModel\Product\CollectionFactory $productsFactory,

but can’t get it.

i want to show Mostviewed Not bestseller Products.

Use the \Magento\Reports\Model\ResourceModel\Report\Product\Viewed\Collection class as an example.
You should add a category filter to it.

1 Like