Search code examples
phpjoomlajoomla1.5virtuemart

How to make Print View of invoice in Joomla VirtueMart publicly viewable?


I wanted a function to VM 1.1.8 in Joomla 1.5.22, to allow emailing of pdf invoice to customers who had their purchases confirmed. I've tried various plugins, non works the way I wanted. Thus I'm coding it myself.

To reduce dependency, I've chosen to use pdfcrowd.com to do the html to pdf conversion, as recommended by some stackoverflowers here. However, I'm now facing one problem where the page to be converted must be publicly view-able in order for pdfcrowd to see the output or else the pdf file will ends up with just the admin login page. I'm been googling around, but not getting anything near, maybe I'm using the wrong search terms.

I've also tried to make an independent php page to display a public invoice, but it was too much hassle to setup everything to make it works without poking into joomla's internals.

The page that I'm trying to reproduce is

administrator/index.php?page=order.order_printdetails&order_id=######&no_menu=1&pop=1&tmpl=component&option=com_virtuemart

which is /administrator/components/com_virtuemart/html/order.order_printdetails.php

Btw, I'll be implementing one time token check for the invoice view page, so that it can only be use within a short time frame for conversion. Converted invoice will be stored and reused later if needed.

Please advise. Thank you.

EDIT: Thanks to LAS_VEGAS for pointing to cURL. His code works for public page. To access logged in page, I just need to add code to pass the cookie over.

<?php
// no direct access
defined('_JEXEC') or die;

//Store cookie in format compatible with cURL
$cookie = "";
foreach($_COOKIE as $key => $value) {
    $cookie .= $key . "=" . $value . "; ";
}
$ch = curl_init();
$fp = fopen("example_page.html", "w");

curl_setopt($ch, CURLOPT_URL, "http://www.example.com/administrator/index.php?page=order.order_printdetails&order_id=######&no_menu=1&pop=1&tmpl=component&option=com_virtuemart");
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

Solution

  • You can use PHP curl library to save the webpage to a location on your server.

    <?php
    // no direct access
    defined('_JEXEC') or die;
    
    $ch = curl_init("http://www.example.com/administrator/index.php?page=order.order_printdetails&order_id=######&no_menu=1&pop=1&tmpl=component&option=com_virtuemart");
    $fp = fopen("example_page.html", "w");
    
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    ?>
    

    Then you can forward the url of this saved file to pdfcrowd.com.

    However you need to run this script from from Joomla framework, otherwise it wont be able to access the page.