The following piece of code is supposed to get the download link only for downloadable products with uploaded samples at the Magento backend.

if($_product->getTypeId() == 'downloadable') {
    /** @var Mage_Downloadable_Model_Resource_Sample_Collection $samples */
    $samples = Mage::getModel('downloadable/sample')->getCollection()->addProductToFilter($product_id);
    if ($samples) {
        $_myprodsamples = Mage::getModel('downloadable/link');
        $_mySampleCollection = $_myprodsamples->getCollection()->addProductToFilter($_product->getId());
        foreach ($_mySampleCollection as $_sample){
            $_samplelink = $this->getUrl('downloadable/download/linkSample/link_id/'.$_sample ->getId());

<?php if($_samplelink): ?>
  <a href="<?php echo $_samplelink ?>" class="button btn-cart piwik_download" target="_blank">Downnload</a>
<?php else: ?>

However, all downloadable products are showing the download links, and this should only happen for downloadable products with uploaded samples at the backend.

Has anybody an idea of what is still going wrong?

1 Answer 1


This made the trick:

$samples = Mage::getSingleton('downloadable/sample')->getSearchableData($_product->getId(), $_product->getStoreId());

Maybe useful for other people

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.