How To

Magento 2: Show Related Products On The List Page

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.

Click to rate this post!
[Total: 1 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

Five Essential Payroll Compliance Tips for eCommerce Startups

Are you setting up a payroll system for your eCommerce startup? Ensuring compliance with myriad…

6 hours ago

Optimizing Laravel Blade: Unlocking Advanced Fetcher Techniques

In the expansive universe of Laravel development, Blade serves as the stellar templating engine, propelling…

7 hours ago

Magento 2: Add Quantity Increment and Decrement on Category Page

Hello Magento Friends, In this blog, we will discuss about adding quantity increment and decrement…

2 days ago

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

5 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

1 week ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

1 week ago