Post by managermd » Sun Jan 02, 2011 8:53 am

Hello support team
I need to add unique downloadable digital product on each product page.
For example I am a VPN account provider and need to send custom username and password for each customer.
and need to create a page for many accounts.
for example 1 month USA account and upload many one month USA account and add to this page from download section. and each customer just able to download one of them and next customer download the next user name.
I did this but each user can download all files but I need each user able to download just one file

Can you please help me about this kind of product ?

for example is this code is according my request or not ?

http://forum.opencart.com/viewtopic.php?f=20&t=4084

Regards

Newbie

Posts

Joined
Sun Jan 02, 2011 8:45 am

Post by Chones » Sun Jan 02, 2011 6:53 pm

Hi Managermd,

That code is for options so not really what you're after, but you should add some code around the same place to do what you're after.

As you've noticed, when a customer buys a product every download file is added to their account. What you need to do is just add one unique download to their account.

Basically, after

Code: Select all

foreach ($product['download'] as $download) {
run a check to see if any customers already have the download in their orders. If they don't, upload it to the order database and then move on without adding any more.

At least, that's what I would try.

http://scarletandjones.com/
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk


User avatar
Active Member

Posts

Joined
Wed Mar 24, 2010 9:07 pm
Location - London

Post by managermd » Sun Jan 02, 2011 9:27 pm

Hello and thanks for your help
Infact I am not a professionam in opencart source code.
Can you please let me to know I must add this code on which file or page ?

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

Thanks

Newbie

Posts

Joined
Sun Jan 02, 2011 8:45 am

Post by Chones » Sun Jan 02, 2011 9:42 pm

Ah, please refer back to the solution you linked to.
It's in in catalog > model > checkout > order.php

You'll need to SELECT the download from the database. If you get no result, meaning it has not been ordered by anyone yet, then you can add it.

http://scarletandjones.com/
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk


User avatar
Active Member

Posts

Joined
Wed Mar 24, 2010 9:07 pm
Location - London

Post by managermd » Sun Jan 02, 2011 10:38 pm

Hi again and thanks
I foudn this line
foreach ($product['download'] as $download) {
in oreder.php
but I don't know which code I must add after this line

Newbie

Posts

Joined
Sun Jan 02, 2011 8:45 am

Post by Chones » Sun Jan 02, 2011 11:18 pm

You're going to have to replace

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']) . "'");
         }
With something like this - although I'm not a programmer, so this may not work

Code: Select all

$count = 1;
foreach ($product['download'] as $download) {

$downloadfile = $this->db->escape($download['filename']);
$downloadquery = $this->db->query("SELECT filename FROM `" . DB_PREFIX . "order_download` WHERE filename = '" . $downloadfile . "'");
$downloadfilename = $downloadquery->row['filename'];
if (($downloadfilename == '') && ($count == 1)) {

$count = 2;
$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']) . "'");
            }
}
If that doesn't work, hopefully someone with more programming experience can help you.

http://scarletandjones.com/
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk


User avatar
Active Member

Posts

Joined
Wed Mar 24, 2010 9:07 pm
Location - London

Post by managermd » Tue Jan 04, 2011 2:00 am

Hi Chones and thanks for your help
One of my friends test it and got this error

I have tested the code with version 1.4.91 and this is the error:
Notice: Undefined index: filename in
D:\AppServ\www\opencart1491\catalog\model\checkout\order.php on line 94Notice:
Undefined index: filename in
D:\AppServ\www\opencart1491\catalog\model\checkout\order.php on line 94Notice:
Undefined index: filename in
D:\AppServ\www\opencart1491\catalog\model\checkout\order.php on line 94

It seems to be for a version easier than 1.4.9.1


Anyway thank you very much for your help

Newbie

Posts

Joined
Sun Jan 02, 2011 8:45 am

Post by Chones » Tue Jan 04, 2011 2:44 am

Sorry it didn't work - I've not really got time to try it out myself and debug it I'm afraid, but anyone with a passing knowledge of PHP should be able to help.

It is the solution you need, it's just my coding obviously leaves a bit to be desired.

http://scarletandjones.com/
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk


User avatar
Active Member

Posts

Joined
Wed Mar 24, 2010 9:07 pm
Location - London
Who is online

Users browsing this forum: No registered users and 2 guests