title: Get sample URL for downloadable product in Magento
body: <p>I'm trying to get sample file url for a downloadable product in my cross sell block on a product page.</p>
  
  <p>The contents of my crosssell.phtml</p>
  
  <pre><code>&lt;?php $_helper = $this-&gt;helper('catalog/output'); ?&gt;
  &lt;?php $_product = $this-&gt;getProduct(); ?&gt;
  
      &lt;?php if($_crossSellProducts = $_product-&gt;getCrossSellProducts()): ?&gt;
  
      &lt;div id="music-crosssell-modal" style="display:none;"&gt;
          &lt;div class="modal-inner"&gt;
          &lt;span id="music-crosssell-header"&gt;Featured Music&lt;/span&gt;
  
      &lt;ul id="music-crosssell-products-list"&gt;
      &lt;?php foreach ($_crossSellProducts as $_item): ?&gt;
  
          &lt;?php $_item = Mage::getModel('catalog/product')-&gt;load($_item-&gt;getId()); ?&gt;
  
          &lt;li class="music-item paused" id="&lt;?php echo urlencode($this-&gt;htmlEscape($_item-&gt;getSongTitle())) ?&gt;"&gt;
                  &lt;span class="player"&gt;Loading...&lt;/span&gt;
                  &lt;span class="track-title"&gt;&lt;?php echo $this-&gt;htmlEscape($_item-&gt;getSongTitle()) ?&gt; by &lt;/span&gt; &lt;span class="music-track-artist"&gt;&lt;?php echo $this-&gt;htmlEscape($_item-&gt;getMusicianName()) ?&gt;&lt;/span&gt;
                  &lt;button type="button" title="&lt;?php echo $this-&gt;__('Buy Now') ?&gt;" class="button btn-primary" onclick="setLocation('&lt;?php echo $this-&gt;getAddToCartUrl($_item) ?&gt;')"&gt;
                      &lt;?php echo $this-&gt;__('Buy Now') ?&gt;
                  &lt;/button&gt;
          &lt;/li&gt;
  
          &lt;?php
          $_myprodsamples = Mage::getModel('downloadable/sample');
          $_mySampleCollection = $_myprodsamples-&gt;getCollection()
          -&gt;addProductToFilter($_item-&gt;getId());
          ?&gt;
  
          &lt;?php
          foreach ($_mySampleCollection as $_sample):
              $_samplelink = $this-&gt;getUrl('downloadable/download/sample/sample_id/'.$_sample-&gt;getId());
          ?&gt;
  
          &lt;?php echo Mage::getModel('downloadable/sample')-&gt;load($_samplelink)-&gt;getUrl() ?&gt;
  
          &lt;script type="text/javascript"&gt;
              jwplayer("#&lt;?php echo urlencode($this-&gt;htmlEscape($_item-&gt;getSongTitle())) ?&gt; .player").setup({
                  flashplayer: "/skin/frontend/default/datura/js/jwplayer/player.swf') ?&gt;",
                  file: "&lt;?php echo Mage::getModel('downloadable/sample')-&gt;load($sampleId)-&gt;getUrl() ?&gt;",
                  height: 25,
                  width: 25,
                  controlbar: "bottom"
              });
          &lt;/script&gt;
  
  
          &lt;?php
              endforeach;
          ?&gt;
  
  
  
          &lt;script type="text/javascript"&gt;
              jwplayer("#&lt;?php echo urlencode($this-&gt;htmlEscape($_item-&gt;getSongTitle())) ?&gt;").setup({
              flashplayer: "/skin/frontend/default/datura/js/jwplayer/player.swf') ?&gt;",
              file: "",
              height: 25,
              width: 300,
              controlbar: "bottom"
              });
          &lt;/script&gt;
  
  
  
      &lt;?php endforeach; ?&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
      &lt;span id="music-crosssell-close-btn" class="close-modal-btn"&gt;X&lt;/span&gt;
  &lt;/div&gt;
  
  &lt;?php endif; ?&gt;
  </code></pre>