Best Way to Update Downloadable Product Attachment For Placed Orders in Magento
Empower customers to upload files with orders!
Add multiple file formats like images, PDFs, word documents to your orders using Magento 2 Order attachment.
Magento CMS is a popular platform used not only by the online stores offering physical items but also downloadable products such as software, extensions, etc.
We know that with each day, software that you offer needs to be updated with new features, bug fixes, etc. And it is a continuous process. Else, you can’t stand in the IT market.
And it is necessary that all the customers, be it for already existing orders or the new customers, get the updated software file.
Also, even if you sell some physical items with a manual or any such product attachment that the customer can download, there are chances that you will update that attachment. The customer needs to get that updated attachment irrespective of the time of the purchase.
However, the default Magento does not facilitate such a process automatically. Hence, I’ve come up with a solution to update downloadable product attachment for placed orders in Magento.
Once you update the software package or any file that is offered to the customer as an order attachment, the customers will be able to access that updated version automatically with this solution!
Method to Update New Downloadable Product Attachment For Placed Orders In Magento:
Create updateDownloadLink.php at root directory
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<?php require('app/Mage.php'); umask(0); Mage::app(); $select = getDb()->select() ->from(getTable('downloadable/link'), array('link_id', 'link_file', 'product_id')); if (($links = getDb()->fetchAll($select)) !== false) { foreach ($links as $link) { try { $linkId = $link['link_id']; $productId = $link['product_id']; $file = $link['link_file']; $select = getDb()->select() ->from(getTable('downloadable/link_title'), 'title') ->where('link_id=?', $linkId) ->limit(1); $title = getDb()->fetchOne($select); $linkPurchasedItems = Mage::getModel('downloadable/link_purchased_item')->getCollection() ->addFieldToFilter('product_id', $productId) ->addFieldToFilter('link_id', $linkId) ->load(); foreach ($linkPurchasedItems as $linkPurchasedItem) { $itm = Mage::getModel('downloadable/link_purchased_item')->load($linkPurchasedItem->getId()); $itm->setlink_title($title) ->setlink_file($file) ->setlink_id($linkId) ->save(); echo '<pre>'; print_r($itm->getData()); echo '</pre>'; } } catch (Exception $e) { print_r($e->getMessage()); } } } function getDb($conn = 'core_read') { return Mage::getSingleton('core/resource')->getConnection($conn); } function getTable($table) { return Mage::getSingleton('core/resource')->getTableName($table); } |
That’s it!
Never leave a chance for customers to complain about a bug fix anymore!
Improve the customer experience by offering timely latest features without any hassle.
Use the Comments section below in case of any doubts about the topic or solution.
I’d be glad to help you out.
Feel free to share the post with fellow developers via social media.
Thanks.
Let the customers upload files when placing the order in your store and collect additional information about the order.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
2 Comments
WIll This work with magento 2.3?
Hello Ryan,
It will not work with Magento 2.3.
Thank You.