Page 1 of 1

Product options = different download file???

Posted: Wed May 20, 2009 4:54 am
by p4m
Hi,

Would it be possible to add the choice to associate a different download file to a product option?
ex: I have a pdf in french or english for download by customers,
option is language,
option values french and english
and only one download file for both option which is not possible and make the option unusuable. I have to create a new product just for a different language. One can imagine what this means if one deal with 3 or 4 options that change a bit the file....
That would be a very useful add.

Thanks

Re: Product options = different download file???

Posted: Wed May 20, 2009 5:16 am
by Daniel
you don't have to create another product for each language. you can have multiple downloads for each product.

Re: Product options = different download file???

Posted: Thu Aug 19, 2010 6:55 pm
by eyeseesound
Hey,

what if i want different downloads DEPENDING on the option chosen.

We have music DVDs. The choices are

1) mp3s only
2) mp3 + .mov
3) DVD

with option 1) they get the mp3.zip file
with option 2) they get the mp3.zip file and mov.zip file
with option 3) they get the mp3.zip file and mov.zip file as well

At the moment it seems that i can only attach multiple downloads so even if they pick mp3 they also get the mov.zip file

Any ideas greatly appreciated as i'd rather not have to have seperate product pages for each option as it's nice them all being in one place.

Re: Product options = different download file???

Posted: Wed Dec 15, 2010 4:26 am
by Chones
I have this problem as well. I'm working on a music download store too, and obviously only want to list each track once. However, I'd like the customer to have a choice of options e.g. mp3 file or WAV file. Depending on the option they choose they get a different download.

I've played around with the admin system but don't seem to be able to do it. Anyone have any ideas?

Re: Product options = different download file???

Posted: Wed Dec 15, 2010 7:23 am
by Xsecrets
it is not possible with the current system. It would take quite a bit of hacking to make it work that way.

Re: Product options = different download file???

Posted: Wed Dec 15, 2010 4:24 pm
by Chones
Yeah, I didn't think so. Guess it's time to get hacking. Or pray that v1.5 comes out soon ;)

Re: Product options = different download file???

Posted: Thu Dec 16, 2010 3:42 am
by Chones
Think I've worked out a quick way to do it:

Add both download files to the product i.e. 'Track Name mp3 version' and 'Track Name wav version'
Name the options 'mp3' and 'wav'
When customer buys the track, in the downloads section by default they currently get to download both files, no matter what option they chose.

All I have to do is only show the one that contains the string of their chosen option. E.g. if they chose 'mp3', only show 'Track Name mp3 version' for download.

This seems a lot easier than adding files to each option, which I thought I was going to have to do.

Right... now I just have to code it! Will post when I'm done.

Re: Product options = different download file???

Posted: Thu Dec 16, 2010 5:31 am
by Chones
Okay, think I've made it work, but will have to do more testing. Basically I'm only adding a download to the order database if the name of the download contains the option. If anyone has any better ideas please let me know. And please excuse the code - I'm more of a designer than a programmer.

Basically, in catalog > model > checkout > order.php find this:

Code: Select all

foreach ($product['download'] as $download) {
				$this->db->query("INSERT INTO " . DB_PREFIX . "order_download SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', name = '" . $this->db->escape($download['name']) . "', filename = '" . $this->db->escape($download['filename']) . "', mask = '" . $this->db->escape($download['mask']) . "', remaining = '" . (int)($download['remaining'] * $product['quantity']) . "'");
			}
Replace it with the following, which just checks if the name of the download contains the option.

Code: Select all

foreach ($product['download'] as $download) {

$valuequery = $this->db->query("SELECT value FROM `" . DB_PREFIX . "order_option` WHERE order_product_id = '" . (int)$order_product_id . "'");
$optionvalue = $valuequery->row['value'];
$downloadname = $this->db->escape($download['name']);
if (strstr($downloadname, $optionvalue)) {

				$this->db->query("INSERT INTO " . DB_PREFIX . "order_download SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', name = '" . $this->db->escape($download['name']) . "', filename = '" . $this->db->escape($download['filename']) . "', mask = '" . $this->db->escape($download['mask']) . "', remaining = '" . (int)($download['remaining'] * $product['quantity']) . "'");
				}
			}
Hope that makes sense and isn't too badly coded! :-\

Re: Product options = different download file???

Posted: Sun Feb 06, 2011 9:09 pm
by Photospirit
Hi,

I've used your code, but the result is still the same. I'm having a picture to download in different sizes (L, XL, S, etc.).
I've added the sizes (L, XL, ...) as option and named the picture to download card1_L / card1_XL / etc.

When I now choose L from the option, I still get both products for download.

What have I done wrong? Any idea?
I'm using OC 1.4.9.3

Many thanks, Chris

Re: Product options = different download file???

Posted: Sun Feb 06, 2011 9:54 pm
by Chones
Well, both of those options have L in them, so when it looks to see if the name contains L it will add both L and XL to the downloads.

Test it to see if it does the same thing when you buy XL. If that works then it's purely down to the naming of your options. You're going to have to think of a different way to differentiate them that doesn't use the same string, or same letter.

As I said, it's not a perfect solution I'm afraid.

Re: Product options = different download file???

Posted: Sun Feb 06, 2011 10:19 pm
by Photospirit
well sometimes things are so easy :-) Now as you mention it, it's obvoius that it was not working with my settings. I've changed it and now it works perfectly....many thanks for your help.

Cheers, Chris

Re: Product options = different download file???

Posted: Wed Oct 05, 2011 8:19 pm
by webbutvecklarna
I know it's a little late but I don't think it's secure enough. strstr finds the first occurrence. So if the name of the downloaded file contains the letter L for large it will add the downloadable file.

Try this instead. It splits the name by underscore and takes the last letter/word for matching. For example.
Options: Small, Medium Large
Downloadable files: image_001_small, image_001_medium, image_001_large

Code: Select all

foreach ($product['download'] as $download) {
				$valuequery = $this->db->query("SELECT value FROM `" . DB_PREFIX . "order_option` WHERE order_product_id = '" . (int)$order_product_id . "'");
				$optionvalue = $valuequery->row['value'];
				$downloadname = $this->db->escape($download['name']);
				$tmp = split('_', $downloadname);
				$size = count($tmp);
				
				if (strtolower($optionvalue) == strtolower($tmp[$size - 1])) {
					$this->db->query("INSERT INTO " . DB_PREFIX . "order_download SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', name = '" . $this->db->escape($download['name']) . "', filename = '" . $this->db->escape($download['filename']) . "', mask = '" . $this->db->escape($download['mask']) . "', remaining = '" . (int)($download['remaining'] * $product['quantity']) . "'");
				}
			}

Re: Product options = different download file???

Posted: Tue Jan 24, 2012 3:45 pm
by animani
I don't know if I might come in handy but I think the problem having several downloads when just one selected is due to the confusion of product downloads tab (auto-free download with every purchase) and options tab (free or with price downloads non automatic). If you create download options make sure you don't get confused by the first download section you find in products... The created options appear in any product options tab and has to be recalled by typing the first letter of the option download name in order to add them.

Hope someone find that useful.