Forums / All Other Contributions/Addons / Restrict Digital Downloads [Support Thread]

Restrict Digital Downloads [Support Thread]

Results 1 to 20 of 113
11 Dec 2014, 14:45
#1
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Restrict Digital Downloads [Support Thread]

You've got a Zen Cart® store that currently delivers automatic digital downloads to your customers and you'd like to restrict the delivery of those automatic downloads based on a specific list of countries. This plugin (RDD) inspects the IPv4 address of a customer that "arrives" at your store, determines if their IP address is associated with a restricted country and, if so, disables any digital-download product options.

I'll post the Plugins area download link once I've received it; RDD will be available for download upon approval.

Plugin download link: http://www.zen-cart.com/downloads.php?do=file&id=1933
14 Dec 2014, 16:49
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Re: Restrict Digital Downloads [Support Thread]

RDD is now available for download.
14 Dec 2014, 16:51
#3
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

Thank you lat9 for this plugin.

It is probably a short circuit between the ears but I have read the instructions several times.
I assumed that to test the functionality, a person just adds US into the string of countries in

/YOUR_ADMIN/includes/extra_datafiles/ip2country_file_database_admin_names.php

update the IP2location csv
attempt to add a product which contains a download file (pdf) to the cart.

That must have been a wrong assumption because I can navigate to a downloadable product page and add it to the cart without receiving a message.
Any pointers appreciated.

As you indicated, the IP2location database table is 1.8Mb and contains 64,500 rows, though the data does not resemble an IP address.

I'm working in my sandbox
zc 1.5.3
php 5.3.28 (sandbox) prod 5.4.35
MySQL 5.5.40-cll (sandbox & prod)
template: picafluor-azul westminster_new responsive

chainweavers (d.o.t) info/ZEN153/

could it be related to document_product_info page instead of product_info page?

TNX again.

EDIT: answered my own question by duplicating the product_info folder as document_product_info.
I do see that there needs to be something done to product attributes to provide an alternate selection or some path for a user to choose.

Sorry that I didn't exercise all my thinking powers before asking a question
14 Dec 2014, 17:00
#4
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

I get the yellow notice but nothing is preventing the item from being added to cart, so I must need to do something in addition to just creating the document_product_info file.
14 Dec 2014, 19:35
#5
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Re: Restrict Digital Downloads [Support Thread]

RixStix, you got the first bit right. The plugin includes support for product_info and product_music_info product types; to replicate for another (like document_product_info), you simply copy /includes/templates/YOUR_TEMPLATE/product_info (and all its files) to /includes/templates/YOUR_TEMPLATE/document_product_info (in your case).

There are some jQuery issues, at least on http://chainweavers (dot) info/ZEN153/index.php?main_page=document_product_info&cPath=22_138&products_id=776 so that the script associated with RDD is not run. You'll notice that your "Back to Top" widget isn't showing either.

I'm puzzled why the "backup" script (in the /extra_cart_actions folder) isn't kicking in, though.
14 Dec 2014, 20:44
#6
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

TNX lat9

Removing the newly created /includes/templates/YOUR_TEMPLATE/document_product_info folder restores functionality to the "Back to TOP" widget (which was broken on all product_info pages (that I checked), not just digitaldownload pages. The only file in that folder is the RDD file.

I'm going out on a limb and guessing that things are somehow related to the responsive template functionality.

I'll install a vanilla template tomorrow and see what happens.
14 Dec 2014, 20:53
#7
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

Does this suggest anything?

[14-Dec-2014 08:13:05 America/Los_Angeles] PHP Warning:  sprintf(): Too few arguments in /home/XXXXXXXX/public_html/ZEN153/ADMIN_folder/tools_update_ip2country.php on line 57
14 Dec 2014, 21:33
#8
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Re: Restrict Digital Downloads [Support Thread]

RixStix:

Does this suggest anything?

[14-Dec-2014 08:13:05 America/Los_Angeles] PHP Warning:  sprintf(): Too few arguments in /home/XXXXXXXX/public_html/ZEN153/ADMIN_folder/tools_update_ip2country.php on line 57

Nope. I just need to update the following statement in /YOUR_ADMIN/includes/languages/english/tools_update_ip2country.php:
define ('MESSAGE_NUM_RECORDS', 'Processing complete. %u records were added to the ' . TABLE_IP2COUNTRY . ' database table in %u seconds.');

to
define ('MESSAGE_NUM_RECORDS', 'Processing complete. %u records were added to the ' . TABLE_IP2COUNTRY . ' database table.');
14 Dec 2014, 21:39
#9
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Re: Restrict Digital Downloads [Support Thread]

You could try editing /includes/extra_cart_actions/restrict_digital_downloads.php, adding (temporarily) the code in red. That will at least give us a clue as to what's going on:
// -----
// Part of the "Restrict Digital Downloads" plugin by Cindy Merkin ([email protected])
// Copyright (c) 2014 Vinos de Frutas Tropicales
//
switch ($_GET['action']) {
  /*----
  ** If a product is being added to the cart and that product includes attributes (the $_POST['id'] array
  ** is set), then check each of the attributes being added to see if there is a download/virtual product amongst them.  If so,
  ** don't allow the duplicate download/virtual product to be added to the cart ... or just add 1 if this is the original add.
  */
  case 'add_product': {
    error_log (__FILE__ . ':' . print_r ($_POST, true));
    if ($_SESSION['is_restricted_ip'] && isset($_POST['products_id']) && $_POST['cart_quantity'] > 0 && isset($_POST['id']) && is_array($_POST['id'])) {
      foreach($_POST['id'] as $option => $value) {
        if (is_digital_download ($_POST['products_id'], $option, $value)) {
          $messageStack->add ('header', sprintf (CART_MESSAGE_DOWNLOAD_PRODUCT_RESTRICTED, zen_get_products_name ($_POST['products_id'])), 'caution');
          unset ($_GET['action']);
          break;

        }
      }
    }
    break;
  }
}
14 Dec 2014, 23:00
#10
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

[14-Dec-2014 14:56:50 America/Los_Angeles] /home/XXXXXXXX/public_html/ZEN153/includes/extra_cart_actions/restrict_digital_downloads.php:Array
(
    [securityToken] => Not sure if it is OK to post that
    [cart_quantity] => 1
    [products_id] => 776
    [id] => Array
        (
            [6] => Array
                (
                    [61] => 61
                )

        )

)
16 Dec 2014, 13:37
#11
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Re: Restrict Digital Downloads [Support Thread]

If you move that error_log statement, do you still get the log?
// -----
// Part of the "Restrict Digital Downloads" plugin by Cindy Merkin ([email protected])
// Copyright (c) 2014 Vinos de Frutas Tropicales
//
switch ($_GET['action']) {
  /*----
  ** If a product is being added to the cart and that product includes attributes (the $_POST['id'] array
  ** is set), then check each of the attributes being added to see if there is a download/virtual product amongst them.  If so,
  ** don't allow the duplicate download/virtual product to be added to the cart ... or just add 1 if this is the original add.
  */
  case 'add_product': {
    if ($_SESSION['is_restricted_ip'] && isset($_POST['products_id']) && $_POST['cart_quantity'] > 0 && isset($_POST['id']) && is_array($_POST['id'])) {
      error_log (__FILE__ . ':' . print_r ($_POST, true));
      foreach($_POST['id'] as $option => $value) {
        if (is_digital_download ($_POST['products_id'], $option, $value)) {
          $messageStack->add ('header', sprintf (CART_MESSAGE_DOWNLOAD_PRODUCT_RESTRICTED, zen_get_products_name ($_POST['products_id'])), 'caution');
          unset ($_GET['action']);
          break;

        }
      }
    }
    break;
  }
}
16 Dec 2014, 14:42
#12
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

lat9:

If you move that error_log statement, do you still get the log?


yes, the log is generated with similar content.
16 Dec 2014, 15:45
#13
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Re: Restrict Digital Downloads [Support Thread]

This is (obviously) kicking my bu++. How about this edit:
// -----
// Part of the "Restrict Digital Downloads" plugin by Cindy Merkin ([email protected])
// Copyright (c) 2014 Vinos de Frutas Tropicales
//
switch ($_GET['action']) {
  /*----
  ** If a product is being added to the cart and that product includes attributes (the $_POST['id'] array
  ** is set), then check each of the attributes being added to see if there is a download/virtual product amongst them.  If so,
  ** don't allow the duplicate download/virtual product to be added to the cart ... or just add 1 if this is the original add.
  */
  case 'add_product': {
    if ($_SESSION['is_restricted_ip'] && isset($_POST['products_id']) && $_POST['cart_quantity'] > 0 && isset($_POST['id']) && is_array($_POST['id'])) {
       foreach($_POST['id'] as $option => $value) {
        error_log ('rdd add_product:  products_id = ' . $_POST['products_id'] . ", options_id = $option, value_id = $value, is_digital_download = " . ((is_digital_download ($_POST['products_id'], $option, $value)) ? 'Yes' : 'No'));
        if (is_digital_download ($_POST['products_id'], $option, $value)) {
          $messageStack->add ('header', sprintf (CART_MESSAGE_DOWNLOAD_PRODUCT_RESTRICTED, zen_get_products_name ($_POST['products_id'])), 'caution');
          unset ($_GET['action']);
          break;

        }
      }
    }
    break;
  }
}
16 Dec 2014, 15:54
#14
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

Different logfile

[16-Dec-2014 07:52:38 America/Los_Angeles] rdd add_product:  products_id = 776, options_id = 6, value_id = Array, is_digital_download = No
16 Dec 2014, 16:14
#15
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Re: Restrict Digital Downloads [Support Thread]

Arggh, I should have seen that before. Do you have a customized /includes/modules/YOUR_TEMPLATE/attributes.php? For a 'out-of-the-box' Zen Cart attributes.php, the 'id' value will come back as an array in options_id => options_values_id format, like the following:
[14-Dec-2014 14:56:50 America/Los_Angeles] /home/XXXXXXXX/public_html/ZEN153/includes/extra_cart_actions/restrict_digital_downloads.php:Array
(
    [securityToken] => Not sure if it is OK to post that
    [cart_quantity] => 1
    [products_id] => 776
    [id] => Array
        (
            [6] => 61
 
        )

)
16 Dec 2014, 16:52
#16
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

lat9:

Arggh, I should have seen that before. Do you have a customized /includes/modules/YOUR_TEMPLATE/attributes.php? For a 'out-of-the-box' Zen Cart attributes.php, the 'id' value will come back as an array in options_id => options_values_id format, like the following:


No, I do not. Searched using Developers Took Kit and didn't find anything by that name.

I did 'drop' the fileset into template_default instead of installing a vanilla template, did nothing on the admin side other than change template to classic_green.

Same result.

Work is calling my name so I'll be in and out for the next few hours.
16 Dec 2014, 18:31
#17
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Re: Restrict Digital Downloads [Support Thread]

There's got to be something different; I've tested this on a Zen Cart v1.5.1 and a Zen Cart v1.5.3 store and both stores log the 'id' variable as 'id'[options_id][values_id].
16 Dec 2014, 20:08
#18
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

Sorry I couldn't reply sooner. This forum does not play nice with Surface tablets which is my only access in the manufacturing room.

I was going to suggest that I wipe the sandbox and start from scratch instead of you tracking down ghosts or other unknowns.
16 Dec 2014, 20:10
#19
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

That is the format of the logfile prior to the last suggested edit.

includes/modules/attributes.php default file is being used.

It looks like your download product examples have more than a single attribute choice. Ours currently only have a single attribute. Any chance that is related?

lat9:

Arggh, I should have seen that before. Do you have a customized /includes/modules/YOUR_TEMPLATE/attributes.php? For a 'out-of-the-box' Zen Cart attributes.php, the 'id' value will come back as an array in options_id => options_values_id format, like the following:
[14-Dec-2014 14:56:50 America/Los_Angeles] /home/XXXXXXXX/public_html/ZEN153/includes/extra_cart_actions/restrict_digital_downloads.php:Array
(
    [securityToken] => Not sure if it is OK to post that
    [cart_quantity] => 1
    [products_id] => 776
    [id] => Array
        (
            [6] => 61
 
        )

)
16 Dec 2014, 20:42
#20
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Re: Restrict Digital Downloads [Support Thread]

RixStix:

That is the format of the logfile prior to the last suggested edit.

includes/modules/attributes.php default file is being used.

It looks like your download product examples have more than a single attribute choice. Ours currently only have a single attribute. Any chance that is related?

You nailed it! I've got this replicated now on my local test site and should have a correction by the morning. Thanks a bunch!