Jump to content

Which class is responsible for sending 'Shipped.html' email?


Recommended Posts

Normally when I need to adjust things about sending email, I can search for occurences of the email file name in PS. For instance, I demanded that no email was sent when specifiyng the tracking number to the shipment. I just search for occurences of "in_transit" and found the place immediately.

 

Now I want to change the behavior of the 'shipping' mail (I will set up to emails: one containing the {followup} variable and one without). But I cannot find the place in PS where the email is send.

 

Can anyone help?

Link to comment
Share on other sites

Normally when I need to adjust things about sending email, I can search for occurences of the email file name in PS. For instance, I demanded that no email was sent when specifiyng the tracking number to the shipment. I just search for occurences of "in_transit" and found the place immediately.

 

Now I want to change the behavior of the 'shipping' mail (I will set up to emails: one containing the {followup} variable and one without). But I cannot find the place in PS where the email is send.

 

Can anyone help?

 

You can't search for it because the data is in the database. The file "OrderState.php" in "classes" folder

is responsible for generating all the order status displayed for any order in "Orders" tabs in backoffice.

 

It is in line 110:

 

public static function getOrderStates($id_lang)

 

 

Look into the file AdminOrders.php under your "admin" folder and under "tabs" folder.

Look at line 137:

 

if ($history->addWithemail(true, $templateVars))

 

This class is under "OrderHistory.php" in "Classes" folder. The code is in line 131:

 

public function addWithemail($autodate = true, $templateVars = false)

 

Good luck!

Link to comment
Share on other sites

You can't search for it because the data is in the database. The file "OrderState.php" in "classes" folder is responsible for generating all the order status displayed for any order in "Orders" tabs in backoffice. It is in line 110:

public static function getOrderStates($id_lang)

Look into the file AdminOrders.php under your "admin" folder and under "tabs" folder. Look at line 137:

if ($history->addWithemail(true, $templateVars))

This class is under "OrderHistory.php" in "Classes" folder. The code is in line 131:

public function addWithemail($autodate = true, $templateVars = false)

Good luck!

 

Thank you very much. You lead me in the exact right direction. I decided to make the fix, as a small hack, in order to save time and i order to make sure I did not screw up anything. Anyone with a deeper knowledge of PS is welcome to improve this solution.

 

My problem: In PS1.5 in_transit mail is sent each time tracking number is set. Also shipping mail does not contain information of the tracking number. I wanted in_transit mail to be sent only if the order was already sent. Also I wanted shipping mail to contain information about the tracking number, but only if the tracking number is available. I don't want an unsubstituted {followup} variable to show in the shipping mail, in case tracking is not set.

 

Here is what I did with the help from yewster:

 

AdminOrdersController.php line ~306

 

											$current_order_state = $order->getCurrentOrderState();

											if ($current_order_state->shipped == 1) {
												if (@Mail::Send((int)$order->id_lang, 'in_transit', Mail::l('Package in transit', (int)$order->id_lang), $templateVars,
   $customer->email, $customer->firstname.' '.$customer->lastname, null, null, null, null,
   _PS_MAIL_DIR_, true, (int)$order->id_shop))
			 {
														Hook::exec('actionAdminOrdersTrackingNumberUpdate', array('order' => $order));
														Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
													}
													else
														$this->errors[] = Tools::displayError('An error occurred while sending e-mail to the customer.');
											}
											else {
   Hook::exec('actionAdminOrdersTrackingNumberUpdate', array('order' => $order));
   Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
											}
 }
 else
  $this->errors[] = Tools::displayError('Order carrier can\'t be updated');
}

 

In Mail.php line ~214:

  $template_html = file_get_contents($template_path.$template.'.html');
  $template_txt = strip_tags(html_entity_decode(file_get_contents($template_path.$template.'.txt'), null, 'utf-8'));

					if ($template_raw_name == 'shipped' && $template_vars['{followup}'] == null) {
						$html_string_to_remove="<br><br>Track & Trace:<br><a href="\"{followup}\"">{followup}</a>";
						$txt_line_to_remove_1="Track & Trace:";
						$txt_line_to_remove_2="{followup}";

						$template_html = str_replace($html_string_to_remove, "", $template_html);
						$template_txt = str_replace($txt_line_to_remove_1, "", $template_txt);
						$template_txt = str_replace($txt_line_to_remove_2, "", $template_txt);
					}

 

I set the $template_raw_name before adding iso-code: line ~191:

 

$template_raw_name = $template;
$template = $iso.'/'.$template;

 

And then adjusted email templates accordingly.

 

No doubt that making such "search-replace" in the Mail.php is a hack. If anyone knows a good way of setting up to shipping templates (i.e. "shipping" and "shipping_no_tracking") please shed some light.

 

Thanks again yewster!

Edited by maze (see edit history)
Link to comment
Share on other sites

  • 2 months later...
×
×
  • Create New...