How to set up Multiple Downloads per Product in MarketPress ?

I definitely need multiple downloads per product in MarketPress. E.g. several songs in a music store belong to an album or a collection.

I studied the plugin and found it is possible with an afternoon's work to build it in. Here are the steps to do it:

1a. The idea is, to store in the mp_file field of a product not one, but all URLs you want to include in the product.

1b. So you have to make the field bigger on the screen to show all these URLs (one at a line)

1c. To do so in file marketpress/marketpress.php you change the input text field with name mp_file into a textarea with 100 cols and 7 rows

1d. In the same file search for update_post_meta( $post_id, 'mp_file' ... ) and put some code in to transform the lines from the input field into a string, where the URLs are separated by comma. This avoids any problems with newlines interpreted as spaces etc.

Now we have several URLs stored in the mp_file field of a product.

2. Whereever the mp_file field is used to generate an URL for downloading one product you change the code so it deals with several URLs:

2a. in marketpress/marketpress.php change the function get_download_url so that it returns an array of URLs (and not a single URL). To make the URLs different from each other I decided to add a GET parameter (named "file") with the number of the URL in the array. This way it interferes the least with the existing method of identifying a download with the product.

2b. In the function serve_download you have to ask the GET parameter "file" to find out which URL to serve for download.
This function also checks how often a file was already downloaded. This is more difficult to implement for each of the URLs of one product - it means extending the data structure of $download array. I decided against it. Instead of I test if there has been more then (max_downloads * number of files for the product) downloads. That means each file could be downloaded the maximum of permitted downloads (or more, if another file is downloaded right away on the first try).
When the file is served marketpress generates a filename for it. To make a different name for each of the files of one product you have to add the number of the file to this filename (search for sanitize_file_name).

2c. The confirmation email must have download links for all files of the product. This is added in the function filter_email.

3. The order status, which can be inspected on the store web page contains the download link. The code for this has to be extended so all download links for all files for one product appear.

3a. There is a file marketpress/marketpress-includes/template-functions.php where you can find useful functions for themes. Searching for "Download" leads you to a table where the link is printed (if the order is paid and the download limit is not exceeded). There you have to make the same adaptions as described above for computation of the download limit and for generating the download links.

4. It should also work with your theme, shouldn't it? I use the child theme gridmarket of FrameMarket. The only way to get it really working with this theme was to change the file framemarket/library/functions/marketpress.php (I could not figure out how to do this in the child theme): Search for a table followed by an "if ($order_paid)". There you have to add the max download test and the generation of the download links - it is the very same as you might have done in the template-functions.php file.

That's it. Screenshots of the result you can see in the first answer (can still not figure out how to include pics in the opening post).

I have to clean up the comments a bit and migrate completely to Marketpress 2.8.1 (I started in 2.8 with it). Then I can give the files to whoever might be interested in this (not before friday).

  • Emanaku
    • The Incredible Code Injector

    ok, here is the download of the three changed files.
    Please read the README and try it first in some test environment ... :wink:

    http://emanaku.com/dl/emanaku-MultipleURLsPerProduct-in-MarketPress.zip

    If you have problems, answer here and I will see what I can do ...

    Enjoy!

    PS: From the README.txt:

    Why didn't you make these changes e.g. in the functions.php so the changes would survive updates of the plugin/theme?
    --------------------------------------------------------------------------------
    I really would have liked to do so!
    But as far as I can see this is not possible (especially not the changes in the function get_download_url in marketpress/marketpress.php)

    and

    Thanks to WPMU and especially Aaron for the wonderful plugin MarketPress and Jeffri for the FrameMarket theme!

    :slight_smile:

  • Emanaku
    • The Incredible Code Injector

    Hi Aaron, I would not like to zip because (1) this is another step after downloading and (2) our customers mostly are not very computer savvy so they would just like to "use it as downloaded" :wink:.
    The files are between 10 and 30MB each. Zipping them just makes the download bigger ...

    Thanks for the rep points, too!

  • Dean Kaus
    • The Bug Hunter

    +1 +1 +1
    Thanks @Emanaku Will be sending some points your way. i can see @Aaron point about zipping files and agree with all of the points given... customer confusion, file size etc... But what I really love with this (and I do hope that we get enough plus 1s here) Is that it would be very simple to have a package of the week deal and change the download url's accordingly.

  • tunelab
    • WPMU DEV Initiate

    This is awesome! Thank you for this. Building off of this, does anyone who knows this stuff think it would be possible to take the same concept of multiple files, but then make it a choice at the end? That way, when I sell a music track, I can give people a choice of whether to download it as .mp3, .m4a, .wav, or .flac. But this is a great start because I can at least offer all 4 in one transaction instead of having to have 4 different product listings.

  • grahamlindsey
    • Design Lord, Child of Thor

    Thanks Aaron - that's really great news! Is this something that is likely to take a week, month or year to be released to folk like us? I'm only asking so I can prepare my clients to wait (or find a workaround) if it'll be out later this year.

    We're also looking at hosting files off-site (Amazon S3) and would like the ability to manually enter a URL for the file.

    Thanks again, and sincerest apologies for having to ask "are we there yet?"

  • grahamlindsey
    • Design Lord, Child of Thor

    Thanks again Aaron - I just wanted to reiterate that being able to specify a URL for each file is critical because we'll be hosting the files (sometimes up to 1.5GB) on an Amazon S3 account, and an uploader won't work in our situation.

  • grahamlindsey
    • Design Lord, Child of Thor

    Hi @Aaron,

    I figured I'd check in, as it's been a bit over a month. Do you have any updated timeline for this plugin?

    Feature Recap:
    - multiple downloadable files per product
    - capability to enter URLs for multiple files (we will store files offsite)

    Many thanks,
    Graham

  • grahamlindsey
    • Design Lord, Child of Thor

    Hi @Aaron - just checking in (at about the 3 month mark). How are things going with the multiple digital downloads addition to Marketpress?

    This feature is critical for my client, and I will start the day it's released - I'm hopeful it will be ready for us to get started very shortly.

    Would you let us know how things are progressing?

    Cheers,
    Graham

  • luckyrhyno
    • WPMU DEV Initiate

    I'm with grahamlindsey.

    These added features would attract more clients I would imagine.

    If there is a list of who wants these particular features add me to that list.

    Being able to specify a URL for each file would be excellent.

    Also, hosting the files (sometimes up to 1.5GB) on an Amazon S3 account would make sense for large file like this, especiallt since the uploader didn't work in my situation. I had to manually upload them using ftp and then input the address in the URL field. Which works, it's just additional steps that could be saved if I just put my S3 URL in the input filed. Big "time" saver which I think time it a much desired commodity on all of ourr lists.

    -Peter .

  • PC
    • WPMU DEV Initiate

    Hey there,

    Thanks for your post.

    Unfortunately its not implemented yet. Our developers have been busy with a theme project and were buried neck deep in development.

    However thanks for adding your vote. If we get more demand, we can push this on the developer's table to keep on top of his list.

    Cheers, PC

  • grahamlindsey
    • Design Lord, Child of Thor

    Thanks for the info, @PC.

    I've been touching base somewhat regularly with @Aaron because the ability to download multiple different files (basically: product variations where a variation can specify a file (or remote URL) for purchase) was in the cards. This is a critical for me because I have several clients who are looking for this feature (NB: the feature I've described is slightly different from @Emanaku's original post, allowing files to be downloaded individually).

    Aaron mentioned that you had a new developer working exclusively on Marketpress. Has that changed?

    Is there an amount that I/we need to pay to have the feature considered? It's critical that I get this feature sooner than later.

    Thank you,
    Graham

  • PC
    • WPMU DEV Initiate

    Hey there Graham,

    Thanks for your post.

    Aaron mentioned that you had a new developer working exclusively on Marketpress. Has that changed?

    No that hasn't changed. Our new developer is still working on adding new features to MarketPress. We have got a lot of feature requests for MarketPress plugin and as per the number of users looking for that feature they are prioritized.

    This one is also sent to the dev team however we don't have any information about any ETA for a new feature.

    Is there an amount that I/we need to pay to have the feature considered? It's critical that I get this feature sooner than later.

    Unfortunately no. The features are developed without any additional charge. If however you want someone to do that for you any sooner, or you need a dedicated developer, we have a Jobs board here : https://premium.wpmudev.org/wpmu-jobs/ :slight_smile:

    Cheers, PC

  • brandee
    • Site Builder, Child of Zeus

    I'm adding +1 +1 to support this feature being implemented in Marketpress.

    I'm not sure how far along this will be done in Marketpress. It seems to be a feature people would want. I have problems with large file download particularly because my client has customers around the world and large download files are difficult for them. Also, non-techy people are confused by unzip features.

    With that said, I'm going to try to implement Emanaku's code as I have a very large download and I really need to break into smaller files. The above post form 1 year ago states if we can to connect with him about this feature to post here. I'm wondering if he could weigh in if the code above will still work on the latest version of Marketpress.

    Thanks!
    Brandee

  • Emanaku
    • The Incredible Code Injector

    Hi Brandee,

    because of travelling and couple of other circumstances in my life I am not able to do any serious work with my code for the multiple downloads.

    It runs on our system with Wordpress 3.5.1 and Marketpress 2.8.5.

    I will not upgrade either of them within the next few months, so for the time being I cannot really help you with this.

    But it should be simple enough to try it, and - if there are any errors - to repair it with basic PHP, Wordpress and Marketpress knowledge ...

    All the best and good luck!!!

    Emanáku.

  • brandee
    • Site Builder, Child of Zeus

    Hi Emanaku,
    Thanks for getting back to me on this. I understand. I'll take a swing at it because I am really in need. Right now I'm giving them a .pdf file with the download links because the files are too large to download as a zip file.

    I'll let you know how it goes.

    Brandee

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.