Monday 27 June 2011

Download link in product list page to download downloadable product in magento


Download link in list page to download downloadable product direct :

<?php
$_myprodlinks = Mage::getModel('downloadable/link');
$_myLinksCollection = $_myprodlinks->getCollection()->addProductToFilter($_product->getId());
if (sizeof($_myLinksCollection)>0):
foreach ($_myLinksCollection as $_link):
$mediaUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
$_linkpath = $mediaUrl."downloadable/files/links".$_link->getLinkFile();
?>
    <a href="<?php echo $_linkpath ?>" target="_blank"><?php echo $this->__('Download') ?></a>
<?php
 endforeach;
endif;
?>
put this code in list.phtm (app/design/frontend/yourtheme/yourtheme/template/catalog/product) page where you want to 'Download' link.
Please make sure that your media dir have 777 permision

10 comments:

  1. Oh man! You are the best!!!! Thankssss!

    ReplyDelete
  2. O bapu..! What a blog.. I've bcum a fan of urs..

    ReplyDelete
  3. it's work but in my site download is not working can you please tell me what is the problem.

    when i click on the link it's redirect on "http://bandwidthmusic.com/index.php/media/downloadable/files/links/l/i/lightbox-gallery.0.6.5.zip" path but zip is not download and home page open.

    ReplyDelete
    Replies
    1. Please check media folder and download folder file permision its 777,or do one thing rename .htaccess file in media folder and download folder may its work

      Delete
  4. Where exactly should I put this inside the file? I pasted it and got erroe? should I replace the entire code?

    ReplyDelete
    Replies
    1. You should put this code in app/design/frontend/yourtheme/yourtheme/template/catalog/product/list.phtml file in any where you want to show link.. what error you got ? i tested it there is no any error.. its work fine..post you error so i can check it

      Delete
  5. Sorry I think I got it wrong. I am looking for code that will disable the automatic URL magento creats for downloadable product and will send the customer the original URL is this code supose to solve it?

    ReplyDelete
  6. Hai when i click on the download link i got 403 forbidden in server

    ReplyDelete
    Replies
    1. Go to media folder the open downloadable folder and open the .htaccess file there change the Deny from all to Allow from all. Save the file now the file links works

      Delete
  7. Good job but not a perfect way. User can download product directly but we can track the information about the downloads using this.

    ReplyDelete