Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Get the Most Viewed Products Collection in Magento 2?

Every online store has its most Viewed or popular products that make the most sales. Store owners can capitalize on these products by bringing them to the limelight. They can get a collection of their most Viewed Products and display them at a noticeable place to draw the user's attention.

The display of your most popular products have many advantages including customer engagement, sales improvement and consistent branding.

In Magento 2, it’s pretty simple to get the most viewed product collection. Following are the steps you can take to do so.

Step 1: Create a Block File

First, you need to create a block file (let’s call it BestSeller.php) in the following path. app\code\Vendor\Extension\Block\BestSeller.php. Add the following code in the file.

_productsFactory = $productsFactory;
 parent::__construct($context, $data);
 }
public function getMostViewedData(){
 
 $mostViewedCollection = $this->_productsFactory->create()->addViewsCount(); 
 return $mostViewedCollection;
 }
}

Step 2: Show Output

Now insert the code shown below in the following phtml file to get product collection from block.

app\code\Vendor\Extension\view\frontend\templates\list.phtml.

getMostViewedData(); ?>
 

Most Viewed Collection.....

  • getSku();?>--getViews();?>

Display Most Viewed Products Using Extension

An alternative to the above method is Magento 2 Product Slider Extension by FMEextensions. It allows you to add multiple sliders to display new, best selling, most viewed, or featured products anywhere on your product, category, and CMS pages. The extension is extremely easy to configure with a lot of useful features.

You get the following features when you opt for the extension.

  • Display more than one sliders
  • Display new products, best selling products, most viewed products, or featured products in each slider
  • Choose to display or hide out of stock products
  • Display sliders on selected products, categories or CMS pages
  • Display slider anywhere on a page or use the shortcode to carry it forward to any other page
  • Choose to display specific product attributes
  • Personalize slider (title, description, number of products to display)

If you have any issue in using Magento 2 then feel free to contact our Support team.

Other Articles You Might be Interested in:

  • How to Cancel a Shipment in Magento 2?
  • How to Enable or Disable Reorder in Magento 2


This post first appeared on Magento Vs PrestaShop Themes–Who Is Best? / Mag, please read the originial post: here

Share the post

How to Get the Most Viewed Products Collection in Magento 2?

×

Subscribe to Magento Vs Prestashop Themes–who Is Best? / Mag

Get updates delivered right to your inbox!

Thank you for your subscription

×