Giving back to the community here is what I did that may help some others in creating this functionality. I created a custom field in product for minimum stock amount and Maximum stock to have on hand. This code will check the minumum field instead of default zen field against actual inventory and then send a low stock email if falls below the minimum field. It allows you to have individually set email notifications for each product instead of one value only for all like default zencart. FYI I am not much of a coder so hope there are no mistakes in this, but it works.
File to change: Includes/classes/order.php Zen 1.5.1
Add yellow sections, created these variables $stock_minvaljp, $stock_maxvaljp
Around line 734
// Stock Update - Joao Correia
//JP Added line below to add to query p.products_minmaxjp, p.products_maxjp
if (STOCK_LIMITED == 'true') {
if (DOWNLOAD_ENABLED == 'true') {
$stock_query_raw = "select p.products_quantity, pad.products_attributes_filename, p.product_is_always_free_shipping, p.products_minmaxjp, p.products_maxjp
from " . TABLE_PRODUCTS . " p
left join " . TABLE_PRODUCTS_ATTRIBUTES . " pa
on p.products_id=pa.products_id
left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
on pa.products_attributes_id=pad.products_attributes_id
WHERE p.products_id = '" . zen_get_prid($this->products[$i]['id']) . "'";
// Will work with only one option for downloadable products
// otherwise, we have to build the query dynamically with a loop
$products_attributes = $this->products[$i]['attributes'];
if (is_array($products_attributes)) {
$stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
}
$stock_values = $db->Execute($stock_query_raw);
} else {
$stock_values = $db->Execute("select * from " . TABLE_PRODUCTS . " where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'");
Around line 766- Get info from our custom fields entered in products
// do not decrement quantities if products_attributes_filename exists
if ((DOWNLOAD_ENABLED != 'true') || $stock_values->fields['product_is_always_free_shipping'] == 2 || (!$stock_values->fields['products_attributes_filename']) ) {
$stock_left = $stock_values->fields['products_quantity'] - $this->products[$i]['qty'];
//JP Added 2lines below and custom variable $stock_minvaljp and $stock_maxvaljp
$stock_minvaljp = $stock_values->fields['products_minmaxjp'];
$stock_maxvaljp = $stock_values->fields['products_maxjp'];
$this->products[$i]['stock_reduce'] = $this->products[$i]['qty'];
} else {
$stock_left = $stock_values->fields['products_quantity'];
}
Around line 786 – Change to check our new variable to determine if need to send email.
// for low stock email
//JP Added changed line below to use variable $stock_min
if ( $stock_left <= $stock_minvaljp ) {
// WebMakers.com Added: add to low stock email
//JP Added changed to add low stock min value and added () to make easier to read in email
$this->email_low_stock .= 'ID# ' . zen_get_prid($this->products[$i]['id']) . "\t\t" . ' (Item: ' . $this->products[$i]['model'] . "\t\t" . ') ' . $this->products[$i]['name'] . "\t\t" . ' (Qty Left:) ' . $stock_left . ' (Stock Min/Max:) ' . $stock_minvaljp . '/' . $stock_maxvaljp . "\n";
Bookmarks