Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Creating a Magento CMS page to download Product’s PDF files for logged in users only
 
josuito
Jr. Member
 
Total Posts:  2
Joined:  2011-12-12
 

I create a page that only users can download a pdf file for products that they had bought and completed transactions.

1- I create a page in CMS in my admin panel and add the following code in in the content section then save it (don’t try to preview it, there’s nothing inside yet):

{{block type="core/template" template="customphp/download-pdfs.phtml"}}

2- I went to my cpanel (file manager) then a create a directory called “customphp”, then I created a file inside this directory called “download-pdfs.phtml” in this path app/design/frontend/default/your-theme/template/ and added the following code. I know there’s better ways to do it but Im not an expert.

<?php

Mage
::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

if(
Mage::getSingleton('customer/session')->isLoggedIn()){
    $customerData 
Mage::getSingleton('customer/session')->getCustomer();
    
$cid $customerData->getId();


$orderCollection Mage::getModel('sales/order')->getCollection()
    ->
addFieldToFilter('customer_id', array('eq' => array($cid)));    



     echo 
"<b>Please click in your product's download link. NOTE: Only completed/Pending/Processing orders will have a download link. (ID.CSC$cid)</b>";
     echo 
"<table class=\"none\" border=\"1\"> 
     <tr bgcolor=\"
#1f1f1f\">
     
<th><center><b>Order ID</b></th
     <
th><center><b>Product Name</b></th>  
     <
th><center><b>Product SKU</b></th>
     <
th><center><b>Category Name</b></th>
     <
th><center><b>Qty</b></th
     <
th><center><b>Status</b></th
     <
th><center><b>Created</b></th
     <
th><center><b>Download Link</b></center></th
     </
tr>";
     echo "
<ol class=\"products-list\" id=\"products-list\">";

foreach(
$orderCollection AS $order_row){
        Mage::log(
$order_row->getData());

$order = Mage::getModel('sales/order')->loadByIncrementId($order_row['increment_id']);
// get order total value
$orderValue = number_format ($order->getGrandTotal(), 2, '.' , $thousands_sep = '');
// get order item collection
$orderItems = $order->getItemsCollection();

 
foreach (
$orderItems as $item){
 
    
$product_id = $item->product_id;
    
$product_sku = $item->sku;
    
$product_name = $item->getName();
    
$_product = Mage::getModel('catalog/product')->load($product_id);
    
$product_pdfpath = $_product->getResource()->getAttribute('pdfpath')->getFrontend()->getValue($_product);
    
$cats = $_product->getCategoryIds();
    
$category_id = $cats[0]; // just grab the first id
    
$category = Mage::getModel('catalog/category')->load($category_id);
    
$category_name = $category->getName();

         
$encryptedData = Mage::helper('core')->encrypt($product_pdfpath);
         
$formatted = number_format($order_row['total_qty_ordered'], 0, '.', ' ');
         echo "
<tr>";
         echo "
<td><center>".$order_row['increment_id']."</center></td>";

 
    echo "
<td><center>".$product_name."</center></td>";
    echo "
<td><center>".$product_sku."</center></td>";
    echo "
<td><center>".$category_name."</center></td>";
 
 
             echo "
<td><center>".$formatted."</td>"; 
             echo "
<td><center>".$order_row['status']."</center></td>"; 
             echo "
<td><center>".$order_row['created_at']."</center></td>";

     if(
$order_row['status']=='canceled'){ 
             echo "
<td><center>Buy It</center></td>";
     }
     else {
             echo "
<td><center> <a target=\"_blank\" href=\"[removed]if(confirm('The PDF DWG will open in other page.')) [removed]='http://www.yourwebsite.com//product-pdfs/".$product_pdfpath."'; \"  download><b>Download</b></a></center></td>"; 
     }
 
         echo "
</tr>";
}
}
  echo "
</ol></table>";

}
else{
    
    echo "
<b>You have to be an active user and purchased a product for you to download the product spec sheetPlease <a href=\"/customer/account/login/\"><font style=\"color:white;text-decoration:underline;font-style:italic;\">login in</font></afirst and then come back to this page.</b>";  
}

?>

3- Still in cpanel (file manager) create a directory where your pdf files will go, in this case was “product-pdfs” and then create a file inside here called “index.html” for security reasons. Then go ahead and upload all your pdf files here, try to name your files in simple way so you can remember starting with the SKU + phrase + date.

4- Then in your magento admin go ahead and open any product for editing, in your top right click the button “create new attribute” in the attribute code write this “pdfpath” remember that you don’t need this in the search, or visible in frontend, pretty much all the properties will be “no”, for the label admin name try “PDF Path” the save it.

5- Now on any product you will have this attribute, if you have a pdf file for that product go ahead and type it in, “REMEMBER” write down exactly as how was upload it to the server, like “this-is-my-pdf-file-name.pdf” this system will automatically get this attribute and put in your download link.

6- Now go to your CMS page that you created for this block from your magento admin and click preview.

7- Link your page in your website adding it to your footer block or your navigation bar.

Hope this helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
arronlee
Jr. Member
 
Total Posts:  11
Joined:  2013-05-02
 

Hi, josuito.
Thanks for the nice sharing. I wonder whether the
PDF manipulator I am testing about these days can also deal with it. And I want to look for a fine professional 3rd party PDF processor whose way of processing is simple and fast to help me with the related work. It will be better if it is totally manual and can be customized by users according to our own favors. Do you have any ideas about it? Or any good suggestion? Thanks in advance.



Best regards,
Arron

 
Magento Community Magento Community
Magento Community
Magento Community
 
makarovsoft
Jr. Member
 
Avatar
Total Posts:  27
Joined:  2013-12-15
 

If someone is looking for extension that allows to download product files for logged in users only, you may consider Product Files extension.

As a bonus it allows:
- put list of files attached to specific product as block on any cms or static page
- allow downloads or url opens not only to registered customers, but also only to customers from specific group

Get your copy of Product Files magento extension

Image Attachments
custom-placement[1].png
 
Magento Community Magento Community
Magento Community
Magento Community
 
FMEExtensions
Mentor
 
Avatar
Total Posts:  1298
Joined:  2009-08-07
 

Following is a paid Magento Extension that allows you to upload files on CMS pages easily, an easy to use module allows you to manage everything from backend. 

FME Magento CMS Pages Extension

Here are some benefits:

- Get products added to cart from CMS pages.
- Get more clicks and conversions by utilizing CMS Product Pages
- Supports all products, “Search CMS pages” functionality included
- Expose those products which normally would not get much attention.
- Create and set unlimited shopping cart rules. Products will be displayed on CMS pages based on these rules
Apply Cart Rules on multiple categories

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top