Page 1 of 5 123 ... LastLast
Results 1 to 10 of 48
  1. #1
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,478
    Plugin Contributions
    88

    Default Limit Quantities for Downloads and Virtual Products [Support Thread]

    I've just submitted v1.1.0 of this plugin to the Zen Cart Plugins for review ...

    If your store has downloadable and/or virtual products, it's possible -- depending on your configuration -- for a customer to add multiple copies of the product to their cart. The customer can go through checkout confirmation, paying for the quantity present in their cart ... but when it comes to the download itself, only one copy is available for the customer to download.

    Downloadable/virtual products can fall into three different customization types:
    1. The product is configured with a single attribute, e.g. one that specifies the download filename. For this type of product, you can use the built-in Zen Cart methods to limit the product to a single instance in a customer's cart. Use your admin's Catalog->Categories/Products and set:
      • Product Qty. Minimum to 1
      • Product Qty. Maximum to 1
      • Product Qty. Units to 1
    2. The product can be purchased either as a download or as a physical (e.g. printed) item. For this type of product, you probably want to allow multiple copies of the physical product to be placed into a customer's cart. Unfortunately, with this configuration the customer can also place multiple copies of the download version of the product in his/her cart ... possibly resulting in charge-back issues for your store.
    3. The downloadable/virtual product has multiple configurations, i.e. more than one attribute. For example, the product might be available in more than one language or in different file formats. The customer should be able to have different configurations of the product in his/her cart, but limited to a single instance for a specific attribute combination.


    This plugin addresses customization types 2 and 3 described above and can be downloaded from: http://www.zen-cart.com/downloads.php?do=file&id=1018

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

    Default Re: Limit Quantities for Downloads and Virtual Products [Support Thread]

    I was peeking at this add-on, as you referenced it today on another thread, and it naturally grabbed my interest ... and I thought isn't this a nifty little add-on ...

    It also is making me think about fun things for future updates of Zen Cart ...

    But in testing it, I was running into things like when adding to the cart for the first time, and I try adding quantity 5, it would do that and only catch the need to fix the quantity to 1 if I then hit Update on the shopping cart or tried to add more to the cart the second time around, triggering the case for the update_product ...

    I tried this on v1.5.1 and upcoming v1.5.2 and v1.6 with the same issue ...

    Now I am not setting the Maximum to 1, but leaving it at 0, as I wanted a simple way to prevent the multiple order of quantity > 1 and also to not show that Max:1, I rather hate that at times, and keep the quantity box for Products that were Download/Physical based on the Attribute selected ...

    So in fooling with this a bit further, I altered the case on add_product and changed it to:
    Code:
      case 'add_product':
        if (isset($_POST['products_id']) && $_POST['cart_quantity'] > 0) {
          if (isset($_POST['id']) && $_SESSION['cart']->in_cart(zen_get_uprid($_POST['products_id'], $_POST['id']))) {
            foreach($_POST['id'] as $option => $value) {
              if (ldProductIsDownload ($_POST['products_id'], $option, $value)) {
                $messageStack->add_session('header', sprintf(ERROR_MAXIMUM_DOWNLOADS, zen_get_products_name($_POST['products_id'])), 'caution');
                zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
              } else {
              }
            }
          } else {
            foreach($_POST['id'] as $option => $value) {
              if (ldProductIsDownload ($_POST['products_id'], $option, $value) && $_POST['cart_quantity'] > 1) {
                $messageStack->add_session('header', sprintf(ERROR_MAXIMUM_DOWNLOADS, zen_get_products_name($_POST['products_id'])), 'caution');
                $_POST['cart_quantity'] = 1;
              } else {
              }
            }
          }
        }
      break;
    Now is it just in my testing that I am not fully understanding what you are doing here or did you write this with the understanding that all Download Products would be set to Max 1, even when there was also the alternative of offering things like Download on one Attribute and the CD on another ... or am I perhaps missing something on your intent ...
    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!

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,478
    Plugin Contributions
    88

    Default Re: Limit Quantities for Downloads and Virtual Products [Support Thread]

    Hmm, I'm not seeing that behavior when I choose 5 downloadable patterns on my needlework site. I've got min/max/units set to 1/0/1, respectively for the product. I also have "show the cart after add-to-cart" (or whatever that setting is), so when I add 5 to the cart I get the cart displayed with 1 item and a message " A downloadable product — <product name> — was not added to your cart. Your cart can hold at most one download of each product." displayed at the top of the shopping_cart page.

    Let me see what's up ...

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

    Default Re: Limit Quantities for Downloads and Virtual Products [Support Thread]

    What version(s) are you testing in?

    Also I may have 1 bug to work out on that add_product as I am getting on some versions the debug log message that could be due to customizations I am working on or an actually issue with this add-on and my code change ...

    But let me know what you run into ...

    My tests are based on the Download Products in the Demo data for:
    /index.php?main_page=product_info&cPath=54_60&products_id=133
    /index.php?main_page=product_info&cPath=54_60&products_id=179
    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
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,478
    Plugin Contributions
    88

    Default Re: Limit Quantities for Downloads and Virtual Products [Support Thread]

    I was testing on the original version of the plugin (the not-so-smart one). I've replicated the issue and am working towards a solution using some of the code fragments you provided ...

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

    Default Re: Limit Quantities for Downloads and Virtual Products [Support Thread]

    Ahh! Good ... not my imagination ... hopefully you come up with a better fix and/or one that does not trip this debug error that I have ... hopefully that is just something I am doing in updating code or something fun ...
    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
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,478
    Plugin Contributions
    88

    Default Re: Limit Quantities for Downloads and Virtual Products [Support Thread]

    Try this for the replacement for the add_product clause (it worked by me!). Essentially, I restructured the clause to first check to see if there's a download among the options and, if so, check to see if there's an instance already in the cart (in which case a redirect to the goto page occurs with no additional cart processing) or if there's not to reduce the quantity to 1 (with message) and let the base add_product processing perform its magic.
    Code:
      /*---- Add a product to cart ----
      **
      ** If a product is being added to the cart (with a quantity greater than 0) and that product has attributes (the $_POST['id'] array
      ** is set), then if either that product is already in the cart -OR- if the quantity to be added is greater than 1,
      ** 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':
    //-bof-v1.1.1c
        if (isset($_POST['products_id']) && $_POST['cart_quantity'] > 0 && isset($_POST['id']) && is_array($_POST['id'])) {
          foreach($_POST['id'] as $option => $value) {
            if (ldProductIsDownload ($_POST['products_id'], $option, $value)) {
              if ($_SESSION['cart']->in_cart(zen_get_uprid($_POST['products_id'], $_POST['id']))) {
                $messageStack->add_session('header', sprintf(ERROR_MAXIMUM_DOWNLOADS, zen_get_products_name($_POST['products_id'])), 'caution');
                zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
                
              } elseif ($_POST['cart_quantity'] > 1) {
                $_POST['cart_quantity'] = 1;
                $messageStack->add_session('header', sprintf(ERROR_MAXIMUM_DOWNLOADS, zen_get_products_name($_POST['products_id'])), 'caution');
                
              }
              break;
            }
          }
        }
    //-eof-v1.1.1c
      break;
    :

  8. #8
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,478
    Plugin Contributions
    88

    Default Re: Limit Quantities for Downloads and Virtual Products [Support Thread]

    Nope, it's close but not perfect. If the virtual/downloadable product includes a text attribute, the in_cart check indicates that the product's not in the cart ... when it is! That's because there's a mismatch between the uprid returned by the zen_get_uprid call and that present in the cart (due to the text attribute's value).

    Still investigating ...

  9. #9
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,478
    Plugin Contributions
    88

    Default Re: Limit Quantities for Downloads and Virtual Products [Support Thread]

    Holy cr@p! I don't understand why this works and the previous version didn't, but it does. The uprid calculated by limit_downloads wasn't matching that present in the shopping_cart, so the in_cart test was failing. The values present in the $_POST['id'] array were identical to those present in the $attributes array processed by the shopping cart, the only difference is that a copy of the $_POST values was used. Making that modification magically makes the operation work properly.

    I'm not a big fan of magic when it comes to code; if anyone can shed some light on why the updated version works while the previous version doesn't, I'd appreciate it!
    Code:
      /*---- Add a product to cart ----
      **
      ** If a product is being added to the cart (with a quantity greater than 0) and that product includes attributes (the $_POST['id'] array
      ** is set), then if either that product is already in the cart -OR- if the quantity to be added is greater than 1,
      ** 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':
    //-bof-v1.1.1c
        if (isset($_POST['products_id']) && $_POST['cart_quantity'] > 0 && isset($_POST['id']) && is_array($_POST['id'])) {
          $the_ids = $_POST['id'];
          foreach($_POST['id'] as $option => $value) {
            if (ldProductIsDownload ($_POST['products_id'], $option, $value)) {
              if ($_SESSION['cart']->in_cart(zen_get_uprid($_POST['products_id'], $the_ids))) {
                $messageStack->add_session('header', sprintf(ERROR_MAXIMUM_DOWNLOADS, zen_get_products_name($_POST['products_id'])), 'caution');
                zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
                
              } elseif ($_POST['cart_quantity'] > 1) {
                $_POST['cart_quantity'] = 1;
                $messageStack->add_session('header', sprintf(ERROR_MAXIMUM_DOWNLOADS, zen_get_products_name($_POST['products_id'])), 'caution');
                
              }
              break;
            }
          }
        }
    //-eof-v1.1.1c
      break;

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

    Default Re: Limit Quantities for Downloads and Virtual Products [Support Thread]

    It works on the 1st time you add from the Product page but if you go to the Product page again and do the add you continue to be able to get an additional Product in the cart ...

    To replicate this, you need to be adding a Download Product that has 2 downloads like the Demo Product for:
    /index.php?main_page=product_info&cPath=54_60&products_id=133
    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!

 

 
Page 1 of 5 123 ... LastLast

Similar Threads

  1. v154 All Products Virtual -- No Shipping [Support Thread]
    By lat9 in forum All Other Contributions/Addons
    Replies: 16
    Last Post: 22 Jul 2019, 12:04 PM
  2. v153 Restrict Digital Downloads [Support Thread]
    By lat9 in forum All Other Contributions/Addons
    Replies: 112
    Last Post: 19 Jan 2016, 05:46 PM
  3. v154 Email Downloads Support Thread
    By swguy in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 17 Jun 2015, 06:41 PM
  4. v151 Virtual Agent ASKOM Support Thread
    By askom in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 3 Apr 2014, 09:13 AM
  5. difference between downloads and virtual products
    By artcoder in forum General Questions
    Replies: 2
    Last Post: 20 Feb 2008, 11:42 PM

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