How to Get All Downloadable Links Details from the Downloadable Product Programmatically in Magento 2

 Steps to Get All Downloadable Links Details from the Downloadable Product Programmatically in Magento 2:

Step 1:  We are getting data in the root script.


Path of file: magento_root_directory\pub\downloadablelink.php


Add below code snippet


<?php

ini_set('display_errors', 1);

ini_set('display_startup_errors', 1);

ini_set('memory_limit', '5G');

error_reporting(E_ALL);

 

use Magento\Framework\App\Bootstrap;

use Magento\Store\Model\ScopeInterface;

 

require '../app/bootstrap.php';

echo "start";

$bootstrap = Bootstrap::create(BP, $_SERVER);

 

$objectManager = $bootstrap->getObjectManager();

$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');

$connection = $resource->getConnection();

$state = $objectManager->get('Magento\Framework\App\State');

$state->setAreaCode('frontend');

    

$sku = 'Downloadable'; //Downloadable item sku

 

$downloadableProductLink = $objectManager->get('Magento\Downloadable\Api\LinkRepositoryInterface');

$downloadableLinkdetails = $downloadableProductLink->getList($sku);

 

foreach ($downloadableLinkdetails as $link)

{

     echo "<pre>";

     print_r($link->getData());

     echo "<pre>";

}

Output:


Magento 2 Downloadable Links Details

Comments

Popular posts from this blog

Add Admin User name and Action name in Order Comment Section through Action Performed from Sales Order Grid in Magento 2

How to Update Product Stock Programmatically in Magento 2

How to Set and Get Cookie in Magento 2