Results 1 to 7 of 7
  1. #1
    Join Date
    May 2016
    Location
    St. John's NL Canada
    Posts
    28
    Plugin Contributions
    0

    Default Has anyone had download counts go negative?

    I discovered, by accident, that some entries in the orders_products_download table have a negative value for download_count. There aren't many, but I want to figure out what is causing this. If the download code checks for a zero value to see if another download is allowed, the presumably once it goes negative the customer can repeat the downloading as often as desired.

    I suspect that most of these negative values occurred while the site was running under Zen Cart 1.3.9h (it is now on 1.5.5a).

    I will be checking out the download code, but I'd be interested if anyone else has encountered this problem.

  2. #2
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: Has anyone had download counts go negative?

    At least with the recent code, this is possible (negative download_count) if the download_maxdays is set to 0. Time allowed outweighs count in that regards. If though the download_maxdays is other than 0 then with a 0 or lower download_count the download will be prevented.

    As to "seeing" this? Can't say have dug into the table data like that for downloads, just the code that uses it. Sure have looked at/modified the data table to support testing, but...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    May 2016
    Location
    St. John's NL Canada
    Posts
    28
    Plugin Contributions
    0

    Default Re: Has anyone had download counts go negative?

    There had been a bug in the downloads code that had the testing of maximum time and maximum downloads wrong. I had fixed it, but I saw that it was fixed in 1.5.5a, so just used the 1.5.5a version.

    We want a maximum number of downloads, but without a restriction on when the downloads are done. For example, a customer downloads an e-book and (although I know nobody ever does this ) fails to keep backups and nukes their downloaded copy. In that case, no matter what time has passed, we want the customer to be able to re-download the e-book. However, we want a limit on how many times the e-book can be downloaded. It's not much protection, but it's better than nothing.

    I'll take a look at the code again and perhaps re-implement my own fix again.

    Thanks very much for explaining the interaction of the two parameters in stock Zen Cart.

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Has anyone had download counts go negative?

    What entering the Maximum Days and Downloads. using:
    Expiry days: (0 = unlimited)

    will allow you to have a limit on how many downloads but not limit how many days those downloads are available ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  5. #5
    Join Date
    May 2016
    Location
    St. John's NL Canada
    Posts
    28
    Plugin Contributions
    0

    Default Re: Has anyone had download counts go negative?

    Ajeh,

    That is what the comments in the code say it will do, but that is not, what in fact, the code does.

    I checked on our live site and if the expiry days is zero (which we have for ALL downloads), when a person goes into his account to re-download, the order shows with a "Remaining" value of "--- *** ---"

    Here is the code from includes/templates/template_default/templates/tpl_modules_downloads.php (reformatted to clarify the nesting of parentheses):

    First the comments, which come further down in the code:

    Code:
    // The link will appear only if:
    // - Download remaining count is > 0, AND
    // - The file is present in the DOWNLOAD directory, AND EITHER
    // - No expiry date is enforced (maxdays == 0), OR
    // - The expiry date is not reached
    Code:
    $is_downloadable = (
        (file_exists(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename'])
            && 
        (
            ($downloads->fields['download_count'] > 0 && $download_timestamp > time())
                || 
            $downloads->fields['download_maxdays'] == 0
            )
        )
    ) ? true : false;

    Here is the code I use (which is a straightforward translation of the comments into code):

    Code:
    $is_downloadable =
    (
    	(	file_exists(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename']) &&
    		(	$downloads->fields['download_count'] > 0 &&
    			(	
    				$download_timestamp > time() ||
    				$downloads->fields['download_maxdays'] == 0
    			)
    		)
    	)
    ) ? true : false;

  6. #6
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Has anyone had download counts go negative?

    Okay ... I get unlimited downloads when I go beyond the count that is set say to 5 and I have downloaded ore than 5 times ...

    What do you want the count to do if you set it to unlimited and the downloads go beyond the number set?

    If you do not want to see a negative number you could set it higher, right now it is counting the total downloads by subtracting against the number that you set ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  7. #7
    Join Date
    May 2016
    Location
    St. John's NL Canada
    Posts
    28
    Plugin Contributions
    0

    Default Re: Has anyone had download counts go negative?

    IF one were able to set the Download count to unlimited, then it could never go negative. However, there is NO UNLIMITED DOWNLOAD setting, only an UNLIMITED TIME. I do not want one of those settings to imply anything about the other.

    If you want to have a limited time and unlimited downloads during that time, then set the count to 99,999 or some other very high number (or 999,999 or whatever the limit is). I however, want to have limited downloads and unlimited time.

    The issue is the way Zen Cart originally implemented Allowed Time and Allowed Downloads. Rather than starting the count (for a given order's download) at the maximum allowed number and then counting down and comparing to see if it has hit zero, a better way would to start the count at zero and increment for each download, comparing it against the maximum allowed.

    That has a couple of benefits:
    • Using a maximum of zero would mean unlimited downloads, much like using zero for the allowed time
    • One could change the maximum allowed downloads and nothing would break. If you increased the maximum, everyone would get the benefit of this (versus doing that in the current setup); if you decreased the maximum allowed, it would similarly affect everyone (some might already have exceeded the new max.)


    And it is a trivial subtraction to see how many downloads remain.

    Just my opinion.

 

 

Similar Threads

  1. Anyone had this happen with Checkout by Amazon?
    By fatiga in forum Addon Payment Modules
    Replies: 1
    Last Post: 12 Aug 2011, 09:32 AM
  2. Replies: 5
    Last Post: 22 Feb 2008, 09:32 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR