I have a product with downloadable PDFs. I recently updated the PDF with a new version. The problem is that customers who bought the old version continue download the old PDF.

How can I get all old customer orders to download the updated PDF?

1 Answer 1


I place the following code into a .php script in the Magento root. You can call it via the CRON or your web browser.



    $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($conn = 'core_read') {
        return Mage::getSingleton('core/resource')->getConnection($conn);

    function getTable($table) {
        return Mage::getSingleton('core/resource')->getTableName($table);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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