Jump to content

Archived

This topic is now archived and is closed to further replies.

suhy

Add PDF files to product page - easy way

Recommended Posts

I needed a PDF file upload & in admin and show link on the product_info.php, but didn't like the idea of adding numerus lines in categories.php.

 

Assuming that product will always have main image and if another one or more is added the gallery is activated.

 

I used the original image upload and changes are only in product_info.php file (w00t). Mine has some other changes also, so I will just post instructions how to modify it. Should be easy ..

 

# product_info.php

 

1. FIND

 if (tep_not_null($pi['htmlcontent'])) {
            $pi_html[] = '<div id="piGalDiv_' . $pi_counter . '">' . $pi['htmlcontent'] . '</div>';
          }

          echo tep_image(DIR_WS_IMAGES . $pi['image'], '', '', '', 'id="piGalImg_' . $pi_counter . '"');
        }

and modify / change it to:

if (tep_not_null($pi['htmlcontent'])) {
            $pi_html[] = '<div id="piGalDiv_' . $pi_counter . '">' . $pi['htmlcontent'] . '</div>';
          }
		  $ext_info = pathinfo(($pi['image']), PATHINFO_EXTENSION);		
		 
		 if (($ext_info == 'jpg') || ($ext_info == 'png') || ($ext_info == 'gif') )  {

          echo tep_image(DIR_WS_IMAGES . $pi['image'], '', '', '', 'id="piGalImg_' . $pi_counter . '"');
		 }
        }

We look for file extension and show only images in the gallery (jpg, png, gif), you can add other if u want ...

 

2.

Put this code where you want links for PDF's, under the gallery is one option .., just bellow the gallery end </script> around line 158

 

It has to be OUT of piGal <div> as the PDF will not open in lightbox ! It also prevents from including uploaded PDF's for image counting, which is needed for correct image count, excluding uploaded PDF's. In this way we also get the correct image count in gallery lightbox and previous / next buttons work only for images.

<div>
	<?php
	

      $pdf_query = tep_db_query("select image from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product_info['products_id'] . "' order by sort_order");
	

	
	  while ($row= tep_db_fetch_array($pdf_query)){
	  
	  $ext_info = pathinfo(($row['image']), PATHINFO_EXTENSION);	
	  
	  if ($ext_info == 'pdf')  {
	  
       echo '<div id="pdf_download_product_info"><a href="'. (DIR_WS_IMAGES) . $row['image'] .'" target="_blank">'. $row['image'] .'</a></div>';
	  }
    }


?>
</div>

Here we filter and show only files with extension PDF (you can easily add others; doc, xls, ...).

 

If you can live with PDF's beeing saved in images folder, this is the easy way to do it I suppose.

 

Let me know if also works for you !

Share this post


Link to post
Share on other sites

You can also use this in stylesheet ... upload some pdf image icon 20px x 20px should do it ...

post-150417-0-99078600-1462073628.png
#pdf_download_product_info {
width:100%;
background-image: url('../../images/pdf_download_s.png');
background-repeat: no-repeat;
background-position: left;
padding: 0px 0px 3px 25px;
}

Share this post


Link to post
Share on other sites

And if your thumbnail images gets 2 small and don't want to find the right setting in the gallery settings ...

 

find:

 if (tep_not_null($product_info['products_image'])) {
      $photoset_layout = '1';

      $pi_query = tep_db_query("select image, htmlcontent from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product_info['products_id'] . "' order by sort_order");       
      
      
      $pi_total = tep_db_num_rows($pi_query) - $pdf_count;
      echo $pi_total;

replace with:

// pdf count
$pdfc_query = tep_db_query("select image from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product_info['products_id'] . "' order by sort_order");
    
     $pdf_count = 0;
     while ($pdf_row = tep_db_fetch_array($pdfc_query)){    
    
     $ext_info = pathinfo(($pdf_row['image']), PATHINFO_EXTENSION);    
       
     if ($ext_info == 'pdf')  {    
     $pdf_count++;    
     }  
 }
 $pdf_count = $pdf_count;
// pdf count
 
    
    if (tep_not_null($product_info['products_image'])) {
      $photoset_layout = '1';

      $pi_query = tep_db_query("select image, htmlcontent from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product_info['products_id'] . "' order by sort_order");       
      
      
      $pi_total = tep_db_num_rows($pi_query) - $pdf_count; // minus pdf count
      

Share this post


Link to post
Share on other sites

×