From the WIKI:
How can I show the amount of stock available next to each attribute on the product information page?
This wiki page points to posts that are not publicly viewable. I have one attribute in a dropdown for a product and here is how I did it, hopefully this saves someone a little bit of time.
zen cart version = 1.3.8a
in includes\modules\attributes.php
after
die('Illegal Access');
}
add the following:
//START PWA EDIT
function zen_draw_pull_down_menu_disableable($name, $values, $default = '', $parameters = '', $required = false) {
$field = '<select name="' . zen_output_string($name) . '"';
if (zen_not_null($parameters)) $field .= ' ' . $parameters;
$field .= '>' . "\n";
if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]);
for ($i=0, $n=sizeof($values); $i<$n; $i++) {
$field .= ' <option value="' . zen_output_string($values[$i]['id']) . '"';
if ($default == $values[$i]['id']) {
$field .= ' selected="selected"';
}
if ($values[$i]['disabled'] == true) $field .= ' disabled="disabled"';
$field .= '>' . zen_output_string($values[$i]['text'], array('"' => '"', '\'' => ''', '<' => '<', '>' => '>')) . '</option>' . "\n";
}
$field .= '</select>' . "\n";
if ($required == true) $field .= TEXT_FIELD_REQUIRED;
return $field;
}
//END PWA EDIT
after
if ($pr_attr->fields['total'] > 0) {
add the following:
//START PWA EDIT
$PWALookup = array();
$PWAQ = $db->Execute("
select
products_with_attributes_stock.quantity as q,
products_attributes.options_values_id as id
from products_with_attributes_stock
left join products_attributes on products_with_attributes_stock.stock_attributes = products_attributes.products_attributes_id
where products_with_attributes_stock.products_id='".(int)$_GET['products_id']."'
");
if ($PWAQ->RecordCount() > 0) {
do {
$PWALookup[$PWAQ->fields['id']] = $PWAQ->fields['q'];
$PWAQ->MoveNext();
} while (!$PWAQ->EOF);
}
//END PWA EDIT
find the following:
$products_options_array[] = array('id' => $products_options->fields['products_options_values_id'],
'text' => $products_options->fields['products_options_values_name']);
replace with:
//START PWA EDIT
$PWAkey = $products_options->fields['products_options_values_id'];
$PWAAppend = "";
$PWADisabled = false;
if (array_key_exists($PWAkey ,$PWALookup)) {
if ($PWALookup[$PWAkey] == 0) {
//out of stock message
$PWAAppend = " (Out of stock)";
$PWADisabled = true;
} else {
//your IN STOCK message goes here
$PWAAppend = " (".$PWALookup[$PWAkey]." in stock)";
}
}
$products_options_array[] = array('id' => $products_options->fields['products_options_values_id'].$PWAHack,
'text' => $products_options->fields['products_options_values_name'].$PWAAppend,'disabled'=>$PWADisabled);
//END PWA EDIT
find the following code
$options_menu[] = zen_draw_pull_down_menu('id[' . $products_options_names->fields['products_options_id'] . ']', $products_options_array, $selected_attribute, 'id="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '"') . "\n";
replace with:
//START PWA EDIT
$options_menu[] = zen_draw_pull_down_menu_disableable('id[' . $products_options_names->fields['products_options_id'] . ']', $products_options_array, $selected_attribute, 'id="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '"') . "\n";
//END PWA EDIT