User Tools

Site Tools


tutorials:zencartmods:back_in_stock_notifications.html

Back in stock notifications

We use the Back in stock notifications plugin for zencart.

The plugin itself works out of the box, and the installation instructions are easy enough to follow, but there are a few modifications to be made that we think makes it better.

Simple Captcha

We used Securimage, which also works quite well as advertised.

Install Securimage somewhere on your webserver, and make these modifications to the Back in stock notifications plugin.

In includes/modules/pages/back_in_stock_notification_subscribe/header.php Line 56 Add

include("PATH_TO_YOUR_SECURIMAGE_PHP");
$securimg = new Securimage();
 
$valid = $securimg->check($_POST['captcha_text']);

(Obviously, you ned to replace PATH_TO_YOUR_SECURIMAGE_PHP with your own path)

Then find Line 74

else if (strtolower($_POST['email']) != strtolower($_POST['cofnospam'])) {
                $form_errors['cofnospam'] =
			BACK_IN_STOCK_NOTIFICATION_FORM_ERROR_EMAIL_CONFIRMATION_DOESNT_MATCH;
        }

and replace with

else if (strtolower($_POST['email']) != strtolower($_POST['cofnospam'])) {
                $form_errors['cofnospam'] =
			BACK_IN_STOCK_NOTIFICATION_FORM_ERROR_EMAIL_CONFIRMATION_DOESNT_MATCH;
        }
else if (!isset($_POST['captcha_text']) || $valid == false)
        {
                $form_errors['captcha'] = BACK_IN_STOCK_NOTIFICATION_FORM_ERROR_CAPTCHA;
        } 

in includes/languages/english/backin_stock_notification_subscribe.php add

define('BACK_IN_STOCK_NOTIFICATION_FORM_ERROR_CAPTCHA', 'Please verify the text on the right!');

in includes/templates/YOUR_TEMPLATE/templates/inc.html.back_in_stock_notifications.html Add wherever you want the captcha to show up (we choose L36&L113 right afer the submit button)

<img style="float: right;" src="securimage_show.php" />
                <ceon:if isset="captcha_error"><p class="alert"><ceon:variable name="captcha_error">Please verify the text on the right!</ceon:variable></p></ceon:if>
                <label class="inputLabel" for="captcha_label"><ceon:variable name="captcha_label">Verify text</ceon:variable>:</label>
                <input type="text" size="35" maxlength="96" name="captcha_text" />

Individual produts

By default, the sendBackInStockNotifications() functions sends notifications to everyone who has subscribed to any item that is back in stock.

In order to make it so you can send notifications to people who are subscribed only to certain item,

in admin/includes/functions/back_in_stock_notifications_functions.php line 32 replace

function sendBackInStockNotifications($test_mode = false)

wiwth

function sendBackInStockNotifications($test_mode = false, $products_id = 0)

and replace

        $email_addresses_query_raw = "                                                                                                                                                                                                                                        
                SELECT                                                                                                                                                                                                                                                        
                        bisns.email_address, bisns.name, c.customers_email_address, c.customers_firstname,                                                                                                                                                                    
                        c.customers_lastname                                                                                                                                                                                                                                  
                FROM                                                                                                                                                                                                                                                          
                        " . TABLE_BACK_IN_STOCK_NOTIFICATION_SUBSCRIPTIONS . " bisns                                                                                                                                                                                          
                LEFT JOIN                                                                                                                                                                                                                                                     
                        " . TABLE_PRODUCTS . " p                                                                                                                                                                                                                              
                ON                                                                                                                                                                                                                                                            
                        p.products_id = bisns.product_id                                                                                                                                                                                                                      
                LEFT JOIN                                                                                                                                                                                                                                                     
                        " . TABLE_CUSTOMERS . " c                                                                                                                                                                                                                             
                ON                                                                                                                                                                                                                                                            
                        c.customers_id = bisns.customer_id                                                                                                                                                                                                                    
                WHERE                                                                                                                                                                                                                                                         
                        p.products_quantity > 0                                                                                                                                                                                                                               
                GROUP BY                                                                                                                                                                                                                                                      
                        email_address, customers_email_address                                                                                                                                                                                                                
                ORDER BY                                                                                                                                                                                                                                                      
                        email_address, customers_email_address";

with

if( $products_id == 0)
          {
        $email_addresses_query_raw = "                                                                                                                                                                                                                                        
                SELECT                                                                                                                                                                                                                                                        
                        bisns.email_address, bisns.name, c.customers_email_address, c.customers_firstname,                                                                                                                                                                    
                        c.customers_lastname                                                                                                                                                                                                                                  
                FROM                                                                                                                                                                                                                                                          
                        " . TABLE_BACK_IN_STOCK_NOTIFICATION_SUBSCRIPTIONS . " bisns                                                                                                                                                                                          
                LEFT JOIN                                                                                                                                                                                                                                                     
                        " . TABLE_PRODUCTS . " p                                                                                                                                                                                                                              
                ON                                                                                                                                                                                                                                                            
                        p.products_id = bisns.product_id                                                                                                                                                                                                                      
                LEFT JOIN                                                                                                                                                                                                                                                     
                        " . TABLE_CUSTOMERS . " c                                                                                                                                                                                                                             
                ON                                                                                                                                                                                                                                                            
                        c.customers_id = bisns.customer_id                                                                                                                                                                                                                    
                WHERE                                                                                                                                                                                                                                                         
                        p.products_quantity > 0                                                                                                                                                                                                                               
                GROUP BY                                                                                                                                                                                                                                                      
                        email_address, customers_email_address                                                                                                                                                                                                                
                ORDER BY                                                                                                                                                                                                                                                      
                        email_address, customers_email_address";
          }
        else
          {
        $email_addresses_query_raw = "                                                                                                                                                                                                                                        
                SELECT                                                                                                                                                                                                                                                        
                        bisns.email_address, bisns.name, c.customers_email_address, c.customers_firstname,                                                                                                                                                                    
                        c.customers_lastname                                                                                                                                                                                                                                  
                FROM                                                                                                                                                                                                                                                          
                        " . TABLE_BACK_IN_STOCK_NOTIFICATION_SUBSCRIPTIONS . " bisns                                                                                                                                                                                          
                LEFT JOIN                                                                                                                                                                                                                                                     
                        " . TABLE_PRODUCTS . " p                                                                                                                                                                                                                              
                ON                                                                                                                                                                                                                                                            
                        p.products_id = bisns.product_id                                                                                                                                                                                                                      
                LEFT JOIN                                                                                                                                                                                                                                                     
                        " . TABLE_CUSTOMERS . " c                                                                                                                                                                                                                             
                ON                                                                                                                                                                                                                                                            
                        c.customers_id = bisns.customer_id                                                                                                                                                                                                                    
                WHERE                                                                                                                                                                                                                                                         
                        p.products_quantity > 0                                                                                                                                                                                                                               
                AND                                                                                                                                                                                                                                                           
                        p.products_id = " . (int)$products_id . "                                                                                                                                                                                                             
                GROUP BY                                                                                                                                                                                                                                                      
                        email_address, customers_email_address                                                                                                                                                                                                                
                ORDER BY                                                                                                                                                                                                                                                      
                        email_address, customers_email_address";
 
          }

You can now make an admin page that will send notifications only to people subscribed to a certain product by calling sendBackInStockNotifications(false, YOUR_PID).

/home/ladyada/public_html/wiki/data/pages/tutorials/zencartmods/back_in_stock_notifications.html.txt · Last modified: 2016/01/28 18:05 (external edit)