[Skip to main content](#vessel-content)

#   onBeforeDownloadFile

##

- **[highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")**
- [![highstat@highstat.com's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile") Topic Author
- [ Offline](/forum/user/70596-highstat-highstat-com)

Less More

- Posts: 28
- Thank you received: 1
-
-

3 years 11 months ago [\#347868](#347868) by [highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")  *[onBeforeDownloadFile](/forum/31-development/905611-onbeforedownloadfile#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(&amp;$filename, &amp;$do, &amp;$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&#95;id = $file-&gt;order&#95;id;  I can get the entire order and user information from:  $app = JFactory::getApplication(); $orderClass = hikashop&#95;get('class.order'); $FullOrder = $orderClass-&gt;loadFullOrder($order&#95;id, true, false);  From that I can get for example the invoice number: $InvNum = $FullOrder-&gt;order&#95;invoice&#95;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-&gt;products as $product) { $ProductID = $product-&gt;order&#95;product&#95;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")* was created by *[highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")*

-- 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(&amp;$filename, &amp;$do, &amp;$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-&gt;order_id;

I can get the entire order and user information from:

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

From that I can get for example the invoice number:
$InvNum = $FullOrder-&gt;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-&gt;products as $product) {
$ProductID = $product-&gt;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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwNTYxMS1vbmJlZm9yZWRvd25sb2FkZmlsZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")**
- [![highstat@highstat.com's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile") Topic Author
- [ Offline](/forum/user/70596-highstat-highstat-com)

Less More

- Posts: 28
- Thank you received: 1
-
-

3 years 11 months ago [\#347874](#347874) by [highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")  Replied by *[highstat@highstat.com](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")* on topic *[onBeforeDownloadFile](/forum/31-development/905611-onbeforedownloadfile#347874 "-- 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(&amp;$filename, &amp;$do, &amp;$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&#95;id = $file-&gt;order&#95;id;  I can get the entire order and user information from:  $app = JFactory::getApplication(); $orderClass = hikashop&#95;get('class.order'); $FullOrder = $orderClass-&gt;loadFullOrder($order&#95;id, true, false);  From that I can get for example the invoice number: $InvNum = $FullOrder-&gt;order&#95;invoice&#95;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-&gt;products as $product) { $ProductID = $product-&gt;order&#95;product&#95;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")*

A bit of Googling gave me this:

function onBeforeDownloadFile(&amp;$filename, &amp;$do, &amp;$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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwNTYxMS1vbmJlZm9yZWRvd25sb2FkZmlsZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14327
-
-

3 years 11 months ago [\#347869](#347869) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[onBeforeDownloadFile](/forum/31-development/905611-onbeforedownloadfile#347869 "-- 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(&amp;$filename, &amp;$do, &amp;$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&#95;id = $file-&gt;order&#95;id;  I can get the entire order and user information from:  $app = JFactory::getApplication(); $orderClass = hikashop&#95;get('class.order'); $FullOrder = $orderClass-&gt;loadFullOrder($order&#95;id, true, false);  From that I can get for example the invoice number: $InvNum = $FullOrder-&gt;order&#95;invoice&#95;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-&gt;products as $product) { $ProductID = $product-&gt;order&#95;product&#95;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")*

Hi,

In $file-&gt;file_ref_id you have the id of the product.
You also have it in your loop in $product-&gt;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](/forum/user/70596-highstat-highstat-com "View highstat@highstat.com's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwNTYxMS1vbmJlZm9yZWRvd25sb2FkZmlsZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.055 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
