This addon allow users (guest and login) to be notified when price are changed for desired product. Sorry for poor explains, but english is not my native language. This is a fork of stock notify made it by funkydunk and other contributors, i just made necesary changes to be used for price notify instead of stock notify. This is for 4.0.18 version heavely modified, should work also with fresh instalation and maybe with other 4x version.
Known problems (hope somebody will solve this): for login users period is hardcoded and second: price value must be changed at least with 1 dollar, euro, lei etc. it's not working just for decimal price changes
WARNING: BACKUP FIRST! I'm not a good programer so use this on your own risk
Skin1 area:
customer/home_main.tpl
before this:
Quote:
{else}
{include file="common_templates.tpl"}
{/if}
|
add:
Quote:
{* mallromania price notify mod *}
{elseif $main eq "price_notify"}
{include file="modules/price_notify/pricenotify.tpl"}
{* end of mallromania price notify mod *}
|
customer/main/product.tpl
before :
Quote:
{if $product.taxes}
{include file="customer/main/taxed_price.tpl" taxes=$product.taxes}{/if} {else}
<INPUT type="text" size="7" name="price">
{/if}
|
add:
Quote:
{* mallromania price notify mod *}
{if $active_modules.price_notify ne "0"}
{ include file="modules/price_notify/notifyme.tpl" product=$product price=$product.taxed_price}
{/if}
{* end of mallromania price notify mod *}
|
create file price_notify.tpl in skin1/mail :
Quote:
{$lng.lbl_hello} {$userinfo.firstname},
{$lng.eml_price_notification}:
{$product.product}
===========================================
{$product.descr}
{$lng.eml_please_click_link}:
{$http_location}/product.php?productid={$product.productid}
{include file="mail/signature.tpl"}
|
create file price_notify_subj.tpl in skin1/mail :
Quote:
{config_load file="$skin_config"}{ $config.Company.company_name }: {$product.product} have new price !!
|
create file price_notify.tpl in skin1/mail/
html:
Quote:
{config_load file="$skin_config"}
{include file="mail/html/mail_header.tpl"}
{$lng.lbl_hello} {$userinfo.firstname},
{$lng.eml_price_notification}:
{$product.product}
</p>
{$lng.eml_please_click_link}
{include file="mail/html/signature.tpl"}
|
//new file added on 08.07.2006
create price_last_notification.tpl in the same folder as above
{config_load file="$skin_config"}
{include file="mail/html/mail_header.tpl"}
{$lng.lbl_hello} {$userinfo.firstname},
{$lng.eml_last_notification}:
{$product.product}
</p>
{$lng.eml_please_click_link}
{include file="mail/html/signature.tpl"}
_____________________________________________-
main/product_details.tpl
before
Quote:
<TR>
{if $productids ne ''}<TD width="15" class="TableSubHead"><INPUT type="checkbox" value="Y" name="fields[low_avail_limit]"></TD>{/if}
|
add:
Quote:
{* start mallromania price notify mod *}
{if $active_modules.price_notify ne ""}
<input type="hidden" name="priceold" value="{$product.price}">
<input type="hidden" name="price_notify" value="true">
{/if}
|
modules/Product_Options/product_variants.tpl
before:
Quote:
{foreachelse}
<TR>
<TD align="center" colspan="4">{$lng.lbl_variants_list_empty}</TD>
</TR>
{/foreach}
|
add:
Quote:
{* start mallromania notify mod changed for variants *}
{if $active_modules.price_notify ne ""}
<input type="hidden" name="vs[{$v.variantid}][priceold]" value="{$product.price}">
<input type="hidden" name="vs[{$v.variantid}][price_notify]" value="true">
{/if}
{* end of mallromania notify mod *}
|
modules/Product_Options/check_options.tpl
before:
Quote:
{literal}
function check_options() {
var cnt, flag;
......
|
add:
Quote:
//mallromania price notify
var link1 = "<a href='price_notify.php?productid={$product.product id}&price=$product.taxed_price&productcode=";
var link2 = "'><font class=FormButton>{$lng.lbl_price_notify_button}</font>[img]{$ImagesDir}/go.gif[/img]</a>";
var link3 = "&guest=true'><font class=FormButton>{$lng.lbl_price_notify_button}</font>[img]{$ImagesDir}/go.gif[/img]</a>";
//end mallromania price notify
|
create pricenotifyme.tpl in skin1/buttons:
Quote:
<font class=FormButton>{$lng.lbl_price_notify_button} [img]{$ImagesDir}/notifyme.gif[/img]</font>
|
create a new module into skin1/modules called price_notify (lowercase, please) and add this pages inside:
1. pricenotify.tpl
Quote:
{capture name=dialog}
{if ($login ne "") or ($guestlogged ne "")}
{include file="modules/price_notify/addedtolist.tpl"}
{else}
{include file="check_email_script.tpl"}
{include file="check_required_fields_js.tpl"}
{$lng.txt_addme_price_notify}{$product.product}
<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="price_notify.php" method="post" name="notify">
<INPUT type="hidden" name="mode" value="notify">
<INPUT type="hidden" name="productid" value="{$productid}">
<INPUT type="hidden" name="price" value="{$price}">
<TR>
<TD class="FormButton">{$lng.lbl_send_price_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>
<td>
{php}
$nextWeek = time() + (7 * 24 * 60 * 60);
$nextMonth = time() + (30 * 24 * 60 * 60);
$nextYear = time() + (365 * 24 * 60 * 60);
$now = date('Y-m-d') ."\n";
$oneweek = date('Y-m-d', $nextWeek)."\n";
$onemonth = date('Y-m-d', $nextMonth)."\n";
$oneyear = date('Y-m-d', $nextYear)."\n";
{/php}
<select name="period">
<option value="{php}echo $oneweek; "\n";{/php}">{php}echo "1 saptamana - ". $oneweek;{/php}</option>
<option value="{php}echo $onemonth; "\n";{/php}">{php}echo "1 luna - ".$onemonth;{/php}</option>
<option value="{php}echo $onemonth; "\n";{/php}">{php}echo "1 an - ".$oneyear;{/php}</option>
</select>
</td>
</TR>
</FORM>
</TABLE>
{include file="buttons/submit.tpl" style="button" button_title=$lng.lbl_price_notify_button href="javascript: if(checkRequired('')) document.notify.submit();"}
{/if}
{/capture}
{include file="dialog.tpl" title=$lng.lbl_price_notify content=$smarty.capture.dialog extra="width=100%"}
|
2. addedtolist.tpl
Quote:
{$lng.txt_added_price_notify}
|
3. notifyme.tpl
now, php pages:
include/process_product.php
before:
Quote:
# Perform SQL query to update products
if (!empty($update))
db_query("UPDATE $sql_tbl[products] SET ".implode(",", $update)." WHERE productid='$k'");
|
add:
Quote:
// mallromania added code for notify when price is lower
$watchersprice = db_query("SELECT email, period FROM `xcart_price_notify` WHERE productid = '$k'");
$newprice = func_query_first("SELECT * FROM `xcart_price_notify` WHERE productid = '$k'");
$mailprice= func_query_first("SELECT * FROM `xcart_pricing` WHERE productid = '$k'");
if (abs($mailprice['price']) < abs($newprice['price'])){
$mail_smarty->assign ("price", $mailprice); // put in to assign price
while ($row = db_fetch_array($watchersprice)){
$email = $row['email'];
$period = $row['period'];
func_send_mail($email, "mail/".$prefix."price_notify_subj.tpl", "mail/".$prefix."price_notify.tpl", $config["Company"]["orders_department"], false);
//changes
$now = date('Y-m-d');
if ($now < $period) {
func_send_mail($email, "mail/".$prefix."price_notify_subj.tpl", "mail/html/".$prefix."price_notify.tpl", $config["Company"]["orders_department"], false);
} else if ($now >= $period) {
func_send_mail($email, "mail/".$prefix."price_notify_subj.tpl", "mail/html/".$prefix."price_last_notification.tpl", $config["Company"]["orders_department"], false);
db_query("DELETE FROM `xcart_price_notify` WHERE email='" . $email . "' and productid = $productid");
}
//end changes
}
$watchersprice = "";
}
// end of code added by mallromania added code for notify when price is lower
|
include/product_modify.php
before:
Quote:
# If image was posted
if ($image_posted) {
|
add:
edited: solve errors with double ` and missing }
Quote:
// mallromania added code for notify when price is lower
if ($price_notify){
// send the email to all registered product watchers
$mailprice= func_query_first("SELECT productid, price FROM `xcart_pricing` WHERE productid = '$productid'");
$watchersprice = db_query("SELECT email, period FROM `xcart_price_notify` WHERE productid = '$productid'");
$newprice= func_query_first("SELECT * FROM `xcart_price_notify` WHERE productid = '$productid'");
if (abs($mailprice['price']) < abs($newprice['price'])){
$mail_smarty->assign ("price", $mailprice); // put in to assign product info to smarty
$mail_smarty->assign ("userinfo", $userinfo);
while ($row = db_fetch_array($watchersprice)){
$email = $row['email'];
$period = $row['period'];
//changes
$now = date('Y-m-d');
if ($now < $period) {
func_send_mail($email, "mail/".$prefix."price_notify_subj.tpl", "mail/html/".$prefix."price_notify.tpl", $config["Company"]["orders_department"], false);
} else if ($now >= $period) {
func_send_mail($email, "mail/".$prefix."price_notify_subj.tpl", "mail/html/".$prefix."price_last_notification.tpl", $config["Company"]["orders_department"], false);
db_query("DELETE FROM `xcart_price_notify` WHERE email='" . $email . "' and productid = $productid");
}
//end changes
}
}
}
// end of code added by mallromania for notify when price is lower
|
forgot to add price_notify.php, see code below
Quote:
<?php
#
# $Id: notify.php, X-Cart 4.09 2005/01/18 Maxking Exp $
#
require "./auth.php";
#
# Put all product info into $product array
#
$product_info = func_select_product($productid, @$user_account['membership']);
if (intval($cat) == 0) {
$cat = $product_info["categoryid"];
}
$main = "product";
$smarty->assign("main",$main);
include $xcart_dir.DIR_CUSTOMER."/send_to_friend.php";
if(!empty($active_modules["Product_Configurator"]))
include $xcart_dir."/modules/Product_Configurator/pconf_customer_product.php";
if(!empty($active_modules["Detailed_Product_Images"]))
include $xcart_dir."/modules/Detailed_Product_Images/product_images.php";
if(!empty($active_modules["Product_Options"]))
include $xcart_dir."/modules/Product_Options/customer_options.php";
if(!empty($active_modules["Upselling_Products"]))
include $xcart_dir."/modules/Upselling_Products/related_products.php";
if(!empty($active_modules["Advanced_Statistics"]))
include $xcart_dir."/modules/Advanced_Statistics/prod_viewed.php";
if($active_modules["Manufacturers"])
include $xcart_dir."/modules/Manufacturers/customer_manufacturers.php";
require $xcart_dir."/include/categories.php";
# NOW WE START WITH THE CHANGED FUNKYDUNKS CODE
if(($login)&& ($product_info != "") && ($active_modules["price_notify"])) {
// ie they are logged in and have selected a product
// echo "logged and ready to roll";
if (!empty($login))
$userinfo = func_userinfo($login,$login_type);
// $period = $HTTP_POST_VARS['period'];
$now = date('Y-m-d') ."\n";
$period = $now;
// echo $userinfo['email'];
// deletes their email if they are already watching this product
db_query("DELETE FROM `xcart_price_notify` WHERE email='".$userinfo['email']."' AND productid= '$productid'");
// add them to the notify table
db_query("INSERT INTO `xcart_price_notify` ( `email` , `productid`, `price`, `period`) VALUES ('".$userinfo['email']."','$productid', '$price', '".$period."')");
}
else {
if (($guestemail) && ($product_info != "") && ($active_modules["price_notify"])){
// ie they are NOT logged in and have selected a product
// echo "NOT LOGGED and ready to roll";
// echo $guestemail
// deletes their email if they are already watching this product
$period = $HTTP_POST_VARS['period'];
db_query("DELETE FROM `xcart_price_notify` WHERE email='".$guestemail."' AND productid='$productid'");
// add them to the notify table
db_query("INSERT INTO `xcart_price_notify` ( `email` , `productid`, `price`, `period`) VALUES ('".$guestemail."','$productid', '$price', '".$period."')");
//
$smarty->assign("guestlogged","true");
}
else{
if ($guest!="true"){
header("Location: error_message.php?access_denied");
exit();
}
}
}
# END OF THE CHANGED FUNKYDUNKS CODE
$smarty->assign("productid", $productid);
$smarty->assign("price", $price);
$smarty->assign("period", $period);
$smarty->assign("userinfo", $userinfo);
$smarty->assign("product",$product_info);
$smarty->assign("main","price_notify");
# Assign the current location line
$smarty->assign("location", $location);
func_display("customer/home.tpl",$smarty);
?>
|
now create table and add this:
Quote:
CREATE TABLE xcart_price_notify (
email char(12 NOT NULL default '',
productid int(11) NOT NULL default '0',
price decimal(10,2) NOT NULL default '0.00',
period date NOT NULL default '0000-00-00',
KEY email_product (email,productid)
) ENGINE=InnoDB;
INSERT INTO xcart_modules VALUES (3,'price_notify','Allows registered users to ask to be notified when a price is change for specified product','Y');
|
add this definitions to your language (some of them are already added, you better check out first):
Quote:
eml_price_notification - the following product have lower price and can be ordered by accesing link below
eml_please_click_link - Please click this link to see new price for this product
lbl_price_notify_button - Notify me when price changed
txt_added_price_notify - Your notification has been recorded
lbl_price_notify - Price change notification
//added on 08.07.2006
add new email definition:
eml_last_notification = We would like to inform you that we have new price for this product but requested period for price change notification is over.
To protect your privacy we remove your e-mail from our database. If you still want to receive notifications from us about this product price please follow this link below, add your email address and select desired period for notification.
|
see examples here (it's applied to any product), click on this text below price: Anunta-ma cand scade pretul
http://www.mallromania.ro/Notebook-Ce-Nec-Versa-M340-18-Ghz-p-16425.html