Added replacement variables to Preordernotifcation

This commit is contained in:
Frank Schubert
2023-01-27 13:28:12 +01:00
parent fe26e8f2bc
commit eab73f53e3
2 changed files with 105 additions and 3 deletions

View File

@@ -20,7 +20,8 @@ class Preordernotification extends mfBaseModel {
public function sendToPreorder(Preorder $preorder, $email_to = false) {
$subject = $this->subject;
$body = $this->body_html; // TODO: Variable replacement
$body = $this->replaceBodyVariables($this->body_html, $preorder); // TODO: Variable replacement
//var_dump($body);exit;
$from = $this->sender_email;
$from_name = $this->sender_name;
$reply_to = null;
@@ -102,6 +103,40 @@ class Preordernotification extends mfBaseModel {
return true;
}
private function replaceBodyVariables($body, $preorder) {
$fullname = "";
if($preorder->firstname) {
$fullname = $preorder->firstname;
if($preorder->lastname) {
$fullname .= " ".$preorder->lastname;
}
} elseif($preorder->lastname) {
$fullname = $preorder->lastname;
}
$replacers = [
'VORNAME' => $preorder->firstname,
'NACHNAME' => $preorder->nachname,
'FIRMA' => $preorder->company,
'FIRMA_ODER_NAME' => ($preorder->company) ? $preorder->company : $fullname,
'EMAIL' => $preorder->email,
'ANSCHLUSS_OAID' => $preorder->adb_wohneinheit->oaid,
'ANSCHLUSS_STRASSE' => $preorder->adb_hausnummer->strasse->name,
'ANSCHLUSS_HAUSNUMMER' => $preorder->adb_hausnummer->hausnummer,
'ANSCHLUSS_PLZ' => $preorder->adb_hausnummer->plz->plz,
'ANSCHLUSS_ORT' => $preorder->adb_hausnummer->ortschaft->name,
'ANSCHLUSS_GEMEINDE' => $preorder->adb_hausnummer->strasse->gemeinde->name,
'PREORDER_CODE' => $preorder->ucode
];
foreach($replacers as $key => $replacement) {
$body = str_replace("{{".$key."}}", $replacement, $body);
}
return $body;
}
public function getProperty($name) {
if($this->$name == null) {