onBeforeDownloadFile

  • Posts: 25
  • Thank you received: 1
  • Hikashop Business
1 year 10 months ago #347868

-- HikaShop version -- : 4.7.0
-- Joomla version -- : 4.latest
-- PHP version -- : 8.1

Hello,
I thought I was finished...

I have made a plugin that adds customer-specific information to the pdf of an E-book, and then makes it available for download. I am using onBeforeDownloadFile.

It works perfect for 1 pdf....but I have hit a small problem if the customer orders multiple downloadable products.

When hikashop executes onBeforeDownloadFile(&$filename, &$do, &$file, $options)
how can I obtain the information which download button was clicked?

Suppose that the customer has purchased 10 downloadable products, and is now in the download page. There are 10 buttons to click on for download. Click on button 1, and my plugin adjusts all 10 pdf files.....but unfortunately always shows the first one.

I can get the order ID from:
$order_id = $file->order_id;

I can get the entire order and user information from:

$app = JFactory::getApplication();
$orderClass = hikashop_get('class.order');
$FullOrder = $orderClass->loadFullOrder($order_id, true, false);

From that I can get for example the invoice number:
$InvNum = $FullOrder->order_invoice_number;

But how do I know which title (product ID) the customer wants to download?

Something like this will only iterate through all products.
foreach($FullOrder->products as $product) {
$ProductID = $product->order_product_code;

//adjust filename

}


I need to know which download product the customer just clicked on. So that I only have to adjust that specific pdf, and only show that specific pdf.

I guess the answer must be somewhere in your downloads.php.
Kind regards,

Alain

Please Log in or Create an account to join the conversation.

  • Posts: 25
  • Thank you received: 1
  • Hikashop Business
1 year 10 months ago #347874

A bit of Googling gave me this:

function onBeforeDownloadFile(&$filename, &$do, &$file, $options){
$a = get_defined_vars();
hikashop_writeToLog($a);


So..if I grab the name of the file in $filename, then I know what the user wants to open.

If there is a more efficient way....let me know.

Kind regards,

Alain

Please Log in or Create an account to join the conversation.

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
1 year 10 months ago #347869

Hi,

In $file->file_ref_id you have the id of the product.
You also have it in your loop in $product->product_id.
So you can compare both to make sure you're using the code of the correct product.

The following user(s) said Thank You: highstat@highstat.com

Please Log in or Create an account to join the conversation.

Time to create page: 0.061 seconds
Powered by Kunena Forum