Jump to content
Latest News: (loading..)
Sign in to follow this  
burt

Product Notifications

Recommended Posts

Posted (edited)

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

  1. Untested.  Try it at your own risk
  2. Untested.  Make a fake product, make a couple of fake customers and sign up for notifications.  Try updating the product.
  3. Untested.
  4. Did I mention... UNTESTED
  5. Would be better as a Hook or something but I am sure someone will do that after it is tested, because this is UNTESTED.
Edited by burt

This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

 

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

 

Share this post


Link to post
Share on other sites
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.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

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!


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites
8 hours ago, douglaswalker said:

Sounds great 

where can we find this

:biggrin:

Check your inbox :thumbsup:

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.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

 


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

@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


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Frozen" release here

Share this post


Link to post
Share on other sites
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.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×