Forums / Bug Reports / Out of Stock When Placing Order - IS Checking by Product and Attribute.

Out of Stock When Placing Order - IS Checking by Product and Attribute.

Views: 4,954

Results 1 to 20 of 25
6 Mar 2012, 11:14 PM
#1
dboling avatar

dboling

New Zenner

Join Date:
Mar 2012
Location:
Sterling, PA 18463
Posts:
5
Plugin Contributions:
0

Out of Stock When Placing Order - IS Checking by Product and Attribute.

When placing product order with attributes. The store is checking stock by the Product and it's Attributes instead of just checking by Product.
I have an item "Custom 14 Karat Gold Namepins Round Wire" with a stock of 1 item, the item has 3 attributes fields "NAME", "CHAIN", "CHRYSTAL HEARTS". the Namepin is priced by character by the name field.

If you add more than 1 item to your cart with identical attributes an error "(Products marked with *** are out of stock)" will appear. if you change an attribute or the name on the namepin, the item gets added to the cart. The problem is I only have 1 product in stock.

the url is: http://www.shamrockstables.org/cart/

I've uploaded a screen shot
Attachment #10239

This is on a linux server.
ZenCart V 1.5
Mysql Version: '5.0.95'

7 Mar 2012, 12:58 AM
#2
dboling avatar

dboling

New Zenner

Join Date:
Mar 2012
Location:
Sterling, PA 18463
Posts:
5
Plugin Contributions:
0

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

I reproduced this bug with a fresh (Pristine) install of ZenCart V1.5 on another virtual domain.

7 Mar 2012, 1:06 AM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

Working on a solution for you ... it will be a while ... :flex:

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!]
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 Mar 2012, 1:45 AM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

See if this works for you ...

Make sure the Product is marked as:

Product Qty Min/Unit Mix: Yes
Then edit the file:
/includes/modules/pages/shopping_cart/header_php.php

and add the code in RED:

    $flagStockCheck = zen_check_stock($products[$i]['id'], $products[$i]['quantity']);
// bof: extra check on stock
    if ($flagStockCheck != true) {
      if ( (zen_get_products_stock($products[$i]['id']) - ($_SESSION['cart']->in_cart_mixed($products[$i]['id']) - $_SESSION['cart']->get_quantity($products[$i]['id']))) <= 0) {
        $flagStockCheck = '<span class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</span>';
      } else {
        $flagStockCheck = '';
      }
    }
// eof: extra check on stock
    if ($flagStockCheck == true) {
      $flagAnyOutOfStock = true;
    }

See if that works on the shopping_cart page ...

I am still working out something for the checkout ...

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!]
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 Mar 2012, 2:03 AM
#5
dboling avatar

dboling

New Zenner

Join Date:
Mar 2012
Location:
Sterling, PA 18463
Posts:
5
Plugin Contributions:
0

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

It flags the item and still adds it to the cart, then it still allows customer to check out with items.

Cart is in testing and dev so your welcome to create a test account on the cart to for testing.

7 Mar 2012, 2:10 AM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

Now edit the file:
/includes/modules/pages/checkout_shipping/header_php.php

// Stock Check
  if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
    $products = $_SESSION['cart']->get_products();
    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
      if (zen_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
        zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
        break;
      } else {
// bof: extra check on stock
        if ( (zen_get_products_stock($products[$i]['id']) - ($_SESSION['cart']->in_cart_mixed($products[$i]['id']) - $_SESSION['cart']->get_quantity($products[$i]['id']))) <= 0) {
          zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
          break;
        }
// eof: extra check on stock
      }
    }
  }
// if no shipping destination address was selected, use the customers own address as default

/includes/modules/pages/checkout_payment/header_php.php

// Stock Check
if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
  $products = $_SESSION['cart']->get_products();
  for ($i=0, $n=sizeof($products); $i<$n; $i++) {
    if (zen_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
      zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
      break;
    } else {
// bof: extra check on stock
      if ( (zen_get_products_stock($products[$i]['id']) - ($_SESSION['cart']->in_cart_mixed($products[$i]['id']) - $_SESSION['cart']->get_quantity($products[$i]['id']))) <= 0) {
        zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
        break;
      }
// eof: extra check on stock
    }
  }
}

// get coupon code

/includes/modules/pages/checkout_confirmation/header_php.php

if (STOCK_CHECK == 'true') {
  for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
    if ($stock_check[$i] = zen_check_stock($order->products[$i]['id'], $order->products[$i]['qty'])) {
      $flagAnyOutOfStock = true;
    }
  }
  // Out of Stock
  if ( (STOCK_ALLOW_CHECKOUT != 'true') && ($flagAnyOutOfStock == true) ) {
    zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
    } else {
// bof: extra check on stock
      if ( (zen_get_products_stock($order->products[$i]['id']) - ($_SESSION['cart']->in_cart_mixed($order->products[$i]['id']) - $_SESSION['cart']->get_quantity($order->products[$i]['id']))) <= 0) {
        zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
        break;
      }
// eof: extra check on stock
  }
}

// update customers_referral with $_SESSION['gv_id']

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!]
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 Mar 2012, 2:24 AM
#7
dboling avatar

dboling

New Zenner

Join Date:
Mar 2012
Location:
Sterling, PA 18463
Posts:
5
Plugin Contributions:
0

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

Still adds it to the cart, but stops it at check out.

7 Mar 2012, 2:32 AM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

That is all it does ... flag the products that cause the problem and not allow checkout until the quantity is fixed ...

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!]
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 Mar 2012, 2:41 AM
#9
dboling avatar

dboling

New Zenner

Join Date:
Mar 2012
Location:
Sterling, PA 18463
Posts:
5
Plugin Contributions:
0

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

Thanks, You were quick to find a solution for the bug and fix it. It'll help a lot of people keep from selling products they don't have.

Wish I was working so I could afford to send you a donut and coffee.

Who do I send a request for a few more generic flat rate shipping modules ?

One flat.php for usps flatrate boxs and packages aren't enough.
I took flat.php and edited it and it worked fine, but wouldn't go past the select shipping page.

7 Mar 2012, 2:50 AM
#10
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

You would have to post a new thread and what you are trying to do and perhaps the code that you are using to see why it is broken with details on how to you need it to work and maybe someone will look at it and try to help you ...

Otherwise, you can look at the Recommended services for any that help write custom code for hire ...

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!]
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!

11 Mar 2012, 2:15 AM
#11
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

NOTE: these would be better checks on the extra stock check:

//        if ( (zen_get_products_stock($products[$i]['id']) - ($_SESSION['cart']->in_cart_mixed($products[$i]['id']) - $_SESSION['cart']->get_quantity($products[$i]['id']))) <= 0) {
          if ($_SESSION['cart']->in_cart_mixed($products[$i]['id']) > zen_get_products_stock($products[$i]['id'])) {
//      if ( (zen_get_products_stock($order->products[$i]['id']) - ($_SESSION['cart']->in_cart_mixed($order->products[$i]['id']) - $_SESSION['cart']->get_quantity($order->products[$i]['id']))) <= 0) {
      if ($_SESSION['cart']->in_cart_mixed($order->products[$i]['id']) > zen_get_products_stock($order->products[$i]['id'])) {

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!]
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 Jun 2012, 8:32 AM
#12
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

I believe that the same issue applies to the quantity in cart feature on the product_info page. By which I mean that with two identical products, except for text attributes that differ, the quantity in cart is shown as 1. I am working on a 'far from clean' install so perhaps I am mistaken.

I also wonder if corresponding changes need to be made to ipn_main_handler.php ? Sort of similar to the changes required by stock by attributes.

Nick
iszent.com

5 Jun 2012, 1:16 PM
#13
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

Make sure that in the Configuration ... Stock ... you have turned on the Stock Check:

Check stock level
Check to see if sufficent stock is available
true

Subtract stock
Subtract product in stock by product orders
true

Allow Checkout
Allow customer to checkout even if there is insufficient stock
false

Make sure that on the Product you have set:

Product Qty Min/Unit Mix: Yes

Make sure that you made the extra stock check on the:
/includes/modules/pages/shopping_cart/header_php.php
/includes/modules/pages/checkout_shipping/header_php.php
/includes/modules/pages/checkout_payment/header_php.php
/includes/modules/pages/checkout_confirmation/header_php.php

I am also assuming that you are using the current Zen Cart v1.5 ...

from above ...

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!]
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 Jun 2012, 3:24 PM
#14
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

It is a test install of 1.5. Just cleaned it down and restarted from scratch.

How to repeat:

  1. Create a product with an attribute (size) and a text attribute.
  2. Add the product to the cart with a text attribute set.
  3. Add the product to the cart again with a different text attribute

The products both show in the cart. However, back on the product_info page the 'Quantity in Cart' shows as one.

Basically in the shopping_cart class function get_quantity($products_id) returns the value of the first product with the correct id. It does not have anything to do with the stock check. ( But I have the settings and changes that you detailed above)

The source below shows the cart object has three products all with the same id. But get_quantity returns a value of 3 which is the stock level of the first one in the list.

Session Cart<br>shoppingCart Object
(
    [contents] => Array
        (
            [7:f1319f0c3751189feae9d6c0df890476] => Array
                (
                    [qty] => 3
                    [attributes_values] => Array
                        (
                            [3] => ffff
                        )

                    [attributes] => Array
                        (
                            [3] => 0
                            [4_chk7] => 7
                            [2] => 3
                            [1] => 6
                        )

                )

            [7:4cfb5324f02c287e27107f9e5453bbdb] => Array
                (
                    [qty] => 1
                    [attributes_values] => Array
                        (
                            [3] => 44
                        )

                    [attributes] => Array
                        (
                            [3] => 0
                            [4_chk7] => 7
                            [2] => 3
                            [1] => 6
                        )

                )

            [7:a5d012a3cd410db0c8e57446dabae7d8] => Array
                (
                    [qty] => 1
                    [attributes_values] => Array
                        (
                            [3] => 55
                        )

                    [attributes] => Array
                        (
                            [3] => 0
                            [4_chk7] => 7
                            [2] => 2
                            [1] => 5
                        )

                )

        )

    [total] => 2050
    [weight] => 0
    [cartID] => 16821
    [content_type] => 
    [free_shipping_item] => 0
    [free_shipping_weight] => 0
    [free_shipping_price] => 0
)
<br>get_quantity returns <br>3<br>

Also, as I said the stock check in ipn_main_handler.php will not cope with this situation. It checks the stock on a product per product basis. So, it will see both those products as being in stock. As similar fix to that detailed above is required where the extra stock check is added in to the code. As I say, similar to the extra checks that are needed for stock by attributes to function properly with ipn_main_handler.

Nick
iszent.com

5 Jun 2012, 4:09 PM
#15
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

You could try this new test ...

Put all your files back how they were and just make this one change to the file:
/includes/functions/functions_lookups.php

And add the code in RED:

  function zen_check_stock($products_id, $products_quantity) {
    //$stock_left = zen_get_products_stock($products_id) - $products_quantity;
    $stock_left = zen_get_products_stock($products_id) - $_SESSION['cart']->in_cart_mixed($products_id);
    $out_of_stock = '';

    if ($stock_left < 0) {
      $out_of_stock = '<span class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</span>';
    }

    return $out_of_stock;
  }

Just to that one function and see if it fixes everything from the PayPal button, to shopping_cart to checkout_shipping, to checkout_payment to checkout_confirmation and ipn_main_handler...

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!]
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 Jun 2012, 4:35 PM
#16
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

Yeah, I think that is the heart of the issue. $_SESSION['cart']->in_cart_mixed works better than just the quantity.

So, actually in tpl_product_info_default.php I think that it shoud read:

    $display_qty = (($flag_show_product_info_in_cart_qty == 1 and $_SESSION['cart']->in_cart($_GET['products_id'])) ? '<p>' . PRODUCTS_ORDER_QTY_TEXT_IN_CART . $_SESSION['cart']->in_cart_mixed($_GET['products_id']) . '</p>' : '');

Nick
iszent.com

5 Jun 2012, 4:42 PM
#17
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

And the slight issue here is that it marks all products out of stock. So with a stock of one and two in the cart with different attributes both are marked out of stock although one is actually purchasable.

Where I came to this is by a module that is under work to exclude some attributes from stock by attribute calculations. A parallel problem arose an I needed to write a stock check function that looped through the cart and calculated the total of the product in the cart at that point. So with two products the first one would have a 'total in the cart so far' count of one and would be in stock. The second product would have a 'total in the cart so far' count of two and would be out of stock.

A bit of a pain ...

Nick
iszent.com

5 Jun 2012, 4:44 PM
#18
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

First, please make the one change in the one function zen_check_stock and see if that fixes everything everywhere ... and ensure the checkout is working ...

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!]
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 Jun 2012, 6:20 PM
#19
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

Sorry, I had written a longer post and then censored myself for being wordy.

Yes, that is what I did. Works fine for everything to do with the cart and checkout. So, yes, that is a nicer solution than changing the header_php files. But doesn't solve any issues that those changes didn't.

Where it doesn't work by itself is in product_info.

Also, as I say it marks multiple products out of stock when only some of them are actually out of stock. Which ones should actually be marked out of stock is a bit moot.

Nick
iszent.com

5 Jun 2012, 6:26 PM
#20
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.

Have you an URL on your site where we can perhaps see this working or not working as you are wanting it to?

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!]
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!