Community Add-Ons

Add file to this package
Top » Features

Quantity for Product Attributes Mod
for osCommerce Online Merchant v2.2

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
Expand All / Collapse All
Fix a bug:: check stock per product attribute quantity (v3) ekodziecko 23 Sep 2009  

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

Errorfix on the bugfix of taajny superfrank 3 Feb 2009  
BUG when delete order taajny 26 Apr 2007  
check stock in checkout_confimation.php hobbynet 25 Feb 2007  
Stock Attributes Quantity Control nevetsnikam 3 Oct 2006  
Paypal Update for this mod nevetsnikam 28 Jul 2006  
Fix a bug:: check stock per product attribute quantity (v2) yuvalj 28 Jul 2005  
Fix a bug:: check stock per product attribute quantity yuvalj 28 Jul 2005  
Update (..again) Ben Cooper 28 Jun 2005  
Update Ben Cooper 27 Jun 2005  
Quantity for Product Attributes Mod Ben Cooper 27 Jun 2005