1

I am working on the downloadable products.i want my preview file on the frontend should play and customers should able to download the products from their account from my downloadable products.

I know their is one configuration given by magento. Under Sys > Config > catalog > Downladable Information. use content disposition to inline both preview and products from my account will play.

and if i use content disposition as attachement then then preview file and products from my account downlad as attachment

Now actually i want preview to be played (inline) and products from my account should be downladed (attachment)

1

After Some Debug in the core file i found the solution to my problem and i am sharing my answer.

I had to override function in controller to achieve this task.for this i had created one module which overrides Mage_Downloadable's Download Controller.

Step 1: Create YourPackageName_Downloadable.xml under app/etc/modules/

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <modules>
        <YourPackageName_Downloadable>
            <active>true</active>
            <codePool>local</codePool>
        </YourPackageName_Downloadable>
    </modules>
</config>

Step 2. Create config.xml file in app/code/local/YourPackageName/Downloadable/etc/.

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <modules>
        <YourPackageName_Downloadable>
            <version>0.0.1</version>
        </YourPackageName_Downloadable>
    </modules>
    <frontend>
        <routers>
            <downloadable>
                <args>
                    <modules>
                        <yourpackagename_downloadable before="Mage_Downloadable">YourPackageName_Downloadable</yourpackagename_downloadable>
                    </modules>
                </args>
            </downloadable>
        </routers>
    </frontend>
</config>

Step 3: Create DownloadController.php in app/code/local/YourPackageName/Downloadable/controllers/

<?php
    require_once("Mage/Downloadable/controllers/DownloadController.php");
    class YourPackageName_Downloadable_DownloadController extends Mage_Downloadable_DownloadController{

        protected function _processDownload($resource, $resourceType)
        {
            $helper = Mage::helper('downloadable/download');
            /* @var $helper Mage_Downloadable_Helper_Download */

            $helper->setResource($resource, $resourceType);

            $fileName       = $helper->getFilename();
            $contentType    = $helper->getContentType();

            $this->getResponse()
                ->setHttpResponseCode(200)
                ->setHeader('Pragma', 'public', true)
                ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
                ->setHeader('Content-type', $contentType, true);

            if ($fileSize = $helper->getFilesize()) {
                $this->getResponse()
                    ->setHeader('Content-Length', $fileSize);
            }

            // custom change in core code strats here
            $actionName = Mage::app()->getRequest()->getActionName();
            if($actionName == "sample"){
                $this->getResponse()
                    ->setHeader('Content-Disposition', 'inline' . '; filename='.$fileName);
            }else{
                if ($contentDisposition = $helper->getContentDisposition()) {
                $this->getResponse()
                    ->setHeader('Content-Disposition', $contentDisposition . '; filename='.$fileName);
                }
            }
            // custom change in core code ends here

            $this->getResponse()
                ->clearBody();
            $this->getResponse()
                ->sendHeaders();

            session_write_close();
            $helper->output();
        }   
    }
?>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.