Re: Out of Stock When Placing Order - IS Checking by Product and Attribute.
NOTE: these would be better checks on the extra stock check:
Code:
// 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'])) {
Code:
// 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'])) {
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.
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:
Quote:
Check stock level
Check to see if sufficent stock is available
true
Quote:
Subtract stock
Subtract product in stock by product orders
true
Quote:
Allow Checkout
Allow customer to checkout even if there is insufficient stock
false
Make sure that on the Product you have set:
Quote:
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 ...
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.
2. 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.
Code:
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.
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:
Code:
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...
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:
Code:
$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>' : '');
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 ...
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 ...
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.
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?