0

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?

0

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

<?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) {
            $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);

            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, privacy policy and cookie policy

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