cancel
Showing results for 
Search instead for 
Did you mean: 

How to get product links

How to get product links

I am trying to fetch the product links for a product (related, cross sell, up sell), but all return as null or zero. Even though, the product links are shown on the admin UI.

 

1: Use ProductLinkRepositoryInterface

    $prdRepo = $this->objectManager->create('Magento\Catalog\Api\ProductLinkRepositoryInterface');
    if ($prdRepo) {
        $links = $prdRepo->getList($product);
        //This output as 0
        echo 'links='; echo count($links); echo PHP_EOL;
    }

2: Use ProductInterface, getProductLinks() method

$productLinks = $product->getProductLinks();

These two ways return 0. I am not sure if it is the correct way to fetch the product links.

1 REPLY 1

Re: How to get product links

@Rakesh Jesadiya Thanks for the reply

 

I want to get all product links (related, upsell and crosssell) by a product ID programmatically.

 

I hope my reply clearer. Smiley Happy

 

 

2017-08-24_16-13-43.png