Вопрос

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

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top