burt Posted March 26, 2018 Share Posted March 26, 2018 Yesterday I helped a shopowner with something and then at the end of the email chain this question came up; Quote Do you have an addon ... that customers can register to be automatically notified when a item comes back in stock? I don't. But I just wrote some code that might do a job, but it is UNTESTED and would be better as a Hook or module. For testing purposes, hardcode it. Here we go; Step 1 - Language Change admin/includes/languages/english/categories.php ADD: // notifications define('NOTIFICATION_BACK_IN_STOCK_SUBJECT', '%1$s is back in stock at %2$s'); define('NOTIFICATION_BACK_IN_STOCK_TEXT', 'Hi! We wanted to let you know that %1$s is back in stock at %2$s online shop!' . "\n\n" . 'Have a look: %3$s' . "\n\n" . ' Sincerely, %2$s'); define('NOTIFICATION_BACK_IN_STOCK_SENT', 'Success: %s emails sent!'); At this point you need to determine how you make stock changes. Some shopowners use the red/green selector. Some shopowners use the product_quantity input when editing product. Step 2 - Admin Page Change If you use the red/green selector admin/categories.php FIND: if (isset($_GET['pID'])) { tep_set_product_status($_GET['pID'], $_GET['flag']); } ADD AFTER: if ($_GET['flag'] == '1') { $notifications_query = tep_db_query("select customers_firstname, customers_email_address from customers where customers_id in (select customers_id from products_notifications where products_id = " . (int)$_GET['pID'] . ")"); $product = tep_get_products_name((int)$_GET['pID']); $url = tep_catalog_href_link('product_info.php', 'products_id=' . (int)$_GET['pID']); $subject = sprintf(NOTIFICATION_BACK_IN_STOCK_SUBJECT, $product, STORE_NAME); $message = sprintf(NOTIFICATION_BACK_IN_STOCK_TEXT, $product, STORE_NAME, $url); $mimemessage = new email(); $text = strip_tags($message); if (EMAIL_USE_HTML == 'true') { $mimemessage->add_html($message, $text); } else { $mimemessage->add_text($text); } $mimemessage->build_message(); $emails = 0; while ($notifications = tep_db_fetch_array($notifications_query)) { $mimemessage->send($notifications['customers_firstname'], $notifications['customers_email_address'], STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, $subject); $emails++; } $messageStack->add_session(sprintf(NOTIFICATION_BACK_IN_STOCK_SENT, $emails), 'success'); } If you use the product_quantity input (editing product) admin/categories.php FIND: if (tep_db_num_rows($product_images_query)) { while ($product_images = tep_db_fetch_array($product_images_query)) { $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_IMAGES . " where image = '" . tep_db_input($product_images['image']) . "'"); $duplicate_image = tep_db_fetch_array($duplicate_image_query); if ($duplicate_image['total'] < 2) { if (file_exists(DIR_FS_CATALOG_IMAGES . $product_images['image'])) { @unlink(DIR_FS_CATALOG_IMAGES . $product_images['image']); } } } tep_db_query("delete from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$products_id . "' and id not in (" . implode(',', $piArray) . ")"); } ADD AFTER: if (($action == 'update_product') && ($_POST['products_quantity'] > 0)) { $notifications_query = tep_db_query("select customers_firstname, customers_email_address from customers where customers_id in (select customers_id from products_notifications where products_id = " . (int)$products_id . ")"); $product = tep_get_products_name((int)$products_id); $url = tep_catalog_href_link('product_info.php', 'products_id=' . (int)$products_id); $subject = sprintf(NOTIFICATION_BACK_IN_STOCK_SUBJECT, $product, STORE_NAME); $message = sprintf(NOTIFICATION_BACK_IN_STOCK_TEXT, $product, STORE_NAME, $url); $mimemessage = new email(); $text = strip_tags($message); if (EMAIL_USE_HTML == 'true') { $mimemessage->add_html($message, $text); } else { $mimemessage->add_text($text); } $mimemessage->build_message(); $emails = 0; while ($notifications = tep_db_fetch_array($notifications_query)) { $mimemessage->send($notifications['customers_firstname'], $notifications['customers_email_address'], STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, $subject); $emails++; } $messageStack->add_session(sprintf(NOTIFICATION_BACK_IN_STOCK_SENT, $emails), 'success'); } Done. Important Notes Untested. Try it at your own risk Untested. Make a fake product, make a couple of fake customers and sign up for notifications. Try updating the product. Untested. Did I mention... UNTESTED Would be better as a Hook or something but I am sure someone will do that after it is tested, because this is UNTESTED. Link to comment Share on other sites More sharing options...
douglaswalker Posted March 26, 2018 Share Posted March 26, 2018 Do you think it could be added to this module Day 07 - Per Product "Contact Us" email and product id would have to be saved into the database and then triggered on product update etc. Just a way to allow non logged in customers to enquire Doug Link to comment Share on other sites More sharing options...
burt Posted March 26, 2018 Author Share Posted March 26, 2018 24 minutes ago, douglaswalker said: Just a way to allow non logged in customers to enquire Doug, in 29DoC (from 2 years ago)...I vaguely recall; I made a box module that allows guests to sign up for notifications... Then a core code change in admin/newsletters.php to allow for such notifications to be sent to guests I'll dig it out and see if it can be plugged in. Link to comment Share on other sites More sharing options...
burt Posted April 11, 2018 Author Share Posted April 11, 2018 Now made into all-new admin page; Export to CSV customers [who have signed up to be notified] per product. View customers [who have signed up to be notified] per product. Email customers [who have signed up to be notified] per product. Delete Notifications per product. It's great to write code from nothing, you should try it. It give a real sense of achievement :) Thanks to the shopowner who saw something in this idea! Link to comment Share on other sites More sharing options...
douglaswalker Posted April 12, 2018 Share Posted April 12, 2018 Sounds great where can we find this Link to comment Share on other sites More sharing options...
multimixer Posted April 12, 2018 Share Posted April 12, 2018 I did something similar some years ago: http://multimixer.gr/16/11/2015/product-notifications-get-the-overview/ My community profile | Template system for osCommerce - New: Responsive | Feedback channel Link to comment Share on other sites More sharing options...
burt Posted April 12, 2018 Author Share Posted April 12, 2018 8 hours ago, douglaswalker said: Sounds great where can we find this Check your inbox Same goes for anyone else who wants it and supported the Project in February. Let me know by PM or email and I will send it on. Link to comment Share on other sites More sharing options...
douglaswalker Posted April 13, 2018 Share Posted April 13, 2018 Thanks Gary .. will have a play with it. Link to comment Share on other sites More sharing options...
Guest Posted June 15, 2018 Share Posted June 15, 2018 Thank You, Burt! Works great with 2.3.4.1 CE I especially love seeing the Success! 1 emails sent message at the top of my screen in Admin when I change the stock number from zero to one. Didn't get that in my 2.2 shop with notifications. Lets me know that someone (or perhaps more than one) has that product on their list and and is getting an email - very nice! - Andrea Link to comment Share on other sites More sharing options...
LeeFoster Posted June 15, 2018 Share Posted June 15, 2018 I don't need it at the moment. this is something that is expected on most modern ecommerce websites. Good work Link to comment Share on other sites More sharing options...
burt Posted June 15, 2018 Author Share Posted June 15, 2018 I extended this into a full module. Quote from a real shopowner; Quote Thanks! Quickly implemented the Notifications Module. Works great ... I did not ever pay any attention to notifications at all ... Now checked the database and there are 15559 entries in the products_notifications table!!! So - 15559 customers ticked the box "Notify me" on checkout succes .... And they NEVER - EVER received a notification 😭😂 ... That's what can happen if you run a shop/business that changes into a roaler-coaster! Link to comment Share on other sites More sharing options...
ArtcoInc Posted June 15, 2018 Share Posted June 15, 2018 @burt On 3/26/2018 at 7:07 AM, burt said: Doug, in 29DoC (from 2 years ago)...I vaguely recall; I made a box module that allows guests to sign up for notifications... Then a core code change in admin/newsletters.php to allow for such notifications to be sent to guests I'll dig it out and see if it can be plugged in. Did you ever check to see if this could be adopted for guests? M Link to comment Share on other sites More sharing options...
burt Posted June 16, 2018 Author Share Posted June 16, 2018 14 hours ago, ArtcoInc said: @burt Did you ever check to see if this could be adopted for guests? M I didn't. But if one was to use my guest notifications module from 29d20 (February 20 2016)...it should not be difficult to recode a portion of the above to make it fit. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.