0

Is it possible to call out the related products on category pages? So within each product in the grid, it would also display the full list of that product's related products.

Related products on category

0

Please try below code on your phtml file.

$product_id = '1';
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);

$relatedProducts = $product->getRelatedProducts();

//var_dump($relatedProducts);

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>";
    }
}  

| improve this answer | |
  • This is not a complete solution - it lists products related to another product - not to the category like in the question – sparrow 16 hours ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.