PDA

View Full Version : Automatic Customer Stock Update Notification



michael_s
07-11-2008, 01:00 AM
use this code to stop the email notification of a stokc update, "IF" the current qty is above zero. for example if the stock was at zero and it was updated to 3, customer would recieve an email, if the qty was at 3 and updated to 7 no email will be sent. Task taken from the "need help with" section. Thanks for a great addon :)

// BEGIN Automatic Stock Notification
$current_stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$_GET['pID'] . "'");
$current_stock = tep_db_fetch_array($current_stock_query);
if ($current_stock['products_quantity'] < 1) {
if ($_POST['products_quantity'] > 0) {
$audience = array();
$products_query = tep_db_query("select distinct pn.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address from " . TABLE_CUSTOMERS . " c, " . TABLE_PRODUCTS_NOTIFICATIONS . " pn where c.customers_id = pn.customers_id and pn.products_id in ( '" . (int)$products_id . "')");
while ($products = tep_db_fetch_array($products_query)) {
$audience[$products['customers_id']] = array('firstname' => $products['customers_firstname'],
'lastname' => $products['customers_lastname'],
'email_address' => $products['customers_email_address']);
}
$product_query_raw = tep_db_query("select p.products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_url, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . (int)$_GET['pID'] . "'");
$product = tep_db_fetch_array($product_query_raw);
$customers_query_raw = tep_db_query("select distinct pn.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address from " . TABLE_CUSTOMERS . " c, " . TABLE_PRODUCTS_NOTIFICATIONS . " pn where c.customers_id = pn.customers_id and pn.products_id in ( '" . (int)$products_id . "')");
$customer = tep_db_fetch_array($customers_query_raw);
reset($audience);
while (list($key, $value) = each ($audience)) {
$mimemessage = new email(array('X-Mailer: osCommerce System Mailer'));
// add the message to the object
if (EMAIL_USE_HTML == 'true') {
$mimemessage->add_html(HTML_NOTIFICATION1 . $value['firstname'] . ' ' . $value['lastname'] . HTML_NOTIFICATION2 . STORE_NAME . HTML_NOTIFICATION3 . $products_id . '">' . $product['products_name'] . HTML_NOTIFICATION4 . '">' . STORE_NAME . HTML_NOTIFICATION5 . $product['products_name'] . HTML_NOTIFICATION6 . $product['products_name'] . HTML_NOTIFICATION7 . STORE_NAME . HTML_NOTIFICATION8 . $products_id . '">' . $product['products_name'] . HTML_NOTIFICATION9 . STORE_NAME);
} else {
$mimemessage->add_text(TEXT_NOTIFICATION1 . $value['firstname'] . ' ' . $value['lastname'] . TEXT_NOTIFICATION2 . STORE_NAME . TEXT_NOTIFICATION3 . $product['products_name'] . TEXT_NOTIFICATION4 . $product['products_name'] . TEXT_NOTIFICATION5 . $product['products_name'] . TEXT_NOTIFICATION6 . STORE_NAME . TEXT_NOTIFICATION7 . $product['products_name'] . TEXT_NOTIFICATION8 . STORE_NAME);
}
$mimemessage->build_message();
$mimemessage->send($value['firstname'] . ' ' . $value['lastname'], $value['email_address'], STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, 'Now In Stock: ' . $product['products_name'], $email_order);
// tep_db_query("delete from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . $products_id . "' ");
}
}
}
// END Automatic Stock Notification

zip is a dummy file....

More... (http://addons.oscommerce.com/info/3152)