Page 1 of 1

Dev Request: Event after Creating downloads

Posted: 27 Apr 2024, 15:05
by lpatrick
Jan

I have searched and it's been requested several times; to be able to join downloads into one. I think you always confirmed it doesn't exist.

So I would like to request to create a new event to be called after you complete the creation in the _phocacart_order_downloads table when the order is completed so I can check if the order with the specified ID has multiple downloads and then combine them into one ZIP file to propose to the customer.

E.g. in our Photo shop, people might order 10-20 images or even more and it's a drag to need to download these one by one.
Also if the customer orders from multiple galleries, then the downloads list can get quite long and I don't see any form of pagination.

If in y callout code, I check if more than 1 item exists in _phocacart_order_downloads for that order, I can read all the download files, combine them into a zip and create my own entry in there pointing to the ZIP file I created with a newly created download token instead.
After testing, I would then also remove the single download rows to keep things tidy and keep the list of downloads small and to honour the configured maximum number of downloads.

I do hope that is not too much effort for you. I'd be ever so grateful.

I'm willing to offer the code for you or anyone asking.

Re: Dev Request: Event after Creating downloads

Posted: 29 Apr 2024, 12:20
by Jan
Hi, the question is, if this could be possible per events only or it should be more some specific external solution. There is no problem add events, but such events cannot break the core functions, the safety, etc. etc. :idea: For example events should not remove single downloads, etc. They can extend e.g. the list so they will display the packaged ZIP and allows it to download but they should not clear the list of single downloades as such can have different features (like date from or date to, etc. etc.) :idea:

Jan

Re: Dev Request: Event after Creating downloads

Posted: 29 Apr 2024, 13:24
by lpatrick
Hey Jan

The new entry would have the same settings as all the other downloads you have created for that order (except for the variable parts of course).

But perhaps an alternative could be to call an event which can change the download files array before you store it in the table?

Because as I said ... if you have hundreds of lines in your Downloads view ... it will stay a real mess. Imagine someone needing to download 50 photos one by one ... would you go back to that shop?

I don't know what all the columns in that table are for. The only ones you really use are id, order_id, title, download_token, download_file, download_hits, download_days, date and published more or less, right?
Since I don't see anything else really used, not in the list of the downloads for frontend, nor backend. My ZIP file is simple there:

Code: Select all

insert INTO #_phocacart_order_downloads (`order_id`, `product_id`, `attribute_id`, `option_id`, 
`order_product_id`, `order_attribute_id`, `order_option_id`, `title`, `alias`, `download_token`, 
`download_folder`, `download_file`, `download_hits`, `download_days`, `checked_out`, `checked_out_time`, 
`type`, `ordering`, `date`, `published`)
SELECT `order_id`, 0, 0, 0, 0, 0, 0, 'Order 136 ZIP', '', `download_token`,
 'AZFCoH3du2OQ8biW7', 'AZFCoH3du2OQ8biW7/secret order136.zip', `download_hits`, `download_days`, `checked_out`, `checked_out_time`, 
`type`, `ordering`, `date`, `published`
FROM `#_phocacart_order_downloads` WHERE order_id = 136 and published = 1 limit 1;
I know I'm cutting corners here but I'm looking for a solution to a problem which seems not to be solvable in another way for a shop which would need to handle large quantities of downloads (if sale goes well).

It's obvious that those who would also like to use the code I've written, need to be aware of the consequences.
But I don't see other problems with core functionality and security since we copy all that and they're all the same for one particular order (right after being created). (I know the download token isn't, but you only need one secret token and it's only verified back the moment a guest downloads the ZIP in this case, right?)

Or do you have a better solution?
Or are you saying Phoca Cart is not a solution for that kind of shop?

Re: Dev Request: Event after Creating downloads

Posted: 03 May 2024, 02:04
by Jan
Hi, I didn't do such modification yet, so for me hard to say if it is OK or is missing something.

You need the token for guest users so there is no direct link to file (including the folder).

Jan

Re: Dev Request: Event after Creating downloads

Posted: 05 May 2024, 13:45
by lpatrick
I think it's probably better that I Unpublish the separate images which I no longer need in the Downloads table to keep compatibility with your code (just in case).

I would call my code just before the 'return true' at the end of saveOrderDownloads in libraries\phocacart\order\order.php

Unless you suggest otherwise.