In my Magento store I have added downloadable products and if user want to download this product user need to subscribe our newsletter. for that I have added newsletter subscriber block in view.phtml file.code is below.

<?php $download = Mage::registry('current_product')->getTypeId();?>
            if($download == 'downloadable')
            { ?>

            <div class="pop-upss">
                <input type="button" onclick="showMrnlePopup();" value="To Download This Product You Need To Subscribe Our Newsletter" name="submit"/>
        <?php }     ?>

so I have set onclick function and when user will click on this button newsletter pop-up will open.

in newsletter PHTML file I get current product's id using below code

<input type="hidden" name="pro_id" value="<?php echo Mage::registry('current_product')->getId();?>">

ok now we go to SubscriberController.php file and it's newAction(). I get current product id in newAction() using below code.

public function newAction()

$product_id = $this->getRequest()->getPost('pro_id');

if($product_id) {
    /** @var Mage_Catalog_Model_Product $product */
    $product = Mage::getModel('catalog/product')->load($product_id);

    if($product->getTypeId() == 'downloadable') {
        /** @var Mage_Downloadable_Model_Resource_Sample_Collection $samples */
        $samples = Mage::getModel('downloadable/sample')->getCollection()->addProductToFilter($product_id);

        if($samples->count() > 0) {
            foreach($samples as $sample) {
                /** @var Mage_Downloadable_Model_Sample $sample */
                $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'downloadable/files/samples' . $sample->getSampleFile();
                echo 'Sample URL: ' . $url . "<br>";

        /** @var Mage_Downloadable_Model_Resource_Link_Collection $links */
        $links = Mage::getModel('downloadable/link')->getCollection()->addProductToFilter($product);

        if($links->count() > 0) {
            foreach($links as $link) {
                /** @var Mage_Downloadable_Model_Link $link */
                $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'downloadable/files/links' . $link->getLinkFile();
                echo 'Link URL: ' . $url;

Now what I want is below :

using newAction 's above code I am getting downloadable product's sample link in console and when I enter this link in url it's redirect to home page so this is my first problem.

when this action is called I want to download product's sample link automatically for that what I need to change or add code in SubscriberController 's code


  • I think link is not Sharable. Try set Shareable to Yes at System > Configuration > Catalog > Downloadable Product Options – Anil Suthar May 21 '16 at 7:04
  • @AnilSuthar I have checked shareable option and it's already set to yes and other suggetion? – Dhaval May 21 '16 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.