Preorder Status Trigger Email done

This commit is contained in:
Frank Schubert
2024-12-09 16:47:11 +01:00
parent 25d4e8271f
commit 72367e2a63
9 changed files with 451 additions and 34 deletions
+48 -22
View File
@@ -167,33 +167,51 @@ class Preorder extends mfBaseModel {
$this->log->debug(__METHOD__ . ": Looking for $classname in $filepath");
if(!file_exists($filepath)) {
$this->log->debug(__METHOD__ . ": $filepath not found");
continue;
if(file_exists($filepath)) {
require_once $filepath;
}
require_once $filepath;
if(class_exists($classname)) {
$trigger = new $classname($this, $new_status);
$trigger->run();
if(!class_exists($classname)) {
$this->log->debug(__METHOD__ . ": $classname not found");
continue;
}
$trigger = new $classname($this, $new_status);
$trigger->run();
//var_dump($status["action"]);
if(array_key_exists("action", $status) && is_array($status) && property_exists($trigger, "run_action") && $trigger->run_action) {
foreach($status["action"] as $type => $action) {
if(!array_key_exists($type, $actions)) {
$actions[$type] = [];
//var_dump($status["action"]);
if (array_key_exists("action", $status) && is_array($status)) {
foreach ($status["action"] as $type => $action) {
if (!array_key_exists($type, $actions)) {
$actions[$type] = [];
}
$action["status_code"] = $intermediate_code;
$actions[$type][] = $action;
}
$action["status_code"] = $intermediate_code;
$actions[$type][] = $action;
}
} else {
$this->log->debug(__METHOD__ . ": $classname not found");
}
// TODO create email action if status templates configured in Campaign
$campaign = new Preordercampaign($this->preordercampaign_id);
if(!$campaign->id) continue;
$status_mail = PreordercampaignStatusnotificationMailtemplate::getFirst(["preordercampaign_id" => $this->preordercampaign_id, "status_code" => $intermediate_code]);
if($status_mail) {
$mailtemplate = $status_mail->mailtemplate;
if(!$mailtemplate) continue;
if(!array_key_exists("email", $actions)) {
$actions["email"] = [];
}
$actions["email"][] = [
"template" => $mailtemplate->code,
"from" => "campaign",
"data" => "preorder, adb_hausnummer, adb_wohneinheit",
"status_code" => $intermediate_code
];
}
}
//var_dump($actions);exit;
// run last email action
if(array_key_exists("email", $actions) && is_array($actions["email"]) && count($actions["email"])) {
// get last email action, ignore previous status'
@@ -210,6 +228,7 @@ class Preorder extends mfBaseModel {
}
if($send_email) {
$this->log->debug(__METHOD__.": Sending Email Action for Status ".$email_action["status_code"]);
$email_to = $this->runTriggerEmailAction($email_action);
if($email_to === false) {
$this->log->warning(__METHOD__ . ": Could not send preorder action email (Preorder " . $this->id . ")");
@@ -223,7 +242,7 @@ class Preorder extends mfBaseModel {
$psn_log->save();
}
} else {
$this->log->warning(__METHOD__.": Not sending status email because same or higher status email was sent already (Preorder ".$this->id.")");
$this->log->warning(__METHOD__.": Not sending status (".$email_action["status_code"].") email because same or higher status email was sent already (Preorder ".$this->id.")");
}
}
@@ -242,6 +261,11 @@ class Preorder extends mfBaseModel {
}
$to = $this->email;
if(array_key_exists("to", $action) && $action["to"]) {
$to = $action["to"];
}
if(!$to) {
$this->log->warning(__METHOD__.": Keine To Adresse (Preorder ".$this->id.")");
return false;
@@ -289,7 +313,9 @@ class Preorder extends mfBaseModel {
}
$subject = $mailtemplate->getVariableReplacedSubject($replacers);
$body = $mailtemplate->renderBody($replacers);
$body = "<html><head></head><body>";
$body .= $mailtemplate->renderBody($replacers);
$body .= "</body></html>\n";
$body_type = $mailtemplate->body_html ? "html" : "text";
@@ -306,7 +332,7 @@ class Preorder extends mfBaseModel {
$email->setHeader("X-".ucfirst(MFAPPNAME)."-ps", $this->getProperty("status")->code);
// add attachments
foreach($mailtemplate->files as $file) {
if($file->filename && $file->file_id && $file->file->storage_filename);
if(!$file->filename || !$file->file_id || !$file->file->store_filename) continue;
$this->log->debug($file->file->getFullPath());
$email->addAttachment($file->file->getFullPath(), null, $file->filename, $file->file->mimetype ?: null);
}