News:

Looking for documentation? Take a look on our wiki

Main Menu

Modifying Product Details printing

Started by Matt_Ginn, October 02, 2014, 10:22:14 AM

Previous topic - Next topic

Matt_Ginn

Looking for a way to modify the layout of the pop-up that appears when I click the 'print' icon on my product details page. Currently it exactly replicates the layout of that page eg. http://www.mardens-trading.co.uk/portwest/component/virtuemart/view/productdetails/virtuemart_product_id/139/virtuemart_category_id/374.

I'd like to be able to trim the content down to just the most relevant bits ie. name, description, and an image. Where is the layout of this controlled from?

GJC Web Design

it is just the same templates with sub templates as your detail view

so you need to over ride them and do some changes depending on whether it was called as normal or as a print view

you can use the

<?php
if(JRequest::getInt('print',false)){ // this is the print view
?>

show on print
<?php }  ?>


to detect if your looking at the print view or vice versa

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

jenkinhill

There is already this code in productdetails/tmpl/default.php which can be utilised:


if(JRequest::getInt('print',false)){
?>
<body onload="javascript:print();">
<?php }
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Matt_Ginn

Hmm, still don't quite get this! When I look at the html source of the pop-up, it's getting it's layout from component.php in the root of my template folder (I can tell from the doctype declaration) but that in turn calls this <jdoc:include type="component" /> to get the content??

GJC Web Design

&type=component is the standard Joomla method of showing a component view without the site template

Either you believe me or not where the html is formed - entirely up to you...  ;)
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Matt_Ginn

Haha  ;D I do believe you mate! I was hoping there was going to be an easier way of doing it! The template I'm using (Gavick Storefront) has the product details layout all in one big file, rather than a series of smaller ones all called from default.php like some other templates do! Means I've got to go through it wrapping each bit of the layout that I don't want in the conditional code!  ::) Oh well, there goes my lunchtime!!

Thanks for you help.

Robert_ITMan

#6
I had issues with printing PDF too and now I have 2 different solutions working for my clients (1) using the VM templates (easy) and (2) using custom php along with TCPDF directly (not so easy!). I can quickly share what I did to get you started - as mine are heavily customized I can't actually share the files:

(1) using the VM templates

/templates/(your template)/html/com_virtuemart/productdetails/default.php
I added a link:
<?php // print to pdf ?>
<div style="float:left;"><a href="/index.php?tmpl=component&option=com_virtuemart&view=productdetails&virtuemart_product_id=<?php echo $this->product->virtuemart_product_id ?>&format=pdf" title="Print Product Details" target="_blank"><img alt="PDF" src="/media/system/images/pdf_button.png" style="margin:0 3px -3px 0;">Print Product Details</a></div>


then customize the file
/templates/(your template)/html/com_virtuemart/productdetails/default_pdf.php

(2) using custom php along with TCPDF directly

Check your install of tcpdf is correct (I remembering having to reinstall it - and it was easy to do) notice also you can customize the config and header in this file: /libraries/tcpdf/config/tcpdf_config.php

/**
* document author
*/
define ('PDF_AUTHOR', "Your Company - What You Do");

/**
* header title
*/
define ('PDF_HEADER_TITLE', "            Your Company - What You Do");

/**
* header description string
*/
define ('PDF_HEADER_STRING', "             Your address\n             Your Phone    www.yourwebsite.com"); //"by Nicola Asuni - Tecnick.com\nwww.tcpdf.org"

/**
* image logo
*/
define ('PDF_HEADER_LOGO', '/images/stories/virtuemart/vendor/logo-print.jpg');

/**
* header logo image width [mm]
*/
define ('PDF_HEADER_LOGO_WIDTH', 15);


/templates/(your template)/html/com_virtuemart/productdetails/default.php
I added a link:
<?php // print to pdf ?>
<div style="float:left;">
<a href="/templates/(your template)/lib/php/productdetails.php?id=<?php echo $this->product->virtuemart_product_id ?>" title="Print Product Details" target="_blank"><img alt="PDF" src="/media/system/images/pdf_button.png" style="margin:0 3px -3px 0;">Print Product Details</a></div>


/templates/(your template)/lib/php/productdetails.php
I hope you find this helpful even though I removed the scripts in the code here - I have a few of these and none are just a better display of the product details - if you do create one please share it here! (I have one just for admins to print off a list of all those who have purchased the product, another to batch print the category of all those who purchased each product)

<?php  // Copyright © ________ All Rights Reserved.
// this script creates a custom PDF
// see TCPDF Documentation: http://www.tcpdf.org/doc/code/classTCPDF.html
// securing this external file see: http://stackoverflow.com/questions/9459430/include-jfactory-class-in-an-external-php-file-joomla
define'_JEXEC');
define'DS'DIRECTORY_SEPARATOR );
define'JPATH_BASE'$_SERVER'DOCUMENT_ROOT' ] );
define'JPATH_BASE'$_SERVER'DOCUMENT_ROOT' ] ); // define JPATH_BASE on the external file
require_once( JPATH_BASE DS 'includes' DS 'defines.php' );
require_once( 
JPATH_BASE DS 'includes' DS 'framework.php' );
require_once( 
JPATH_BASE DS 'libraries' DS 'joomla' DS 'factory.php' );
$mainframe =& JFactory::getApplication('site');
require_once( 
JPATH_BASE DS 'libraries' DS 'import.php' ); // framework
require_once( JPATH_BASE DS 'configuration.php' ); // config file
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

// GETTING the values
// need prod id 
$prod_id =  htmlspecialchars($_GET['id']);
  if (
$prod_id == '') {
  
//$prod_id = '59';  // for testing without getting real data
  
die('Sorry no items match your search results.');
  }
////////// removed customization //////////
JFactory::getDBO()->setQuery("SELECT product_sku FROM jos_virtuemart_products WHERE virtuemart_product_id=$prod_id LIMIT 1");
$current_sku JFactory::getDBO()->loadResult();
if (
$current_sku == '') { // no such product
  
die('Sorry no items match your search results.');
} else { 
// product exists
////////// removed customization //////////
JFactory::getDBO()->setQuery("SELECT product_name FROM jos_virtuemart_products_en_gb WHERE virtuemart_product_id=$prod_id LIMIT 1");
$prod_name JFactory::getDBO()->loadResult();

// SETTING the values
////////// removed customization //////////

//// END of GETTING and SETTING the values - start calculating
////////// removed customization //////////

//load the pdf creator as already installed in libraries
ob_start(); // clear the php buffer needed to stop warning for 'headers already sent'
require_once( JPATH_BASE '/libraries/tcpdf/config/lang/eng.php' );
require_once( 
JPATH_BASE '/libraries/tcpdf/tcpdf.php' );

// create new PDF document
//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // Portrait
$pdf = new TCPDF('L'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false); // Landscape

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('www.yourwebsite');
$pdf->SetTitle('Product Details for '.$prod_name);
$pdf->SetSubject('Product Details');
$pdf->SetKeywords('');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN''PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA''PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFTPDF_MARGIN_TOPPDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin('');//$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// IMPORTANT: disable font subsetting to allow users editing the document
$pdf->setFontSubsetting(false);

// set font
$pdf->SetFont('helvetica'''8''false);

/* help
TCPDF::Cell  (
  $  w,  
  $  h = 0,  
  $  txt = '',  
  $  border = 0,  
  $  ln = 0,  
  $  align = '',  
  $  fill = false,  
  $  link = '',  
  $  stretch = 0,  
  $  ignore_min_height = false,  
  $  calign = 'T',  
  $  valign = 'M'   
 ) 
*/

// add a page
$pdf->AddPage();

// Title
$pdf->Cell(10'');
$pdf->SetFont('helvetica''B'12);
$pdf->Cell(10'Product Details for '.$prod_name00L);
$pdf->Ln(0.1);
$pdf->SetLineStyle(array('width' => 0.3));
$pdf->SetFont('helvetica'''10);

////////// removed customization //////////

$pdf->Ln(7);
// Close and output PDF document
$varfilename 'product_details_'.$prod_id.'.pdf';
$pdf->Output($varfilename'I');
ob_end_flush();
// may need more or less closing brackets here depending on what is above
?>


WEBSITES @ OURFINGERTIPS
manage > develop > market > repeat

Save a lot of time and money when focused on building a website that works with marketing efforts to get more leads and sales from visitors.

www.ourfingertips.com

GJC Web Design

just to add - I had terrible problems formatting TCPDF consistantly and used the https://github.com/dompdf/dompdf
was soo much easier to do the html etc
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Adwans

Hello!
I m struggling with TCPDF too, especially trying to use normal html elements like <svg> or <canvas>, which seems to be rather impossible.
Question is: = how to incorporate and than use dompdf with VM/ Joomla?
GJC, could You write it in few words?
Does DOMPDF allow to use <svg> or <canvas> tag?
Regards
A.

GJC Web Design

from 18 months ago?   :o

lucky if i can remember what I had for breakfast..  ;)

I'm sure St42 had an article on this but I see he has a shiny new site..  :(  can't find

http://st42.fr/
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Adwans

OK, I thought that you often use DOM instead of TCPDF.  8)
But: one may notice that both of them don't support <svg> nor <canvas>.
Now, this is different way I want to achieve this = drawings on invoices.
PHP. GD. Not so nice-looking but hope will works together with TCPDF. Or maybe there 's another way?
Thanks a lot!
Regards!
Z