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

Restrict Digital Downloads [Support Thread]

Views: 10,146

Results 21 to 40 of 113
16 Dec 2014, 9:05 PM
#21
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Restrict Digital Downloads [Support Thread]

You're welcome, I think.

But I'm also thinking that in order to have an alternative choice for the digital download for the EU customers, at least a second attribute should be required for the choice of "Email the file to me" instead of the automated download.

That would be a "my problem" not a lat9 problem to resolve? OR attribute to add?

OK, I will hold off wiping the sandbox.

16 Dec 2014, 9:37 PM
#22
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,086
Plugin Contributions:
56

Re: Restrict Digital Downloads [Support Thread]

RixStix:

You're welcome, I think.

But I'm also thinking that in order to have an alternative choice for the digital download for the EU customers, at least a second attribute should be required for the choice of "Email the file to me" instead of the automated download.

That would be a "my problem" not a lat9 problem to resolve? OR attribute to add?

OK, I will hold off wiping the sandbox.
I'll go for a "combined" problem. I believe that you should offer your customers an alternative-delivery choice, but the plugin should be bullet-proof.

18 Dec 2014, 1:57 PM
#23
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,086
Plugin Contributions:
56

Re: Restrict Digital Downloads [Support Thread]

My internet access has been funky; I ***thought ***that I'd posted the corrections that are included in the (just uploaded) v1.0.1.:blush:

Anyway, here are the two files that are changed in that version. First /includes/extra_cart_actions/restrict_digital_downloads.php:

// -----
// Part of the "Restrict Digital Downloads" plugin
// 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) {
      $the_options = array ();
      if (isset($_POST['id']) && is_array($_POST['id'])) {
        $the_options = $_POST['id'];
        
      }
      if (isset ($_POST['download_options']) && is_array ($_POST['download_options'])) {
        foreach ($_POST['download_options'] as $option => $value) {
          if (!isset ($the_options[$option])) {
            $the_options[$option] = $value;
            
          }
        }
      }
      foreach ($the_options 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;
  }
}

Secondly, /includes/templates/YOUR_TEMPLATE/{product_type}/extra_main_template_vars/restrict_digital_downloads.php:

<?php
// -----
// Part of the "Restrict Digital Downloads" plugin
// Copyright (c) 2014 Vinos de Frutas Tropicales
//
// NOTE:  $products_options_names, $options_menu and $order_by are previously set by /includes/modules/attributes.php's processing.
//
if (isset ($_SESSION['is_restricted_ip']) && isset ($products_options_names)) {
  $products_options_names->Move (0);
  $products_options_names->MoveNext ();  //-Rewind the object to the beginning
  
  $download_selectors = '';
  $downloads_present = false;
  $option_count = 0;
  while (!$products_options_names->EOF) {
    $options_id = (int)$products_options_names->fields['products_options_id'];
    $products_options = $db->Execute ("SELECT pov.products_options_values_id, pov.products_options_values_name, pa.*
                                         from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov
                                        where pa.products_id = '" . (int)$_GET['products_id'] . "'
                                          and pa.options_id = '$options_id'
                                          and pa.options_values_id = pov.products_options_values_id
                                          and pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " . $order_by);
    $option_has_download = false;
    while (!$products_options->EOF) {
      $options_values_id = $products_options->fields['options_values_id'];
      $download_check = $db->Execute ("SELECT products_attributes_id FROM " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " WHERE products_attributes_id = " . $products_options->fields['products_attributes_id'] . " LIMIT 1");
      if (!$download_check->EOF) {
        $option_has_download = true;
        $downloads_present = true;
        $products_options_type = zen_get_attributes_type ($products_options->fields['products_attributes_id']);
        switch ($products_options_type) {
          case PRODUCTS_OPTIONS_TYPE_SELECT: {
            $download_selectors .= (($products_options->RecordCount ()) == 1) ? ('#attrib-' . $options_id . '-' . $options_values_id . ', ') : ('#attrib-' . $options_id . ' option[value="' . $options_values_id . '"], ');
            break;
          }
          case PRODUCTS_OPTIONS_TYPE_RADIO: {
            $download_selectors .= '#attrib-' . $options_id . '-' . $options_values_id . ', ';
            break;
          }
          default: {
            break;
          }
        }
      }
      if ($option_has_download && $products_options->RecordCount () == 1 && $products_options_type != PRODUCTS_OPTIONS_TYPE_CHECKBOX) {
        $options_menu[$option_count] .= zen_draw_hidden_field ("download_options[$options_id]", $options_values_id);
        
      }
      $products_options->MoveNext ();
      
    }
    $option_count++;
    $products_options_names->MoveNext ();
    
  }
  if ($downloads_present != '') {
    $messageStack->add ('product_info', PRODUCT_MESSAGE_DOWNLOAD_PRODUCT_RESTRICTED, 'caution');
    
  }
  if ($download_selectors != '') {
    $download_selectors = substr ($download_selectors, 0, -2);  //-Strip trailing ', '
?>
<script type="text/javascript">
$(document).on ('ready', function(){
  $('<?php echo $download_selectors; ?>').each(function(){
    $(this).removeAttr( 'selected checked' );
    $(this).attr( 'disabled', 'disabled' );
  });
});
</script>
<?php
  }
}
18 Dec 2014, 3:15 PM
#24
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

TNX lat9

I know funky internet :smile:. I'm lucky we have not had snow yet. Snow on the mountaintops usually plays havoc with our 1MB connection.

I don't see any difference in functionality other than no MyDebug logs are generated.

I get the yellow warning banner but am still able to add the product to the cart and complete the checkout.

I have not changed any product details, nor have I added an attribute for a non-pdf choice.

Before I wipe the sandbox and test with my database/product setup without any plugins or responsive template, do you have a specific downloadable product w/attributes setup example that I could use to generate a new product within the catalog for testing.

18 Dec 2014, 3:44 PM
#25
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,086
Plugin Contributions:
56

Re: Restrict Digital Downloads [Support Thread]

I've got an option (radio-button) named "Delivery Method" that has two option values: I'll download it and Email it to me. I apply those two option/value pairs via the Attributes Controller to my downloads (the I'll download it option has the download file associated).

If the responsive template you're using is one of Picaflor-Azul's, she's got a tendency to mis-code calls to get_template_dir like this:

<script src="<?php echo $template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,'jscript') . '/back_to_top.min.js'; ?>" type="text/javascript"></script>

where the proper coding is

<script src="<?php echo $template->get_template_dir('back_to_top.min.js',DIR_WS_TEMPLATE, $current_page_base,'jscript') . '/back_to_top.min.js';  ?>" type="text/javascript"></script>

I ran into that gotcha in another customization that I created that uses the template-override method used by RDD.

18 Dec 2014, 4:37 PM
#26
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

I'm gonna have to wipe everything and start from scratch.

Yes I am using one of Anne's templates. Made the edit for get_template.

Create new temp digital download product category
Create new product within that category
Add attribute for download pdf file and associate a pdf to that attribute
Add attribute for "Email the file to me"
attribute option type is "Checkbox" (a couple products contain multiple download files)
Is the checkbox the source of my headache?

I get the yellow alert message but am still able to add the product to the cart regardless of chosen attribute.

Checkout and receive the download link immediately.

DarN. It may be a day or two before I have the time to start from scratch. Physical Christmas orders are a bit more pressing.

18 Dec 2014, 5:14 PM
#27
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

How dumb can a person feel?
Can I claim a "DUH" moment?

Repeat after me a kazillion times....

Radio, Radio, Radio. NOT checkbox, NOT checkbox, NOT checkbox.

Our initial reason for using checkbox is that we have a couple products which have 2 or more pdf associated with the product.
More reason for me to redo things.

Things appear to work when I use the proper setup. Says he with egg completely covering face.

18 Dec 2014, 5:41 PM
#28
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,086
Plugin Contributions:
56

Re: Restrict Digital Downloads [Support Thread]

When the product was using a checkbox attribute, was it that the product (without the checkbox-option) was added to the cart? I tested using a checkbox-type attribute, thinking that there might be a product that could be either physical (unchecked) or virtual (checked).

18 Dec 2014, 6:15 PM
#29
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

lat9:

When the product was using a checkbox attribute, was it that the product (without the checkbox-option) was added to the cart? I tested using a checkbox-type attribute, thinking that there might be a product that could be either physical (unchecked) or virtual (checked).

download file attribute can be added to cart if checked, regardless of warning.

product with no checkbox selected can be added to cart
product with download attribute selected can be added to cart
product with "email it to me" attribute selected can be added to cart

19 Dec 2014, 12:59 PM
#30
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,086
Plugin Contributions:
56

Re: Restrict Digital Downloads [Support Thread]

Can you post or PM a link?

19 Dec 2014, 2:08 PM
#31
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

http://chainweavers (dot) info/ZEN153/index.php?main_page=product_info&cPath=155&products_id=875

19 Dec 2014, 3:48 PM
#32
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,086
Plugin Contributions:
56

Re: Restrict Digital Downloads [Support Thread]

OK, so there's still something funny going on with the checkbox-type options. What happens if you "convert" that option to a radio-button (especially since the checkbox-type option values are independent)?

19 Dec 2014, 4:19 PM
#33
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

lat9:

What happens if you "convert" that option to a radio-button (especially since the checkbox-type option values are independent)?

Functions as expected.
pdf attribute cannot be added to cart.
email me attribute can be added to cart.

I don't think it is worth your time to worry with the checkbox optiontype. We only used checkbox because one product contains more than one download file and it was easiest (at the time) to use checkbox attributes than to futz with something different.

19 Dec 2014, 9:24 PM
#34
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,086
Plugin Contributions:
56

Re: Restrict Digital Downloads [Support Thread]

I'll still play with the checkbox processing (it bugs me that it's not working), but I'll lower its pr

24 Dec 2014, 6:59 PM
#35
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

TNX for everything Cindy

Our accountant indicated that the logic of this plugin is sufficient for our business.

When I was asked for statutory examples of how the EU expects to enforce within the USA, I could provide none; so I was also told the advice may change if/when anyone finds those specifics.

24 Dec 2014, 7:18 PM
#36
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,086
Plugin Contributions:
56

Re: Restrict Digital Downloads [Support Thread]

Happy to help, Rick.

27 Dec 2014, 10:11 PM
#37
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

HELP. I must have done something stupid when uploading to the live site but have not been able to find it after a couple hours.

I just uploaded the files to my live site.
Edited/merged the tpl_footer
updated the IP2location csv

In my sandbox, I had edited
/YOUR_ADMIN/includes/extra_datafiles/ip2country_file_database_admin_names.php

by inserting US into the string for testing.

I did not do this on my live site but checked that file to make sure that US was not included in the string.

My home IP receives the yellow warning.
If I select the alternate delivery method attribute, I can add the item to the cart.

the only log file generated is

[27-Dec-2014 13:48:51 America/Los_Angeles] #1  sprintf() called at [/home/XXXXXXXX/public_html/niahc/tools_update_ip2country.php:57]

which you said to ignore

I'm still looking for my OOPS but if you have any ideas, I'm all ears.

27 Dec 2014, 10:24 PM
#38
rixstix avatar

rixstix

Totally Zenned

Join Date:
Aug 2009
Location:
North Idaho, USA
Posts:
2,015
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

Just downloaded 1.0.1 and used that fileset instead of the original files.

same result.

Also, digital downloads which are no charge/free receive the yellow alert.

28 Dec 2014, 1:26 PM
#39
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,086
Plugin Contributions:
56

Re: Restrict Digital Downloads [Support Thread]

Arggh, yet-another update to /includes/init_includes/init_restrict_digital_downloads.php. The $customers_ip_address variable was not set until ***after ***the auto-load processing. If you've got an active session (since the restriction is set into a session variable), you'll need to delete the ***zenid ***cookie set for your site to verify.

<?php
// -----
// Part of the "Digital Download Restrictions" plugin by lat9
// Copyright (c) 2014 Vinos de Frutas Tropicales
//

function is_digital_download ($products_id, $options_id, $options_value_id) {
  global $db;
  
  $sql = "SELECT pa.products_id FROM " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
          WHERE pa.products_id = " . (int)$products_id . "
            AND   pa.options_id = " . (int)$options_id . "
            AND   pa.options_values_id = " . (int)$options_value_id . "
            AND   pa.products_attributes_id = pad.products_attributes_id LIMIT 1";
  $sql_result = $db->Execute($sql);

  return ($sql_result->EOF) ? false : true;
  
}

$ipv4_address_check = filter_var ($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
if (!$ipv4_address_check) {
  $is_restricted_ip = true;
  
} else {
  $ipv4_quads = explode ('.', $_SERVER['REMOTE_ADDR']);
  $ipv4_integer = $ipv4_quads[3] + $ipv4_quads[2] * 256 + $ipv4_quads[1] * 256 * 256 + $ipv4_quads[0] * 256 * 256 * 256;
  
  $ipv4_check = $db->Execute ("SELECT * FROM " . TABLE_IP2COUNTRY . " WHERE ip_from <= $ipv4_integer AND ip_to >= $ipv4_integer LIMIT 1");
  $is_restricted_ip = !($ipv4_check->EOF);
}
if ($is_restricted_ip) {
  $_SESSION['is_restricted_ip'] = $is_restricted_ip;
}

For your free downloads, are they set with the "Product is free" flag?

28 Dec 2014, 1:56 PM
#40
adb34 avatar

adb34

Totally Zenned

Join Date:
Mar 2008
Location:
Brampton, Cumbria, United Kingdom, United Kingdom
Posts:
825
Plugin Contributions:
0

Re: Restrict Digital Downloads [Support Thread]

This plugin will be very useful when the new EEC rules for VAT come in to play 1st January 2015. http://www.grant-thornton.co.uk/Global/Publication_pdf/VAT-changes-in-2015.pdf Not my site, worth a read. Do not fall in to the trap