To simply put it, it allows for you to give attributes a quantity. I
know a few people that use this shopping cart that wished that it had
this option so I thought I would write a modification to do this.
Once you have added an attribute the quantity option for the actual
product is disabled. This mod will control your product stock levels
so everytime you add or delete a product attribute the total quantity
will change accordingly. If you delete all attributes for a certain
product you will have access to the standard quantity control again.
Once a product attribute has reached a quantity of 0 it removes the
product attribute from the product page. Future development might
include more options for this.
Thanks to Pavel Rojkov I have added his contribution to allow you
to manage product attributes from the products page.
Legend: 
Download

Report
the previous "Fix a bug:: check stock per product attribute quantity" (v2) doesn't work if you have products with attribute AND products without attribute.
use checkout_payment.php and checkout_confirmation.php from the previous fix but for shopping_cart.php and general.php use the code below.
for shopping_cart.php :
find these lines:
if (STOCK_CHECK == 'true') {
$stock_check = tep_check_stock($products[$i]['id'], $products[$i]['quantity']);
if (tep_not_null($stock_check)) {
$any_out_of_stock = 1;
$products_name .= $stock_check;
}
}
and replace with:
if (STOCK_CHECK == 'true') {
if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
reset($products[$i]['attributes']);
while (list($option, $value) = each($products[$i]['attributes'])) {
$stock_check = tep_check_stock_attribute($products[$i]['id'], $products[$i][$option]['products_attributes_id'], $products[$i]['quantity']);
if (tep_not_null($stock_check)) {
$any_out_of_stock = 1;
$products_name .= '<br /> ' . $stock_check;
}
}
} else {
$stock_check = tep_check_stock($products[$i]['id'], $products[$i]['quantity']);
if (tep_not_null($stock_check)) {
$any_out_of_stock = 1;
$products_name .= '<br /> ' . $stock_check;
}
}
}
for general.php:
find:
////
// Break a word in a string if it is longer than a specified length ($len)
and add above:
////
// Return a product's stock - ATTRIBUTE
// TABLES: products
function tep_get_products_stock_attribute($products_id, $products_attributes_id) {
$products_id = tep_get_prid($products_id);
$stock_query = tep_db_query("select options_quantity from " . TABLE_PRODUCTS ." p,".TABLE_PRODUCTS_ATTRIBUTES. " pa where p.products_id = '" . (int)$products_id . "'"." AND p.products_id=pa.products_id AND pa.products_attributes_id='".(int)$products_attributes_id."'");
$stock_values = tep_db_fetch_array($stock_query);
return $stock_values['options_quantity'];
}
////
// Check if the required stock is available - ATTRIBUTE
// If insufficent stock is available return an out of stock message
function tep_check_stock_attribute($products_id, $products_attributes_id, $products_quantity) {
$stock_left = tep_get_products_stock_attribute($products_id, $products_attributes_id) - $products_quantity;
$out_of_stock = '';
if ($stock_left < 0) {
$out_of_stock = '<span class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</span>';
}
return $out_of_stock;
}
NOTE: THIS IS A BLANK FILE
With the last bugfix of taajny, mysql might give the error:
"1052 - Column 'products_options_id' in field list is ambiguous".
A simple modification to fix that error:
File to change:
~/catalog/admin/includes/functions/general.php
Around line 928, find:
$options_query = tep_db_query("SELECT products_options_id, products_options_values_id FROM " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " LEFT JOIN " . TABLE_PRODUCTS_OPTIONS . " ON products_options_name = products_options LEFT JOIN " . TABLE_PRODUCTS_OPTIONS_VALUES . " ON products_options_values_name = products_options_values WHERE orders_products_id = '" . (int)$order['orders_products_id'] . "'");
CHANGE TO:
$options_query = tep_db_query("SELECT opa.products_options_id, opa.products_options_values_id FROM " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa LEFT JOIN " . TABLE_PRODUCTS_OPTIONS . " ON products_options_name = products_options LEFT JOIN " . TABLE_PRODUCTS_OPTIONS_VALUES . " ON products_options_values_name = products_options_values WHERE orders_products_id = '" . (int)$order['orders_products_id'] . "'");
That's it.
Only one file, contains the same text at this description above.
I found a bug:
when You want to delete order in admin, only quantity on products is restocking, not in products_attributes.
I fixed it. Description is in this package.
hi,
I found a bug - perhaps this is a problem about global vars declaration.
within the "check stock" (around line 70) all attributes will be pushed into an array. but the $products... arn't set. it needs to be reinitialized by calling $products = $cart->get_products(); from the cart.
so the change I made (arround line 70);
----------------
// Stock Check
$any_out_of_stock = false;
if (STOCK_CHECK == 'true') {
$products = $cart->get_products();
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
// Yuval - Start - Fix a bug:: check stock per product attribute quantity
// Push all attributes information in an array
---------------
only the line that with "$products = $cart->get_products();" is new!
hopefully this help an solves some problems.
regards
peter
For this to work you need Paypal 2.8 at least although there are later versions available but it works fine on 2.8 for me and I don't repair whats not broken.
http://www.oscommerce.com/community/contri...arch,paypal+2.8
Its also noteworthy that all products regardless of whether they have attributes or not still have to have one attribute assigned even if its just "No Options" for the stock control part of this to work.
Steve
If you use Paypal with your cart you may will see as we did that your stock is not updated on any Paypal orders.
Make changes as detailed in the attached file to catalog includesmodulespaymentpaypalcatalogcheckout_process.inc.php
Works great for us but there is a downside!
Because Paypal orders are recorded in the cart before payment is made and left waiting for an IPN
from Paypal the stock is taken before its complete.
As the existing re-stock quantity option for deleted orders works on the products_quantiy and
not options_quantity there is perhaps a little more work to finalise the attributes quantity mod needed
to make the re-stock orders feature re-stock the options_quantity fields.
Time to install < 1 minute
Skill level - basic
Feel free if you can do it?
Steve M
Hi again,
I had to re-fix since there were still problems left.
Please use this zip package.
Bug Description:
When an attribute quantity is set say to 5
and user changes the quantity in the cart to 6
there was no stock check done, and user could go on with the payment process, and buy this amout even if not available in stock.
Pay attention:
The change I have done only takes care of products with attibute quantity (as all of my products have attibute quantity) .
I did not handle not tested the case when some products have no attibute quantity, and I should think it will not work...
Thats it.
Yuval.
Update to include manual installation notes and also code commented the modifications that were made.
A file was left out in the previous download, please use this updated file.
Thanks to Dror S. for pointing this out. :-)
To simply put it, it allows for you to give attributes a quantity. I
know a few people that use this shopping cart that wished that it had
this option so I thought I would write a modification to do this.
Once you have added an attribute the quantity option for the actual
product is disabled. This mod will control your product stock levels
so everytime you add or delete a product attribute the total quantity
will change accordingly. If you delete all attributes for a certain
product you will have access to the standard quantity control again.
Once a product attribute has reached a quantity of 0 it removes the
product attribute from the product page. Future development might
include more options for this.
Thanks to Pavel Rojkov I have added his contribution to allow you
to manage product attributes from the products page.