Author Topic: Modifying Product Details printing  (Read 9601 times)

Matt_Ginn

  • Beginner
  • *
  • Posts: 42
Modifying Product Details printing
« on: October 02, 2014, 10:22:14 am »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9746
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Modifying Product Details printing
« Reply #1 on: October 02, 2014, 11:35:17 am »
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

Code: [Select]
<?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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

jenkinhill

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 27798
  • Always on vacation
    • Jenkin Hill Internet
Re: Modifying Product Details printing
« Reply #2 on: October 02, 2014, 11:44:56 am »
There is already this code in productdetails/tmpl/default.php which can be utilised:

Code: [Select]
if(JRequest::getInt('print',false)){
?>
<body onload="javascript:print();">
<?php }
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

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

Currently using VM 3.8.4.10335 on Joomla 3.9.19 PHP 7.3.18

Matt_Ginn

  • Beginner
  • *
  • Posts: 42
Re: Modifying Product Details printing
« Reply #3 on: October 02, 2014, 12:48:59 pm »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9746
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Modifying Product Details printing
« Reply #4 on: October 02, 2014, 13:14:51 pm »
&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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Matt_Ginn

  • Beginner
  • *
  • Posts: 42
Re: Modifying Product Details printing
« Reply #5 on: October 02, 2014, 13:31:44 pm »
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

  • Jr. Member
  • **
  • Posts: 160
    • websites developed and managed @ ourfingertips.com
  • VirtueMart Version: LIVE 3.2.12 and testing latest
Re: Modifying Product Details printing
« Reply #6 on: October 02, 2014, 17:24:48 pm »
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:
Code: [Select]
<?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
Code: [Select]
/**
* 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:
Code: [Select]
<?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)
Code: [Select]
<?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
?>

Let me know if I can help in anyway!

Hope all is good with you and yours - stay safe! So far all is good with me and mine.

www.ourfingertips.com - websites developed and managed @ ourfingertips

Let me help you make the most of the technology at our fingertips

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9746
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Modifying Product Details printing
« Reply #7 on: October 02, 2014, 22:41:57 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Adwans

  • Beginner
  • *
  • Posts: 49
  • Beginner+
  • VirtueMart Version: J! 3.9.16 / J!3.9.18 VM 3.6.10
Re: Modifying Product Details printing
« Reply #8 on: April 27, 2016, 14:01:16 pm »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9746
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Modifying Product Details printing
« Reply #9 on: April 27, 2016, 16:12:52 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Adwans

  • Beginner
  • *
  • Posts: 49
  • Beginner+
  • VirtueMart Version: J! 3.9.16 / J!3.9.18 VM 3.6.10
Re: Modifying Product Details printing
« Reply #10 on: April 28, 2016, 18:44:32 pm »
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