Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Apr 2010
    Posts
    232
    Plugin Contributions
    0

    Default Products Quantity not working

    Hi,

    I seem to be picking up a small problem on my site, www.watsonpublishers.com.

    When I go to the 1st category, and go to the 1st product, and on the product screen add 1 product and click Add to Cart, and then go to the second product and again add 1 product, in my cart I can see the two products with a quantity of 1 each. However, each of those products has been set that a customer cannot purchase more than 5 of each.

    Now the tricky part. When I try to update those quantities from 1 to 5 on the cart, I get error messages, as well as the quantities keep changing. In some cases I will change the one product quantity from 1 to 5, click Update Cart, then for 1 product I will have a quantity of 1, for the other the system adds 4. No matter what I do, I simply cannot seem to update the quantity on the shopping cart once I have added products. What is going wrong? Am I right in saying that if I can buy 5, I should be able to change my quantity on the cart from 1 to 5 without any problems?

  2. #2
    Join Date
    Apr 2010
    Posts
    232
    Plugin Contributions
    0

    Default Re: Products Quantity not working

    Just tested something else, when I add 5 of one product and then 5 of another, I have two products in my shopping cart, each with 5 items. I cannot seem to change these. If I try to reduce the quantity from 5 to 1 of any of the products, I get error messages. Can someone please help with this?

  3. #3
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    64,665
    Plugin Contributions
    6

    Default Re: Products Quantity not working

    There is a ... umm ... bug ...

    You can try this fix, but be careful with it ...

    What this will do is when there is a Maximum of 5 and you have 3 in the amount on the shopping cart, and try to change it to 7, it will change back to 3 with a warning ...

    If you try to add more from the product _info page, it will set the quantity to 5, with a warning ...

    Backup your original shopping cart class file first, then try to edit the file:
    /includes/classes/shopping_cart.php

    and change lines 1121 - 1134 to read:
    Code:
    // validate cart contents for checkout
            if ($check_for_valid_cart == true) {
              $fix_once = 0;
    
              // Check products_status if not already
              $check_status = $products->fields['products_status'];
              if ( $check_status == 0 ) {
                $fix_once ++;
                $_SESSION['valid_to_checkout'] = false;
                $_SESSION['cart_errors'] .= ERROR_PRODUCT . $products->fields['products_name'] . ERROR_PRODUCT_STATUS_SHOPPING_CART . '<br />';
                $this->remove($products_id);
              } else {
                if (isset($this->contents[$products_id]['attributes'])) {
                  reset($this->contents[$products_id]['attributes']);
                  $chkcount = 0;
                  while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
                    $chkcount ++;
                    $chk_attributes_exist_query = "select products_id
                                              from " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                                              where pa.products_id = '" . (int)$products_id . "'
                                              and pa.options_values_id = '" . (int)$value . "'";
    
                    $chk_attributes_exist = $db->Execute($chk_attributes_exist_query);
    //echo 'what is it: ' . ' : ' . $products_id . ' - ' . $value . ' records: ' . $chk_attributes_exist->RecordCount() . ' vs ' . print_r($this->contents[$products_id]) . '<br>';
                    if ($chk_attributes_exist->EOF) {
                      $fix_once ++;
                      $_SESSION['valid_to_checkout'] = false;
                      $_SESSION['cart_errors'] .= ERROR_PRODUCT_ATTRIBUTES . $products->fields['products_name'] . ERROR_PRODUCT_STATUS_SHOPPING_CART_ATTRIBUTES . '<br />';
                      $this->remove($products_id);
                      break;
                    }
                  }
                }
              }
    
              // check only if valid products_status
    Changes lines 1394 - 1424 to read:
    Code:
      function in_cart_mixed($products_id) {
        global $db;
        // if nothing is in cart return 0
        if (!is_array($this->contents)) return 0;
    
        // check if mixed is on
        //      $product = $db->Execute("select products_id, products_quantity_mixed from " . TABLE_PRODUCTS . " where products_id='" . (int)$products_id . "' limit 1");
        $product = $db->Execute("select products_id, products_quantity_mixed from " . TABLE_PRODUCTS . " where products_id='" . zen_get_prid($products_id) . "' limit 1");
    
        // if mixed attributes is off return qty for current attribute selection
        if ($product->fields['products_quantity_mixed'] == '0') {
          return $this->get_quantity($products_id);
        }
    
        // compute total quantity regardless of attributes
        $in_cart_mixed_qty = 0;
        $chk_products_id= zen_get_prid($products_id);
    
    // added for new code - Ajeh
    global $cart, $messageStack;
    
        // reset($this->contents); // breaks cart
        $check_contents = $this->contents;
        reset($check_contents);
        while (list($products_id, ) = each($check_contents)) {
          $test_id = zen_get_prid($products_id);
    //$messageStack->add_session('header', 'Product: ' . $products_id . ' test_id: ' . $test_id . '<br>', 'error');
          if ($test_id == $chk_products_id) {
    //$messageStack->add_session('header', 'MIXED: ' . $products_id . ' test_id: ' . $test_id . ' qty:' . $check_contents[$products_id]['qty'] . ' in_cart_mixed_qty: ' . $in_cart_mixed_qty . '<br><br>', 'error');
            $in_cart_mixed_qty += $check_contents[$products_id]['qty'];
          }
        }
    //$messageStack->add_session('header', 'FINAL: in_cart_mixed_qty: ' . 'PRODUCT: ' . $test_id . ' in cart:' . $in_cart_mixed_qty . '<br><br>', 'error');
    
        return $in_cart_mixed_qty;
      }
      /**
       * Method to calculate item quantity, bounded the mixed/min units settings
    Change lines 1532 - 1581 to read:
    Code:
      function actionUpdateProduct($goto, $parameters) {
        global $messageStack;
    
        for ($i=0, $n=sizeof($_POST['products_id']); $i<$n; $i++) {
          $adjust_max= 'false';
          if ($_POST['cart_quantity'][$i] == '') {
            $_POST['cart_quantity'][$i] = 0;
          }
          if (!is_numeric($_POST['cart_quantity'][$i]) || $_POST['cart_quantity'][$i] < 0) {
            $messageStack->add_session('header', ERROR_CORRECTIONS_HEADING . ERROR_PRODUCT_QUANTITY_UNITS_SHOPPING_CART . zen_get_products_name($_POST['products_id'][$i]) . ' ' . PRODUCTS_ORDER_QTY_TEXT . zen_output_string_protected($_POST['cart_quantity'][$i]), 'error');
            continue;
          }
          if ( in_array($_POST['products_id'][$i], (is_array($_POST['cart_delete']) ? $_POST['cart_delete'] : array())) or $_POST['cart_quantity'][$i]==0) {
            $this->remove($_POST['products_id'][$i]);
          } else {
            $add_max = zen_get_products_quantity_order_max($_POST['products_id'][$i]); // maximum allowed
            $cart_qty = $this->in_cart_mixed($_POST['products_id'][$i]); // total currently in cart
    //$messageStack->add_session('header', 'actionUpdateProduct Products_id: ' . $_POST['products_id'] . ' qty: ' . $cart_qty . ' <br>', 'caution');
            $new_qty = $_POST['cart_quantity'][$i]; // new quantity
            $current_qty = $this->get_quantity($_POST['products_id'][$i]); // how many currently in cart for attribute
            $chk_mixed = zen_get_products_quantity_mixed($_POST['products_id'][$i]); // use mixed
    //echo 'I SEE actionUpdateProduct: ' . $_POST['products_id'] . ' ' . $_POST['products_id'][$i] . '<br>';
    
            $new_qty = $this->adjust_quantity($new_qty, $_POST['products_id'][$i], 'shopping_cart');
    
    //die('I see Update Cart: ' . $_POST['products_id'][$i] . ' add qty: ' . $add_max . ' - cart qty: ' . $cart_qty . ' - newqty: ' . $new_qty);
            if (($add_max == 1 and $cart_qty == 1) && $new_qty != $cart_qty) {
              // do not add
              $adjust_max= 'true';
            } else {
            if ($add_max != 0) {
    //$messageStack->add_session('shopping_cart', 'PROCESSING MAX: Update Cart chk_mixed false: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' - newqty: ' . $new_qty . ' current_quantity: ' . $current_qty, 'warning');
              // adjust quantity if needed
    //          if ($add_max != 0 && $new_qty > $current_qty && ($cart_quantity - $current_qty + $new_qty) != 0 && (($cart_quantity - $current_qty + $new_qty) + $cart_qty > $add_max)) {
            switch (true) {
              case ($new_qty == $current_qty): // no change
    //$messageStack->add_session('shopping_cart', 'I see NEW=CURRENT Update Cart chk_mixed false: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' - newqty: ' . $new_qty . ' current_quantity: ' . $current_qty, 'warning');
                $adjust_max= 'false';
                $new_qty = $current_qty;
                break;
              case ($new_qty > $add_max && $chk_mixed == false):
    //$messageStack->add_session('shopping_cart', 'I see Update Cart chk_mixed false: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' - newqty: ' . $new_qty . ' something: ' . $something_qty, 'warning');
                $adjust_max= 'true';
                $new_qty = $add_max ;
                break;
              case (($add_max - $cart_qty + $new_qty >= $add_max) && $new_qty > $add_max && $chk_mixed == true):
    //$messageStack->add_session('shopping_cart', 'I see NEW > ADD Update Cart chk_mixed true: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' + newqty: ' . $new_qty, 'warning');
                $adjust_max= 'true';
                $requested_qty = $new_qty;
                $new_qty = $current_qty;
                break;
              case (($cart_qty + $new_qty - $current_qty > $add_max) && $chk_mixed == true):
    //$messageStack->add_session('shopping_cart', 'I see CART + NEW - CURRENT > ADD Update Cart chk_mixed true: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' + newqty: ' . $new_qty . ' current_qty: ' . $current_qty, 'warning');
                $adjust_max= 'true';
                $requested_qty = $new_qty;
                $new_qty = $current_qty;
                break;
              default:
    //$messageStack->add_session('shopping_cart', 'I see DEFAULT Cart - TURN OFF<br>: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' + newqty: ' . $new_qty . '<br>' . 'current: ' . $current_qty, 'warning');
                $adjust_max= 'false';
              }
              $attributes = ($_POST['id'][$_POST['products_id'][$i]]) ? $_POST['id'][$_POST['products_id'][$i]] : '';
              $this->add_cart($_POST['products_id'][$i], $new_qty, $attributes, false);
            } else {
              // adjust minimum and units
              $attributes = ($_POST['id'][$_POST['products_id'][$i]]) ? $_POST['id'][$_POST['products_id'][$i]] : '';
              $this->add_cart($_POST['products_id'][$i], $new_qty, $attributes, false);
            }
            }
            if ($adjust_max == 'true') {
    //          $messageStack->add_session('shopping_cart', ERROR_MAXIMUM_QTY . ' A: - ' . zen_get_products_name($_POST['products_id'][$i]), 'caution');
    //$messageStack->add_session('shopping_cart', 'actionUpdateProduct<br>' . ERROR_MAXIMUM_QTY . zen_get_products_name($_POST['products_id'][$i]) . '<br>Requested: ' . $requested_qty . ' current: ' . $current_qty , 'caution');
              $messageStack->add_session('shopping_cart', ERROR_MAXIMUM_QTY . zen_get_products_name($_POST['products_id'][$i]), 'caution');
            } else {
    // display message if all is good and not on shopping_cart page
              if (DISPLAY_CART == 'false' && $_GET['main_page'] != FILENAME_SHOPPING_CART) {
                $messageStack->add_session('header', SUCCESS_ADDED_TO_CART_PRODUCT, 'success');
              }
            }
          }
        }
        zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
      }
      /**
       * Method to handle cart Action - add product
    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.1]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...

  4. #4
    Join Date
    Apr 2010
    Posts
    232
    Plugin Contributions
    0

    Default Re: Products Quantity not working

    Hi ajeh,

    Hope you're well. I have tried it, but when I upload, my site disappears. Do you want me to post the shopping cart file so you can see what I have changed?

  5. #5
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    64,665
    Plugin Contributions
    6

    Default Re: Products Quantity not working

    You may have a typo on it ...

    Look in the /cache and see if you have any debug logs ...
    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.1]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...

  6. #6
    Join Date
    Apr 2010
    Posts
    232
    Plugin Contributions
    0

    Default Re: Products Quantity not working

    Hi Ajeh,

    The message I got was :

    [11-Aug-2011 18:12:18] PHP Parse error: syntax error, unexpected $end in /home/watsonpu/public_html/includes/classes/shopping_cart.php on line 1985.

    Only thing is, there is nothing on that line, and it is the last line on that page. Do you know what can I do to remedy this?

  7. #7
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    64,665
    Plugin Contributions
    6

    Default Re: Products Quantity not working

    This is the shopping_cart.php that I have ... see if this helps you identify the error that you have on the changes ...
    Attached Files Attached Files
    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.1]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...

  8. #8
    Join Date
    Apr 2010
    Posts
    232
    Plugin Contributions
    0

    Default Re: Products Quantity not working

    YOU ARE THE BEST!!!! I must have made a mistake then, sorry!

    I have uploaded your file, and it worked immediately. I tested the shopping cart, and it seems to work perfectly. Thank you!

  9. #9
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    64,665
    Plugin Contributions
    6

    Default Re: Products Quantity not working

    You are most welcome ... thanks for the update that those changes have been able to correct this problem ...
    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.1]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...

  10. #10

    Default Re: Products Quantity not working

    Works like a charm! Thank you again for the quick response :) Kathy
    www.pinkchalkfabrics.com - cloth, pattern + tool for modern sewists
    ZC version 1.3.9h, Simple Category Tree, Super Orders

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Unlimited Quantity not working
    By Tech NO Babble in forum Setting Up Categories, Products, Attributes
    Replies: 5
    Last Post: 11 Oct 2010, 08:25 PM
  2. Quantity Discount Feature Not Working
    By InnaSky in forum Creating Discounts/Coupons, Gift Certificates, Newsletters
    Replies: 2
    Last Post: 3 Feb 2010, 06:29 PM
  3. PLZ HELP. My Quantity text box is not working...
    By aruleal in forum General Questions
    Replies: 3
    Last Post: 13 Dec 2008, 10:52 AM
  4. Quantity box.....not working.HELLLLP
    By dhamma in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 20 Jul 2008, 01:13 AM
  5. Quantity Discount not working?
    By grace83 in forum Creating Discounts/Coupons, Gift Certificates, Newsletters
    Replies: 1
    Last Post: 16 Sep 2007, 01:21 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
  •