View Single Post
  #86  
Old 05-19-2005, 11:02 AM
 
jeanne jeanne is offline
 

Advanced Member
  
Join Date: Aug 2004
Posts: 85
 

Default Modified to work with variants 4.0.13

I modifed this a bit to work with variants and to get the product name in the email that is sent out. I am not much into coding more like messing around until something works, so use at your own risk.

First follow the directions left by sishapipe to install this mod for products without variants. Make sure that it works first before you continue and of course back up all files.

Then I added the field 'productcode' to the xcart_notify table. varchar(32) Don't add the ' s to the field.

In config.php add
Code:
"notify" => "xcart_notify",
after
Code:
"newsletter" => "xcart_newsletter",

I modified the email files and the files that generate the automatic emails to get the product name sent to the customer.

include/process_product.php
in the code submitted by sishapipe on page 4 of this thread (thanks BTW)

replace
Code:
$mailproduct = func_query_first("SELECT * FROM `xcart_notify` WHERE productid = '$k'");
with
Code:
$mailproduct= func_query_first("SELECT * FROM $sql_tbl[products] WHERE productid = '$k'");

Replace skin1/mail/stock_notify_subj.tpl with
Code:
{config_load file="$skin_config"}{ $config.Company.company_name }: {$product.product} back in stock !!

in skin1/mail/html/stock_notify.tpl I added
Code:
{$product.product}
that will put the name of the product in the body of the email. You can put it anywhere that it makes sense.

To modify for variants I changed modules/Product_Options/product_variants.php right after
Code:
db_query("UPDATE $sql_tbl[variants] SET productcode = '$v[productcode]' WHERE variantid = '$k'");
add
Code:
// funkydunk added code for notify when back in stock changed for variants if ($v[notify]){ if ($v[avail] > $v[oldavail]){ // send the email to all registered product watchers $mailproduct= func_query_first("SELECT * FROM $sql_tbl[products] WHERE productid = '$productid'"); $watchers = db_query("SELECT email FROM $sql_tbl[notify] WHERE productcode='$v[productcode]'"); //echo "SELECT * from $sql_tbl[notify] WHERE productcode= '$v[productcode]'"; $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 $sql_tbl[notify] WHERE email='" . $email . "' and productcode = '$v[productcode]'"); } } } // end of code added by funkydunk for notify when back in stock changed for variants

in skin1/modules/Product_Options/product_variants.tpl right after
Code:
<TD><INPUT type="text" size="3" name="vs[{$v.variantid}][backorder]" value="{$v.backorder}"></TD> </TR>
add
Code:
{* start funkydunk notify mod changed for variants *} {if $active_modules.stock_notify ne "" and $v.avail eq 0 and $v.productcode ne ""} <input type="hidden" name="vs[{$v.variantid}][oldavail]" value="0"> <input type="hidden" name="vs[{$v.variantid}][notify]" value="true"> {/if} {* end of funkydunk notify mod changed for *}

in skin1/customer/main/product.tpl I added
Code:
{if $variants ne ''} {if $login ne ''} <tr><td width="30%"></td><td><span id="product_productcode">{$product.productcode}</span></td></tr> {else} <tr><td width="30%"></td><td><span id="product_productcodeguest">{$product.productcode}</span></td></tr> {/if} {/if}
I put that after
Code:
<TR><TD width="30%">{$lng.lbl_quantity}</TD><TD nowrap><SPAN id="product_avail_txt">{if $product.avail gt 0}{$product.avail}</SPAN>{else}{$lng.txt_no}{/if} {$lng.txt_items_available}</TD></TR>

in skin1/modules/Product_Options/customer_options.tpl change
Code:
variants[{$k}] = new Array(new Array({$v.taxed_price|default:$v.price|default:$product.taxed_price|default:$product.price}, {$v.avail|default:0}, '{if $v.is_thumbnail eq 'Y'}{$v.variantid}{/if}', '{$v.weight|default:0}', {$v.price|default:$product.price|default:'0'}), new Array(), new Array());
to
Code:
variants[{$k}] = new Array(new Array({$v.taxed_price|default:$v.price|default:$product.taxed_price|default:$product.price}, {$v.avail|default:0}, '{if $v.is_thumbnail eq 'Y'}{$v.variantid}{/if}', '{$v.weight|default:0}', {$v.price|default:$product.price|default:'0'}, '{$v.productcode}'), new Array(), new Array());
after
Code:
var is_unlimit = '{$config.General.unlimited_products}';
add
Code:
var link1 = "<a href='notify.php?productid={$product.productid}&productcode="; var link2 = "'><font class=FormButton>{$lng.lbl_stock_notify_button}</font>[img]{$ImagesDir}/go.gif[/img]</a>"; var link3 = "&guest=true'><font class=FormButton>{$lng.lbl_stock_notify_button}</font>[img]{$ImagesDir}/go.gif[/img]</a>";
after
Code:
if(document.getElementById('product_weight')) document.getElementById('product_weight').innerHTML = variants[x][0][3];
add
Code:
if(document.getElementById('product_productcode')){ if (avail <= 0) document.getElementById('product_productcode').innerHTML = link1+variants[x][0][5]+link2; else document.getElementById('product_productcode').innerHTML = ""; } if(document.getElementById('product_productcodeguest')){ if (avail <= 0) document.getElementById('product_productcodeguest').innerHTML = link1+variants[x][0][5]+link3; else document.getElementById('product_productcodeguest').innerHTML = ""; }

For your products with variants the link to the notify me page will only show up when you are out of stock on the variant. I modified the link on the products without variants as well so that it won't show {if $product.avail le 1}...{/if} I am not using the 'Buy Now' feature so I am not sure how that would be afftected.
__________________
Jeanne
4.1.8 Gold
Reply With Quote