The most successful Ecommerce stores never fail to provide best user experience to their customers by any means. One of the most important aspect of it is to minify pageloads and avail customers with smoother navigation. This idea can be used in many cases. Let’s take an example of a category with single product. Redirecting customers to the category page and then to perform repeated click only to move to the product page may be useless in majority of situation. (It’s useful when a category describes some important information before visiting product page.) This illustration creates a need of finding the solution to redirect customers directly on product page in order to provide better navigation.

Let’s take a look at how we can achieve this in Magento 2. This requires developing a custom extension with the below code.

  1. As stated above, you need to create a small custom extension and modify the block’s method behavior for getting products collection.
    Create etc/di.xml in your extension with the following code:

2. then create the plugin class Block/Catalog/Product/ListProduct.php with the code below:

Clear the Magento default or other cache you are using.

You can also install the extension to implement the above functionality directly to your Magento store.

This extension is prepared using the code of  Yaroslav Rogoza done on this GitHub Repo. We are thankful to him for this.
Leave comment if you face any trouble with it.
Happy Coding.

Click to rate this post!
[Total: 8 Average: 4]