Jump to content

evaluating array


sgreen0

Recommended Posts

I'm using Paypal Shopmaker for an online store.  It is all in PHP.  I'm not much of a programmer - especially not PHP.

 

I'd like to change the contents of the confirmation email a customer is sent for one product only.

 

Here is the original code that puts the text into the email:

 

 

} else { // Send notification email directly

ewpp_LoadEmail("ipn.txt");

 

I'd like to test the Item array for the special product and put different text into the email.  This is what I thought of:

 

 

} else { // Send notification email directly

// Add check for Total Sondheim Package

if ($ewpp_Item["ItemName"]=="Total Sondheim Seminar Package") {

ewpp_LoadEmail("ipn_total_sondheim.txt");

} else {

ewpp_LoadEmail("ipn.txt");

}

 

Do you think that might work?  Or this?

 

foreach ($arrCart as $cartItem) {

if ($cartItem["item_name"] == "Total Sondheim Seminar Package") {

ewpp_LoadEmail("ipn_total_sondheim.txt");

}

} else {

ewpp_LoadEmail("ipn.txt");

}

 

Any help you can offer would be greatly appreciated.

 

Stephen

 

Stephen

 

 

Link to comment
Share on other sites

if you want it to replace everything if it's one of the items in $arrCart... try this

$tssp = false;
foreach ($arrCart as $cartItem) {
  if ($cartItem["item_name"] == "Total Sondheim Seminar Package") {
    $tssp = true;
    break;
  }
} 
if ($tssp){
  ewpp_LoadEmail("ipn_total_sondheim.txt");
} else {
  ewpp_LoadEmail("ipn.txt");
}

Link to comment
Share on other sites

Thanks for the suggestion!  It looks good.

 

However, you comment brought up an issue I hadn't dealt with - if there are more items in the cart that just the one I'm filtering for...

 

It IS possible that a customer might buy something else along with this.  Hmmm....

 

For now, I'm going to try the code you suggested, and keep thinking about the other issue.  Any ideas?

 

Thanks again.

 

Stephen

Link to comment
Share on other sites

$tssp = false;
foreach ($arrCart as $cartItem) {
  if ($cartItem["item_name"] == "Total Sondheim Seminar Package") {
    $tssp = true;
    break;
  }
} 
if ($tssp){
  ewpp_LoadEmail("ipn_total_sondheim.txt");
}
ewpp_LoadEmail("ipn.txt");

 

? hard to know what to do without knowing more about the context

Link to comment
Share on other sites

You could make it work dynamically, if you made a naming convention for your email txt files.

 

I would suggest either the whole name of the item, or you could specify X number of characters, say 10.

 

So, if you did 10 characters, then your package name:

Total Sondheim Seminar Package

would have an email file of:

ipn_total_sond.txt

 

If you need it longer, just specify, and adjust.

Example

<?php
$tssp = array();
foreach ($arrCart as $cartItem) { 
    $tssp[] = 'ipn_' . str_replace(' ','_',substr($cartItem['item_name'],0,10)) . '.txt'; //this is the text files name: ipn_theFirst10charactersOfTheName.txt    
} 
if (!empty($tssp)) { //if tssp is not empty.
  foreach($tssp as $file) {
       if(file_exists($file)) { //search the array to see if the files exist.
            $email = $file; //the first one it finds, set the email variable, and break the loop.
            break;
       }
   }
}

if(!empty($email)) { //if email variable is set and not empty.
  ewpp_LoadEmail($email); //load the file.
} else {
  ewpp_LoadEmail("ipn.txt"); //else load the default.
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.