X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   if a product is outstock, notify when in stock - preorder (https://forum.x-cart.com/showthread.php?t=2471)

shishapipe 01-16-2005 08:00 AM

Quote:

They are probably saving it for one of their $99.95 addons when they hope we have all forgotten about this thread. :lol:

The thing is, i would pay for this, its cost me in time more money to try and work it out and i am not good with PHP, HTML yes, but PHP not my subject and i need this addon so bad.

shishapipe 01-16-2005 08:15 AM

Now there are 3 amended template files, these are:
skin1/customer/main/product.tpl - Just ADD between the {* funkydunk notify mod *} and {* end of funkydunk notify mod *} The rest of the code is to show you where i have placed it the skin1/customer/main/product.tpl
Code:

<TR><TD height="25" width="30%">{$lng.lbl_quantity}{if $product.min_amount gt 1}
<FONT class="ProductDetailsTitle">{$lng.txt_need_min_amount} {$product.min_amount} {$lng.lbl_items}</FONT>{/if}</TD>
<TD>
{if $config.General.unlimited_products eq "N" and ($product.avail le 0 or $product.avail lt $product.min_amount) and $variants eq ''}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var min_avail = 1;
var avail = 0;
var product_avail = 0;
</SCRIPT>
{$lng.txt_out_of_stock}

{* funkydunk notify mod *}
{if $active_modules.stock_notify ne "0"}


{ include file="modules/stock_notify/notifyme.tpl" product=$product}
{/if}
{* end of funkydunk notify mod *}

{else}
{if $config.General.unlimited_products eq "Y"}
{math equation="x+1" assign="mq" x=$config.Appearance.max_select_quantity}
{else}
{math equation="x/y" x=$config.Appearance.max_select_quantity y=$product.min_amount assign="tmp"}
{if $tmp<2}
{assign var="minamount" value=$product.min_amount}
{else}


skin1/customer/home_main.tpl - Again just add the code between {* funkydunk notify mod *} and {* end of funkydunk mod *} in the skin1/customer/home_main.tpl
Code:

{* funkydunk notify mod *}
{elseif $main eq "notify"}
{include file="modules/stock_notify/stocknotify.tpl"}
{* end of funkydunk mod *}

{include file="customer/main/welcome.tpl" f_products=$f_products newproducts=$newproducts}

{else}
{include file="common_templates.tpl"}
{/if}


skin1/main/product_details.tpl - Again just add the code between {* start funkydunk notify mod and the {* end of funkydunk notify mod
Code:

<TD class="FormButton" nowrap>{$lng.lbl_quantity_in_stock}</TD>
  <TD class="ProductDetails">
    <INPUT type="text" name="avail" size="18" value="{if $product.productid eq ""}1000{else}{ $product.avail }{/if}">
        {if $product.is_variant eq 'Y'} readonly{/if}
{if $top_message.fillerror ne "" and $product.avail eq ""}<FONT class="Star">&lt;&lt;</FONT>{/if}
{if $product.is_variant eq 'Y'}
{$lng.lbl_note}: {$lng.txt_pvariant_avail_note}{/if}
</TD>
</TR>

{* start funkydunk notify mod inserted into shopcart/skin1/main/product_details.tpl NOT shopcart/skin1/main/product_modify.tpl as per instructions for X-Cart 3.4 *}
{if $active_modules.stock_notify ne "" and $product.avail eq 0 and $product.productid ne ""}
<input type="hidden" name="oldavail" value="0">
<input type="hidden" name="notify" value="true">
{/if}
{* end of funkydunk notify mod inserted into shopcart/skin1/main/product_details.tpl NOT shopcart/skin1/main/product_modify.tpl as per instructions for X-Cart 3.4 *}


<TR>
{if $productids ne ''}<TD width="15" class="TableSubHead"><INPUT type="checkbox" value="Y" name="fields[low_avail_limit]"></TD>{/if}
  <TD class="FormButton" nowrap>{$lng.lbl_lowlimit_in_stock}</TD>
  <TD class="ProductDetails">
    <INPUT type="text" name="low_avail_limit" size="18" value="{if $product.productid eq ""}10{else}{ $product.low_avail_limit }{/if}">
{if $top_message.fillerror ne "" and $product.low_avail_limit le 0}<FONT class="Star">&lt;&lt;</FONT>{/if}
  </TD>
</TR>


shishapipe 01-16-2005 08:31 AM

Now you need to amend 2 php files, these are:
include/product_modify.php - Only add the files between // funkydunk added code for notify when back in stock and // end of code added by funkydunk for notify when back in stock.
Code:

# Update the default price
                        db_query("UPDATE $sql_tbl[pricing] SET price='$price' WHERE productid='$productid' AND quantity='1' AND membership='' AND $sql_tbl[pricing].variantid = 0");
                       
                        if($fields['price'] == 'Y' && $productids)
                                db_query("UPDATE $sql_tbl[pricing] SET price='$price' WHERE quantity='1' AND $sql_tbl[pricing].variantid = 0 AND membership=''".$products_condition);


// funkydunk added code for notify when back in stock
                if ($notify){
                        if ($avail > $oldavail){
// send the email to all registered product watchers
                        $mailproduct= func_query_first("SELECT * FROM `xcart_products` WHERE productid = '$productid'");
                        $watchers = db_query("SELECT email FROM `xcart_notify` WHERE productid = '$productid'");
// echo "SELECT * from `xcart_notify` WHERE productid = '$productid'";
                        $mail_smarty->assign ("product", $mailproduct); // put in to assign product info to smarty
                        $mail_smarty->assign ("userinfo", $userinfo);       
                                while ($row = db_fetch_array($watchers)){
// echo $row['email'];
                                        $email = $row['email'];
                                        func_send_mail($email, "mail/".$prefix."stock_notify_subj.tpl", "mail/".$prefix."stock_notify.tpl", $config["Company"]["orders_department"], false);
// delete watchers from table
                                        db_query("DELETE FROM `xcart_notify` WHERE email='" . $email . "' and productid = $productid");
                                }
                       
                        }
                }
// end of code added by funkydunk for notify when back in stock


                        # If image was posted


include/process_product.php - Only add between // funkydunk added code for notify when back in stock (shopcart/includes/process_product.php) and // end of code added by funkydunk for notify when back in stock (shopcart/includes/process_product.php)

Code:

                                # Include 'avail' field into the updating list
                                if (isset($v["avail"]) and is_numeric($v["avail"]))
                                        $update[] = "avail='".intval($v["avail"])."'";

// funkydunk added code for notify when back in stock (shopcart/includes/process_product.php) - Modify by Maxking
                        $watchers = db_query("SELECT email FROM `xcart_notify` WHERE productid = '$k'");
                        $mailproduct = func_query_first("SELECT * FROM `xcart_notify` WHERE productid = '$k'");
                        $oldavail = intval($product['avail']);
                        if ($value > $oldavail){                       
                                $mail_smarty->assign ("product", $mailproduct); // put in to assign product info to smarty
                                        while ($row = db_fetch_array($watchers)){
                                                $email = $row['email'];
                                                func_send_mail($email, "mail/".$prefix."stock_notify_subj.tpl", "mail/".$prefix."stock_notify.tpl", $config["Company"]["orders_department"], false);
db_query("DELETE FROM `xcart_notify` WHERE email='" . $email . "' AND productid= '$k'");
                                        }
                                $watchers = "";
                        }
// end of code added by funkydunk for notify when back in stock (shopcart/includes/process_product.php) - Modify by Maxking
                       
                        # Perform SQL query to update products
                                if (!empty($update))
                                        db_query("UPDATE $sql_tbl[products] SET ".implode(",", $update)." WHERE productid='$k'");


shishapipe 01-16-2005 08:35 AM

Here is the full list that you should have:
// Notify when back in stock mod
// copyright funkydunk.net 2003
// designed to allow customers to sign up to recieve an automatic email notifying them of when the product is back in stock


new template files:
shopcart/skin1/modules/stock_notify/addedtolist.tpl
shopcart/skin1/modules/stock_notify/stocknotify.tpl
shopcart/skin1/modules/stock_notify/notifyme.tpl
shopcart/skin1/buttons/notifyme.tpl
shopcart/skin1/mail/stock_notify.tpl
shopcart/skin1/mail/stock_notify_subj.tpl

shopcart/new php files:
shopcart/notify.php

amended template files:
shopcart/skin1/customer/main/product.tpl
shopcart/skin1/customer/home_main.tpl
shopcart/skin1/main/product_details.tpl

amended php files:
shopcart/include/product_modify.php
shopcart/include/process_product.php


You must add the extra items to the SQL that i posted. MAKE SURE YOU DO A SQL BACKUP FIRST. And also backup your PHP and template files so if it does not work you can revert back to your original settings.

shishapipe 01-16-2005 08:43 AM

I have checked my SQL and i get in the database:

Code:

CREATE TABLE xcart_notify (
  email varchar(100) NOT NULL ,
  productid int(11) NOT NULL
);

INSERT INTO xcart_notify VALUES ('TEST@shishapipe.net', 16246);
INSERT INTO xcart_notify VALUES ('TEST@shishapipe.net', 16247);


So that seems to be working OK with people who have logged in, but NOT guests :(

DogByteMan 01-16-2005 09:18 AM

This mod never did work but with signed in customers, I know because I was the one who originally paid the 'dunk to do it.

shishapipe 01-16-2005 01:23 PM

DELETED AS IT WAS WRONG.


DONT USE THIS ONE, USE THE ONE IN THE FOLLOWING THREADS

shishapipe 01-17-2005 07:50 AM

Also placed this code into shopcart/skin1/customer/main/buy_now.tpl
So it shows in normal mode without going to the details section.
Just add the code between {* funkydunk notify mod *} and {* end of funkydunk notify mod *}


Code:

<TD width="20%" nowrap>
{if $config.General.unlimited_products ne "Y" and ($product.avail le 0 or $product.avail lt $product.min_amount)}
{$lng.txt_out_of_stock}

{* funkydunk notify mod *}
{if $active_modules.stock_notify ne "0"}

 
{ include file="modules/stock_notify/notifyme.tpl" product=$product}
{/if}
{* end of funkydunk notify mod *}

{else}
{if $config.General.unlimited_products eq "Y"}
{math equation="x+1" assign="mq" x=$config.Appearance.max_select_quantity}
{else}


shishapipe 01-17-2005 03:07 PM

Here is the NEW X-Cart 4.09 shopcart/skin1/modules/stock_notify/stocknotify.tpl file
This sends a responce (addtolist.tpl - {$lng.txt_added_stock_notify}) to a guest once the email address has been entered correctly and also a responce (addtolist.tpl - {$lng.txt_added_stock_notify}) to a login user.

stocknotify.tpl

Code:

{* stocknotify.tpl funkydunk.net 2003 - changed by Maxking *}
{capture name=dialog}
{* OK CUSTOMER IS LOGGED IN, JUST GO TO THE STOCK NOTIFY TEXT *}
{if ($login ne "") or ($guestlogged ne "")}
{include file="modules/stock_notify/addedtolist.tpl"}
{else}
{* OK NOT LOGGED IN, SO GET THERE EMAIL ADDRESS *}
{include file="check_email_script.tpl"}
{include file="check_required_fields_js.tpl"}
{$lng.txt_addme_notify}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var requiredFields = new Array();
requiredFields[0] = new Array('guestemail', "{$lng.lbl_send_your_email|strip_tags|replace:'"':'\"'}", false);
</SCRIPT>
<TABLE border="0">
<FORM action="notify.php" method="post" name="notify">
<INPUT type="hidden" name="mode" value="notify">
<INPUT type="hidden" name="productid" value="{$productid}">
<TR><TD class="FormButton">{$lng.lbl_send_your_email}:</TD>
<TD><FONT class="Star">*</FONT></TD>
<TD><INPUT value"Enter Your Email" id="guestemail" type="text" size="45" name="guestemail" onchange="javascript: checkEmailAddress(this);"></TD>
</TR>
<TR><TD colspan="3">

{include file="buttons/submit.tpl" style="button" button_title=$lng.lbl_stock_notify_button href="javascript: if(checkRequired('')) document.notify.submit();"}</TD>
</TR>
{/if}
</FORM>
</TABLE>
{/capture}
{include file="dialog.tpl" title=$lng.lbl_stock_notify content=$smarty.capture.dialog extra="width=100%"}


shishapipe 01-17-2005 03:23 PM

Well, a guest now can request stock when it arrives back, this is the dump of my SQL after testing the notify.php script thats posted above.

Code:

INSERT INTO xcart_notify VALUES ('TEST@shishapipe.net', 16246);
INSERT INTO xcart_notify VALUES ('paul@lamari.net', 16246);
INSERT INTO xcart_notify VALUES ('triaya74@hotmail.com', 16209);
INSERT INTO xcart_notify VALUES ('triaya74@hotmail.com', 16212);
INSERT INTO xcart_notify VALUES ('triaya74@hotmail.com', 16227);
INSERT INTO xcart_notify VALUES ('triaya74@hotmail.com', 16188);
INSERT INTO xcart_notify VALUES ('triaya74@hotmail.com', 16241);
INSERT INTO xcart_notify VALUES ('triaya74@hotmail.com', 16242);
INSERT INTO xcart_notify VALUES ('TEST@shishapipe.net', 16146);
INSERT INTO xcart_notify VALUES ('guest@dontknow.com', 16246);
INSERT INTO xcart_notify VALUES ('guest@whocares.com', 16246);
INSERT INTO xcart_notify VALUES ('whocares@whocares.com', 16246);
INSERT INTO xcart_notify VALUES ('testingguess@shishapipe.net', 16247);


So its just the email that needs to be sorted now, will look at this later.

But for X-Cart 4.09 if you follow the above posts Notify will work for a guest and a reg user :)


All times are GMT -8. The time now is 05:38 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.