Domanda

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?

È stato utile?

Soluzione

This made the trick:

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

Maybe useful for other people

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top