Wednesday, April 10, 2013

Magento how to show pdf that shows blank?

Go to app\code\local\CompanyNameorWhatever\Mycatalog\controllers\Frontend\Catalog\ProductController or wherever this is located. You can also use Sublime Text to search the directory for function downloadAction(). In this file, check this
$id = Mage::app()->getRequest()->getParam("id");
        $name = explode("+", Mage::getModel('catalog/product')->load($id

        )->getName());
        $_product = strtoupper(trim($name[0]));
        $resource = Mage::getBaseDir().DS."media".DS."catalog".DS."product"

.DS."pdfs".DS.$_product.".pdf";

Note that this is very specific and might help you. The key code that I had to use was
Mage::app()->getRequest()->getParam("id");
and Mage::getModel('catalog/product')->load($id)->getName());

The "id" section can be replaced with $fileName= Mage::app()->getRequest()->getParam(\’file\’); and so forth. I got some of the information from http://www.magentocommerce.com/boards/viewthread/276949/#t381584 .

I also had to check a file app\code\local\Mage\Catalog\Block\Product\View\Pdf.php to contain the following

public function getPdfUrl(){
$name = explode(“+”, $this->getProduct()->getName());
$product_pdf = strtoupper(trim($name[0])).”.pdf”;
$product_id = $this->getProduct()->getId();
$file = Mage::getBaseDir().DS.”media”.DS.”catalog”.DS.”product”

.DS.”pdfs”.DS.$product_pdf;
if(file_exists($file)){
$url = Mage::getUrl(“catalog/product/download/id/$product_id”);
return $url;
}
return false;
}
}

No comments:

Post a Comment