How To

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

Hello Magento Friends,

In the current tutorial blog, I will explain How to Get All Downloadable Links Details from the Downloadable Product Programmatically in Magento 2.

Downloadable products include e-books, music, video, software, file and more. Customers can download or purchase downloadable products from the product details page. With Magento 2, you can create downloadable products for your store.

The Downloadable Products link details are stored in the database table with information like product_id, download link file, download link URL, number of downloads, link type, etc. To retrieve all downloadable links details from the Downloadable Product in Magento 2, check out the below steps.

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:

Conclusion:

Accordingly, you can Get All Downloadable Links Details from the Downloadable Product Programmatically in Magento 2. If you have difficulty in the above steps, kindly share them with me through the comment box. Stay abreast for more Magento solutions.

Happy Coding!

Click to rate this post!
[Total: 2 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

Generating Thumbnails with Spatie Media Library in Laravel 11: A Step-by-Step Guide

Generating image thumbnails is a common requirement in web applications, especially when handling media-heavy content.…

6 hours ago

Enhancing Web Application Security with Laravel’s Built-In Features

In today’s digital landscape, web application security is paramount. As a powerful PHP framework, Laravel…

1 day ago

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

October was an exciting month for MageComp! From significant updates across our Magento 2 extension…

1 day ago

Improving Error Handling and Transition Management in Remix with useRouteError and useViewTransitionState

In modern web development, seamless navigation and state management are crucial for delivering a smooth…

1 week ago

Magento Open Source 2.4.8-Beta Release Notes

Magento Open Source 2.4.8 beta version released on October  8, 2024. The latest release of…

1 week ago

How to Create Catalog Price Rule in Magento 2 Programmatically?

Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…

1 week ago