Hello Magento Folks,

Welcome to Create Product Programmatically in Magento 2 series where I will help you learn How to Create Downloadable Product Programmatically in Magento 2.

Mainly we can create 6 types of products Programmatically in Magento 2:

Basically downloadable products are the products which the customers will require to download such as eBook, music, video, software application, etc. You can enable your customers to log in and get the link or send the link via email. Eventually when you are creating a massive amount of downloadable products then it is very complicated and becomes time-consuming. Instead of doing this confusing thing you can directly create downloadable products programmatically. Check out the below code.

Steps to Create Downloadable Product Programmatically in Magento 2:

Step 1 : Firstly, create a downloadable_product.php file in the Magento root directory after adding the below code.

Step 2: After the above step run the below URL.

Note*: Magento has added this feature in latest 2.3.3 You have to whitelist the domains of those links through ssh in order to save them. To add a domain you have to run the below command :

php bin/magento downloadable:domains:add www.yourdomain.com

In order to get all whitelisted domains use the below command

php bin/magento downloadable:domains:show

In order to remove a domain from whitelist

php bin/magento downloadable:domains:remove www.yourdomain.com

Wrap Up:

Hopefully, all are able to create Downloadable Product Programmatically in Magento 2  using the code above. If you come across any error during creating Downloadable Product Programmatically then let me know in the comment section below I will help you there. As per the nature of Magento always make sure you clear cache and reindex to display output on the frontend of your Magento 2 store. You can also take the help of our certified Magento Developers. 

Don’t forget to share the tutorial with your Magento Friends via social media channels

Happy Reading!

Click to rate this post!
[Total: 3 Average: 5]