New Zenner
- Join Date:
- Sep 2008
- Posts:
- 22
- Plugin Contributions:
- 0
Stocks by attributes
You can either comment out the old and paste in the new or you can just replace. Here are the changes you make.
Copy modules/attributes.php into modules/(your template)/attributes.php
Make the following two changes to the page.
Around line 75 change sql. I commented out original and put new below so you could see both. You can just replace the original with the new if you like.
/*
$sql = "select pov.products_options_values_id,
pov.products_options_values_name,
pa.*
from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov
where pa.products_id = '" . (int)$_GET['products_id'] . "'
and pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
and pa.options_values_id = pov.products_options_values_id
and pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
$order_by;
*/
$sql = "select pov.products_options_values_id,
pov.products_options_values_name,
pa.*,
pwas.*
from " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov, " . TABLE_PRODUCTS_ATTRIBUTES . " pa LEFT JOIN " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pwas ON pwas.stock_attributes = pa.products_attributes_id
where pa.products_id = '" . (int)$_GET['products_id'] . "'
and pa.options_id = '" . (int)$products_options_names->fields['products_options_id'] . "'
and (pwas.quantity > 0 or pwas.quantity IS NULL)
and pa.options_values_id = pov.products_options_values_id
and pov.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
$order_by;
Around line 105 change the statement you found. Again original in comment above and new below.
/*
$products_options_array[] = array('id' => $products_options->fields['products_options_values_id'],
'text' => $products_options->fields['products_options_values_name']);
*/
if($products_options->fields['quantity'])
{
$products_text_to_use = $products_options->fields['products_options_values_name'] . " (" . $products_options->fields['quantity'] . " Available)"; //yes Available is improperly hard coded
}
else
{
$products_text_to_use = $products_options->fields['products_options_values_name'];
}
$products_options_array[] = array('id' => $products_options->fields['products_options_values_id'],
'text' => $products_text_to_use);
Now I didn't find this mentioned by anyone else, but I'll give you a heads up. If you plan on having multiple attribute names (not values under a single name) on a product, but only one attribute name will be controlling the quantity you need to do the following or won't display.
- Add the attributes controlling quantity first.
- Go into Products with Attributes Stock and setup stock. IMPORTANT Do this even on attributes that have no stock presently, but you may add later.
- Now go back and add the additional attribute names/values to the product. add those attributes first and then set the quantity.
Hope you enjoy it. Worked well for me.

