using an if statement in email message string

Get help with nopcart Perl, PHP or ASP checkout related issues.

Moderators: Koibito, Stefko, Randy

using an if statement in email message string

Postby batgirl » Wed Feb 23, 2011 6:19 am

In the checkout.pl script, if the shipping information is the same as the billing information, the email sends a message with the line "Same as billing information". Is there a way to do this in the checkou.php script? If the shipping fields are null, can it insert the same line? The section of code I am referring to is

$today = date ("l, F jS Y");
$strMessageBody = "";
$strMessageBody .= "A new order has been received. A summary of this order appears below.\n";
$strMessageBody .= "\n";
$strMessageBody .= "Order Date: $today \n";
$strMessageBody .= " \n";
$strMessageBody .= "Bill To: \n";
$strMessageBody .= "-------- \n";
$strMessageBody .= " $b_first $b_last \n";
$strMessageBody .= " $b_addr \n";
$strMessageBody .= " $b_addr2 \n";
$strMessageBody .= " $b_city, $b_state $b_zip \n";
$strMessageBody .= " $b_phone \n";
$strMessageBody .= " $b_fax \n";
$strMessageBody .= " $b_email \n";
$strMessageBody .= " $b_ccname \n";
$strMessageBody .= " $b_ccnumber \n";
$strMessageBody .= " $b_ccsecurity \n";
$strMessageBody .= " \n";
$strMessageBody .= " \n";
$strMessageBody .= "Ship To: \n";
$strMessageBody .= "-------- \n";
$strMessageBody .= " $s_first $s_last \n";
$strMessageBody .= " $s_addr \n";
$strMessageBody .= " $s_addr2 \n";
$strMessageBody .= " $s_city, $s_state $s_zip \n";
$strMessageBody .= " $s_phone \n";
$strMessageBody .= " \n";
$strMessageBody .= " \n";
$strMessageBody .= "Qty Price(\$) Product ID - Product Name\n";
$strMessageBody .= "===================================================================== \n";
$strMessageBody .= "$QUANTITY_1 \$$PRICE_1 $ID_1 - $NAME_1 $ADDTLINFO_1 \n";
if( $NAME_2 ) {$strMessageBody .= "$QUANTITY_2 \$$PRICE_2 $ID_2 - $NAME_2 $ADDTLINFO_2 \n";}
if( $NAME_3 ) {$strMessageBody .= "$QUANTITY_3 \$$PRICE_3 $ID_3 - $NAME_3 $ADDTLINFO_3 \n";}
if( $NAME_4 ) {$strMessageBody .= "$QUANTITY_4 \$$PRICE_4 $ID_4 - $NAME_4 $ADDTLINFO_4 \n";}
if( $NAME_5 ) {$strMessageBody .= "$QUANTITY_5 \$$PRICE_5 $ID_5 - $NAME_5 $ADDTLINFO_5 \n";}
if( $NAME_6 ) {$strMessageBody .= "$QUANTITY_6 \$$PRICE_6 $ID_6 - $NAME_6 $ADDTLINFO_6 \n";}
if( $NAME_7 ) {$strMessageBody .= "$QUANTITY_7 \$$PRICE_7 $ID_7 - $NAME_7 $ADDTLINFO_7 \n";}
if( $NAME_8 ) {$strMessageBody .= "$QUANTITY_8 \$$PRICE_8 $ID_8 - $NAME_8 $ADDTLINFO_8 \n";}
if( $NAME_9 ) {$strMessageBody .= "$QUANTITY_9 \$$PRICE_9 $ID_9 - $NAME_9 $ADDTLINFO_9 \n";}
if( $NAME_10 ){$strMessageBody .= "$QUANTITY_10 \$$PRICE_10 $ID_10 - $NAME_10 $ADDTLINFO_10 \n";}
if( $NAME_11 ){$strMessageBody .= "$QUANTITY_11 \$$PRICE_11 $ID_11 - $NAME_11 $ADDTLINFO_11 \n";}
if( $NAME_12 ){$strMessageBody .= "$QUANTITY_12 \$$PRICE_12 $ID_12 - $NAME_12 $ADDTLINFO_12 \n";}
if( $NAME_13 ){$strMessageBody .= "$QUANTITY_13 \$$PRICE_13 $ID_13 - $NAME_13 $ADDTLINFO_13 \n";}
$strMessageBody .= "===================================================================== \n";
$strMessageBody .= "SUBTOTAL: $SUBTOTAL \n";
$strMessageBody .= "TOTAL: $TOTAL \n";
$strMessageBody .= "\n";
$strMessageBody .= "FREIGHT: $SHIPPING \n";
$strMessageBody .= "\n\n";
$strMessageBody .= "Comments: \n";
$strMessageBody .= "--------- \n";
$strMessageBody .= "$comment \n";
$strMessageBody .= " \n";


There are if statements for the products but I would like to place an if statement that will bypass the shipping fields if they are blank. Any help on this would be greatly appreciated. As it stands now, all the forms are working perfectly.
batgirl
WebMaster
 
Posts: 4
Joined: Wed Feb 23, 2011 5:50 am

Re: using an if statement in email message string

Postby Koibito » Wed Feb 23, 2011 1:35 pm

Yes, you could do something like:

Code: Select all
   if( $s_last ) {print MAIL "$s_first $s_last \n $s_addr, $s_addr2 \n $s_city, $s_state $s_zip \n $s_country \n $s_phone \n";}


This will look for a last name, and if it doesn't find a last name for a shipping address, it won't display the shipping address.
John
Koibito
Site Admin / Guru
 
Posts: 918
Joined: Sun May 28, 2006 1:59 am
Location: New Jersey, USA

Re: using an if statement in email message string

Postby batgirl » Wed Feb 23, 2011 5:10 pm

This is exactly what I am looking for. Can this be modified to print out the line "Shipping is the same as Billing"?
batgirl
WebMaster
 
Posts: 4
Joined: Wed Feb 23, 2011 5:50 am

Re: using an if statement in email message string

Postby Koibito » Wed Feb 23, 2011 6:14 pm

Code: Select all
if ( $s_last ) {
print MAIL "$s_first $s_last \n $s_addr, $s_addr2 \n $s_city, $s_state $s_zip \n $s_country \n $s_phone \n\n";
} else {
print MAIL "Shipping is the same as Billing \n";
}
John
Koibito
Site Admin / Guru
 
Posts: 918
Joined: Sun May 28, 2006 1:59 am
Location: New Jersey, USA

Re: using an if statement in email message string

Postby batgirl » Wed Feb 23, 2011 8:31 pm

Thank you very much! This worked perfectly. I modified it a bit and this is what I ultimately used.

if ( $s_first ) {$strMessageBody .= "$s_first $s_last \n $s_addr \n $saddr2 \n $s_city, $s_state $s_zip \n $s_phone \n";} else {$strMessageBody .= "Shipping information same as Billing information.";}
batgirl
WebMaster
 
Posts: 4
Joined: Wed Feb 23, 2011 5:50 am


Return to Help: Perl/PHP/ASP Checkout

Who is online

Users browsing this forum: No registered users and 1 guest

cron