Zen Cart Logo
Forums / General Questions / Send additional order confirmation email based on product ordered.

Send additional order confirmation email based on product ordered.

Views: 1,416

Results 1 to 9 of 9
15 Mar 2012, 10:37 PM
#1
abcschooldr avatar

abcschooldr

New Zenner

Join Date:
Feb 2012
Posts:
77
Plugin Contributions:
0

Send additional order confirmation email based on product ordered.

I would like to send an additional order confirmation email to the purchaser with password information (based on the product purchased). How do I code order.php? ...and do I also have to change the email template?
Thank you!!!
Cindy Weber

16 Mar 2012, 9:42 AM
#2
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Send additional order confirmation email based on product ordered.

Well, that is quite a big question and has a few parts.

But you are in the right place. order.php is where the work will get done.


Firstly, have you created the password already? If not then that is a whole different subject.


You need to check that that particular product has been ordered. You'll do that in the 'for' statement that loops through all the products. It starts with this line at about 696

    for ($i=0, $n=sizeof($this->products); $i<$n; $i++) {

In there you will want to text is the current product is the right one . You'll use something like:

if( 100 == $this->products[$i]['id'] )
{
  // what you want to do goes in here.
}

That would test if the product is id=100 and then do something. I am writing the code off the top of my head so there may be typos in there :-) You can put that pretty much anywhere in the 'for' loop but see what I say lower down


Now for what you actually want to do. Well that is kind of up to you. But you can either send a separate email or add the information to the existing email.

To send a separate email look at the function zen_mail and have a look at how it is used on line 1050ish of order.php.

To add the information to the existing email you'd add the string to the $custom_information. There are some comments about how to do that at about line 880 of order.php.


Hope that all helps. It is hard to comment further without more information.

16 Mar 2012, 8:17 PM
#3
abcschooldr avatar

abcschooldr

New Zenner

Join Date:
Feb 2012
Posts:
77
Plugin Contributions:
0

Re: Send additional order confirmation email based on product ordered.

Niccol:
Thank you for your response!!
I attempted to add it to the existing email. The email is still functioning, but it does not show up in the email. I am using an elseif statement. It starts on line 985 with:
if($this->products[$i]['id'] = '4') {

 // build output for email notification
  $this->products_ordered .=  $this->products[$i]['qty'] . ' x ' . $this->products[$i]['name'] . ($this->products[$i]['model'] != '' ? ' (' . $this->products[$i]['model'] . ') ' : '') . ' = ' .
  $currencies->display_price($this->products[$i]['final_price'], $this->products[$i]['tax'], $this->products[$i]['qty']) ;

if($this->products[$i]['id'] = '4') {
$this->products_ordered_attributes .= "\n" . 'Link: link User Name: 90 Password: student (the word student, not your name)';
}
elseif($this->products[$i]['id'] = '2') {
$this->products_ordered_attributes .= "\n" . 'Link: link User Name: 90 Password: student (the word student, not your name)';
}
elseif($this->products[$i]['id'] = '7') {
$this->products_ordered_attributes .= "\n" . 'Link: link User Name: 45 Password: student (the word student, not your name)';
}
elseif($this->products[$i]['id'] = '3') {
$this->products_ordered_attributes .= "\n" . 'Link: link User Name: 45 Password: student (the word student, not your name)';
}
elseif($this->products[$i]['id'] = '8') {
$this->products_ordered_attributes .= "\n" . 'Link: link User Name: abc Password: student (the word student, not your name)';
}
elseif($this->products[$i]['id'] = '9') {
$this->products_ordered_attributes .= "\n" . 'Link: link User Name: abc Password: student (the word student, not your name)';
}
elseif($this->products[$i]['id'] = '6') {
$this->products_ordered_attributes .= "\n" . 'Link: link User Name: abc Password: student (the word student, not your name)';
}

    ($this->products[$i]['onetime_charges'] !=0 ? "\n" . TEXT_ONETIME_CHARGES_EMAIL . $currencies->display_price($this->products[$i]['onetime_charges'], $this->products[$i]['tax'], 1) : '') .

What am I doing wrong?

16 Mar 2012, 9:48 PM
#4
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Send additional order confirmation email based on product ordered.

Well the version of order.php that I am working on is a bit different so the line numbers do not match up :-) but the easiest way of doing that is about line 896

        if( 100==$this->products[$i]['id'] )
        {
        $custom_insertable_text .= 'A MESSAGE HERE';
        }

        $this->products_ordered_attributes .= $custom_insertable_text;

/* END: ADD MY CUSTOM DETAILS */

I have included the comment that exists in the original so you can find it.

That just adds a message to that product.

17 Mar 2012, 2:15 PM
#5
abcschooldr avatar

abcschooldr

New Zenner

Join Date:
Feb 2012
Posts:
77
Plugin Contributions:
0

Re: Send additional order confirmation email based on product ordered.

Thank you again!! :D What if I have multiple products? The form still works without error but nothing still shows in my email.

  •  $this->products_ordered_attributes .=  {INSERT CUSTOM INFORMATION HERE};
    

/
if( 4==$this->products[$i]['id'] )
{
$custom_insertable_text .= 'Link: User Name: 90 Password: student (the word student, not your name)';
}
$this->products_ordered_attributes .= $custom_insertable_text;
elseif( 2==$this->products[$i]['id'] )
{
$custom_insertable_text .= 'Link: User Name: 90 Password: student (the word student, not your name)';
}
$this->products_ordered_attributes .= $custom_insertable_text;
elseif( 7==$this->products[$i]['id'] )
{
$custom_insertable_text .= 'Link: User Name: 45 Password: student (the word student, not your name)';
}
$this->products_ordered_attributes .= $custom_insertable_text;
elseif( 3==$this->products[$i]['id'] )
{
$custom_insertable_text .= 'Link: User Name: 45 Password: student (the word student, not your name)';
}
$this->products_ordered_attributes .= $custom_insertable_text;
elseif( 8==$this->products[$i]['id'] )
{
$custom_insertable_text .= 'Link: User Name: abc Password: student (the word student, not your name)';
}
$this->products_ordered_attributes .= $custom_insertable_text;
elseif( 9==$this->products[$i]['id'] )
{
$custom_insertable_text .= 'Link: User Name: abc Password: student (the word student, not your name)';
}
$this->products_ordered_attributes .= $custom_insertable_text;
elseif( 6==$this->products[$i]['id'] )
{
$custom_insertable_text .= 'Link: User Name: abc Password: student (the word student, not your name)';
}
$this->products_ordered_attributes .= $custom_insertable_text;
/
END: ADD MY CUSTOM DETAILS */

Am I missing an initial statement?
Thanks again!
Cindy

17 Mar 2012, 2:53 PM
#6
abcschooldr avatar

abcschooldr

New Zenner

Join Date:
Feb 2012
Posts:
77
Plugin Contributions:
0

Re: Send additional order confirmation email based on product ordered.

I just tried it without the elseif's, and it still doesn't show on the confirmation email. Would the settings....plain text v html....make a difference here? I have it set for html, put I see plain text. Here is the 1 item version, in context, starting with if.

  •  $this->products_ordered_attributes .=  {INSERT CUSTOM INFORMATION HERE};
    

/
if( 4==$this->products[$i]['id'] )
{
$custom_insertable_text .= 'Link: User Name: 90 Password: student (the word student, not your name)';
}
$this->products_ordered_attributes .= $custom_insertable_text;
/
END: ADD MY CUSTOM DETAILS */

20 Mar 2012, 8:08 PM
#7
abcschooldr avatar

abcschooldr

New Zenner

Join Date:
Feb 2012
Posts:
77
Plugin Contributions:
0

Re: Send additional order confirmation email based on product ordered.

I am still trying. :dontgetit

This is my error:
PHP Fatal error: Cannot use string offset as an array in includes/classes/order.php on line 985
v1.3.9h

line 982 // build output for email notification
$this->products_ordered .= $this->products[$i]['qty'] . ' x ' . $this->products[$i]['name'] . ($this->products[$i]['model'] != '' ? ' (' . $this->products[$i]['model'] . ') ' : '') . ' = ' .
$currencies->display_price($this->products[$i]['final_price'], $this->products[$i]['tax'], $this->products[$i]['qty']) ;
line 985 if ($this->products_ordered[$i]['id'] =='4'.
$this->products_ordered_attributes .= "\n" . "User Name: 90 Password: student");
elseif
($this->products_ordered[$i]['id'] == '2'.
$this->products_ordered_attributes .= "\n" . "User Name: 90 Password: student");
elseif
($this->products[$i]['id'] == '7'.
$this->products_ordered_attributes .= "\n" . "User Name: 45 Password: student");
elseif
($this->products_ordered[$i]['id'] == '3'.
$this->products_ordered_attributes .= "\n" . "User Name: 45 Password: student");
elseif
($this->products_ordered[$i]['id'] == '8'.
$this->products_ordered_attributes .= "\n" . "User Name: abc Password: student");
elseif
($this->products_ordered[$i]['id'] = '9'.
$this->products_ordered_attributes .= "\n" . "User Name: abc Password: student ");
elseif
($this->products_ordered[$i]['id'] == '6'.
$this->products_ordered_attributes .= "\n" . "User Name: abc Password: student");

END ($this->products[$i]['onetime_charges'] !=0 ? "\n" . TEXT_ONETIME_CHARGES_EMAIL . $currencies->display_price($this->products[$i]['onetime_charges'], $this->products[$i]['tax'], 1) : '') .
$this->products_ordered_attributes . "\n";
$this->products_ordered_html .=

Can anyone help?

20 Mar 2012, 8:18 PM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Send additional order confirmation email based on product ordered.

line 985 if ($this->products**_ordered**[$i]['id'] =='4'.
should probably be
line 985 if ($this->products[$i]['id'] =='4'.

20 Mar 2012, 8:35 PM
#9
abcschooldr avatar

abcschooldr

New Zenner

Join Date:
Feb 2012
Posts:
77
Plugin Contributions:
0

Re: Send additional order confirmation email based on product ordered.

Thank you for the quick response! That worked! The error's gone, but it still doesn't show in the confirmation email. Here is the email.

Thanks for shopping with us today!
The following are the details of your order.

Date Ordered: Tuesday 20 March, 2012
Products

1 x 90 hour Principles, Practices and Law Hard-Copy Course =
$0.01------------------------------------------------------
Sub-Total: $0.01
Total: $0.01

Delivery Address