Magento 2: Show Related Products On The List Page

How to Show Related products in product list page in Magento 2

Hello Magento Folks,

How are you progressing? Today I am here to explain to you all how to show related products on the List page of your Magento 2 store. Don’t forget to visit the previously published How to Display Extra Product Attributes In the Checkout Summary In Magento 2 article of the How-To Series.  

Introduction:

Basically, the word Related itself describes the meaning of the product. Related product features will enhance your store by increasing the sales of the products. If any customer is going through one product then all the products related to that which are added to the related product list is displayed. It means if you are shopping at the Hair Comb then the Hair oil or Different types of Hair Combs are displayed to improve the sales ratio of the store. So, when there is a requirement of displaying related products which are on the list page of that product you have to just implement the given below solution.

Let’s Implement Code:

Step 1: Override the list file and then just add this file in your extension.

app/code/VENDOR/EXTENSION/view/frontend/template/catalog/product/view.phtml




$relatedProducts = $product->getRelatedProducts();

if (!empty($relatedProducts)) {

    echo 'Related Products <br />';   

    foreach ($relatedProducts as $relatedProduct) {

        $_product = $objectManager->create('Magento\Catalog\Model\Product')->load($relatedProduct->getId());

        echo $relatedProduct->getId().'<br/>';

        echo $_product->getPrice().'<br/>';

        echo $_product->getName().'<br/>';

        echo $relatedProduct->getId(); //get name

        echo "<br>";

    }

}

Step 2: Add your list of products with related products list and that’s it the related products will display.

Conclusion

Hence, by implementing the given above steps you will be capable to display the related products to the customer visiting any specific product that will be more helpful in increasing the growth and customer experience of your store. So this was it for the day I hope it helps you.

Don’t forget to comment down your valuable reviews for the article and if the article seems to be helpful then share with your Magento pals and improve their knowledge. And there is any sort of issue in applying the above-given steps then don’t hesitate to reach us at MageComp Support. Till then be all that you can be.

Happy Coding.

Previous Article

Removing Customer Account Navigation Links in Magento 2: A Step-by-Step Guide

Next Article

7 Reasons Why Online Reviews Are Important For Your Ecommerce Business

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Get Connect With Us

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨