...I do it? Below is the code used to generate the number - I then need to turn that number into a percentage remaining?
// ######### BEGIN CUSTOM CODING RELATED TO STOCK DISPLAY ###############
function garland_uc_product_add_to_cart( $node ) {
// look up all sku's for this product
$skus=uc_attribute_uc_product_models($node);
if(!empty($skus)){ // if there are multiple sku's, then list stock availability of options.
$avail = array();
foreach($skus as $val) {
$sl = uc_stock_level($val);
if (is_numeric($sl)) {
$name=lookup_option_name($val); // get the pretty name of option sku
$avail[] = " " .$name." (".$sl.")";
}
}
if(!empty($avail)) { $avail_string = "<br><div class=\"stock_level\">Number Available: ". implode(",",$avail) ."</div>"; }
return( $avail_string ). theme_uc_product_add_to_cart($node);
}
else { // else, we do the normal thing.
$stocklevel = uc_stock_level($node->model);
if (is_numeric($stocklevel)) {
// Stock tracking is active
if ($stocklevel == 0) {
return( '<div class="out_of_stock">' . t('Sorry, this item is out of stock') . '</div>' );
} else {
return( '<div class="stock_level">' . t('Number available: ') . $stocklevel . '</div>' ) . theme_uc_product_add_to_cart($node);
}
} else {
// Stock tracking is not being used for this product, just show the add to cart button as normal
return theme_uc_product_add_to_cart($node);
}
}
}
function uc_stock_attribute_uc_product_models($node) {
$models = array();
// Get all the SKUs for all the attriibutes.
$adjustments = db_query("SELECT model FROM {uc_product_adjustments} WHERE nid = %d", $node->nid);
while ($adjustment = db_fetch_object($adjustments)) {
if (!in_array($adjustment->model, $models)) {
$models[$adjustment->model] = $adjustment->model;
}
}
return $models;
}
function lookup_option_name($sku){
//uc_attribute_options: name,oid
//uc_product_adjustments: combination (number in "quotes" equals oid above),model
$query = "SELECT combination FROM {uc_product_adjustments} WHERE model = '$sku'";
$result = db_query($query);
while ($row = db_fetch_array($result)) {
$combo = $row[combination];
list($stuff, $oid, $junk) = split('"', $combo);
$query2="SELECT name FROM {uc_attribute_options} WHERE oid = '$oid'";
$result2=db_query($query2);
while($row2=db_fetch_array($result2)){$name=$row2[name];}
return $name;
}
}
// ######### END CUSTOM CODING RELATED TO STOCK DISPLAY ###############
// ######### BEGIN CUSTOM CODING RELATED TO STOCK DISPLAY ###############
function garland_uc_product_add_to_cart( $node ) {
// look up all sku's for this product
$skus=uc_attribute_uc_product_models($node);
if(!empty($skus)){ // if there are multiple sku's, then list stock availability of options.
$avail = array();
foreach($skus as $val) {
$sl = uc_stock_level($val);
if (is_numeric($sl)) {
$name=lookup_option_name($val); // get the pretty name of option sku
$avail[] = " " .$name." (".$sl.")";
}
}
if(!empty($avail)) { $avail_string = "<br><div class=\"stock_level\">Number Available: ". implode(",",$avail) ."</div>"; }
return( $avail_string ). theme_uc_product_add_to_cart($node);
}
else { // else, we do the normal thing.
$stocklevel = uc_stock_level($node->model);
if (is_numeric($stocklevel)) {
// Stock tracking is active
if ($stocklevel == 0) {
return( '<div class="out_of_stock">' . t('Sorry, this item is out of stock') . '</div>' );
} else {
return( '<div class="stock_level">' . t('Number available: ') . $stocklevel . '</div>' ) . theme_uc_product_add_to_cart($node);
}
} else {
// Stock tracking is not being used for this product, just show the add to cart button as normal
return theme_uc_product_add_to_cart($node);
}
}
}
function uc_stock_attribute_uc_product_models($node) {
$models = array();
// Get all the SKUs for all the attriibutes.
$adjustments = db_query("SELECT model FROM {uc_product_adjustments} WHERE nid = %d", $node->nid);
while ($adjustment = db_fetch_object($adjustments)) {
if (!in_array($adjustment->model, $models)) {
$models[$adjustment->model] = $adjustment->model;
}
}
return $models;
}
function lookup_option_name($sku){
//uc_attribute_options: name,oid
//uc_product_adjustments: combination (number in "quotes" equals oid above),model
$query = "SELECT combination FROM {uc_product_adjustments} WHERE model = '$sku'";
$result = db_query($query);
while ($row = db_fetch_array($result)) {
$combo = $row[combination];
list($stuff, $oid, $junk) = split('"', $combo);
$query2="SELECT name FROM {uc_attribute_options} WHERE oid = '$oid'";
$result2=db_query($query2);
while($row2=db_fetch_array($result2)){$name=$row2[name];}
return $name;
}
}
// ######### END CUSTOM CODING RELATED TO STOCK DISPLAY ###############