I am not really sure if this is a bug in Magento or I am missing something. Every time I change the file (Add a new file) to a downloadable product in the Admin end, the file does not update for the customers who already bought it and have it in their download list.

I found This solution for Magento 1.7, I tried it in Magento 2.2 but it did not work. Is there an alternative for Magento 2 as well that anybody is aware of?

Please let me know if there is an obvious way of fixing this and I am missing it, thank you!


use \Magento\Framework\App\Bootstrap;

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');

$select = getDb()->select()
    ->from(getTable('downloadable_link'), array('link_id', 'link_file', 'product_id'));

if (($links = getDb()->fetchAll($select)) !== false) {
    foreach ($links as $link) {
        $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)

        $title = getDb()->fetchOne($select);

        echo sprintf("Updating %s to %s<br />", $file, $title);

        $cond = getDb()->quoteInto('product_id=?', $productId);

        getDb()->update(getTable('downloadable_link_purchased_item'), array('link_id' => $linkId, 'link_title' => $title, 'link_file' => $file), $cond);

function getDb()
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
    return $connection = $resource->getConnection();;

function getTable($table)
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
    return $tableName = $resource->getTableName($table);

Try this. It should work.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.