Hello,
I can certainly see how nice that would be!
I gave it a try. I made a new plugin. Without the plugin, I am able to download the original pdf. When I enable the plugin, then I can see that the plugin is being executed. And I am able to access the order number (and therefore all info I need to make new pdfs on the fly).
But I get "File not found" when I click on the download link. So..it trying to change the filename (which is good)...but to the wrong thing. Nothing to see in the log file.
Below is part of the code that I made.
1. I guess that the error must be in $filename. It is the full path + new file name?
2. So, if the original pdf is in /media/com_hikashop/upload/safe/Paper1.pdf and the newly generated file is in /media/com_hikashop/upload/safe/downloads/Paper1.pdf...then that should all work?
3. I assume that the "/home/username/website address/" has to be included in $filename?
4. Could the error be due to the subdirectory downloads being in an .htaccess protected directory?
5. The filename itself can be different (e.g. PaperNewName.pdf) ?
Any idea what is causing the error?
Alain
function onBeforeDownloadFile(&$filename, &$do, &$file, $options){
if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }
//Step 1: Get order ID.
$order_id = $file->order_id;
//Step 2: From the manual: $filename is the path to the file name.
//I assume that this is the path to the new file.
//As a test, I created a copy of the original pdf and copied
//it into a directory with the name 'downloads'. Hence,
//com_hikashop/upload/safe contains the original and
//com_hikashop/upload/safe/downloads the newly modified pdf for
//the customer. Eventually, $filename has to be created at the
//very end of this file.
$filename = "/home/***/***.com/media/com_hikashop/upload/safe/downloads/Paper1.pdf";
$do = FALSE;
//Step 3: Load the complete information of an order
//via loadFullOrder.
$app = JFactory::getApplication();
$orderClass = hikashop_get('class.order');
$FullOrder = $orderClass->loadFullOrder($order_id, true, false);
// And from here onward it is piece of cake!
}