added new custom logical mails for preorder

This commit is contained in:
Luca Haid
2025-06-04 15:31:11 +02:00
parent ec09270472
commit b3b41a95f5
5 changed files with 177 additions and 22 deletions

View File

@@ -462,6 +462,50 @@
</div>
<?php $i++; endforeach; ?>
<?php
// echo json_encode($campaign->statusnotifcation_mailtemplates);exit;
?>
<!-- START CUSTOM LOGICAL MAIL TEMPLATES-->
<div class="form-group row p-2 mb-0 border-bottom" id="statustemplate-300-custom" style="background-color: #<?=($i%2 == 0) ? "fafafa" : "fff"?>">
<label class="col-lg-2 col-form-label text-right text-monospace" for="mailtemplates_300-custom">VA - 8 Wochen - keine Bestellung</label>
<div class="col-lg-10">
<div class="row">
<div class="col-8">
<div class="input-group">
<div class="input-group-prepend text-monospace">
<span class="input-group-text" id="basic-addon1">300 Custom</span>
</div>
<select name="mailtemplates[300-custom][mailtemplate_id]" id="mailtemplate-300-custom" class="form-control select2">
<option value=""></option>
<?php foreach(MailtemplateModel::search(["is_include" => "0"]) as $template): ?>
<!-- TODO: select value if selected-->
<option value="<?=$template->id?>" <?=(is_array($campaign->statusnotifcation_mailtemplates) && array_key_exists('300-custom', $campaign->statusnotifcation_mailtemplates) && $campaign->statusnotifcation_mailtemplates['300-custom']->mailtemplate_id == $template->id) ? "selected='selected'" : ""?>><?=$template->name?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="col">
<div class="input-group">
<div class="input-group-prepend text-monospace">
<span class="input-group-text">@</span>
</div>
<input type="text" class="form-control" name="test_to" id="test-to-300-custom"
value="" placeholder="Test E-Mail (example@test.tld)" />
<div class="input-group-append">
<button class="btn btn-outline-success" type="button" onclick="sendTestStatusEmail('300-custom')"><i class="fas fa-envelope"></i> Testmail versenden</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- END CUSTOM LOGICAL MAIL TEMPLATES -->
</div>
</div>
<?php else: ?>

View File

@@ -286,7 +286,12 @@ class Preordercampaign extends mfBaseModel {
return [];
}
foreach($snmts as $snmt) {
$this->statusnotifcation_mailtemplates[$snmt->status_code] = $snmt;
if ($snmt->status_code !== null) {
$this->statusnotifcation_mailtemplates[$snmt->status_code] = $snmt;
} else {
$logical_config = json_decode($snmt->logical_config, true);
$this->statusnotifcation_mailtemplates[$logical_config['type']] = $snmt;
}
}
return $this->statusnotifcation_mailtemplates;
}

View File

@@ -476,39 +476,50 @@ class PreordercampaignController extends mfBaseController {
$allow_on_skip = $status_data["allow_on_skip"];
$prevent_previous = $status_data["prevent_previous"];
/*if($status_code == 920) {
var_dump($status_data);exit;
}*/
if(!$mailtemplate_id && !$allow_on_skip && !$prevent_previous) {
$mailtemplates_delete[] = $status_code;
continue;
}
if($status_code == 920) {
//var_dump($status_data, $allow_on_skip, $prevent_previous);exit;
}
if($mailtemplate_id) {
// check if Mailtemplate exists
$mailtemplate = new Mailtemplate($mailtemplate_id);
if(!$mailtemplate || !$mailtemplate->id) continue;
}
$mt_data = [
"preordercampaign_id" => $campaign->id,
"status_code" => $status_code,
"mailtemplate_id" => ($mailtemplate_id) ? $mailtemplate->id : null,
"allow_on_skip" => ($allow_on_skip) ? 1 : 0,
"prevent_previous" => ($prevent_previous) ? 1 : 0,
];
// if status_code is only numbers then log it and die for debugging
if(preg_match("/^\d+$/", $status_code)) {
$mt_data = [
"preordercampaign_id" => $campaign->id,
"status_code" => $status_code,
"mailtemplate_id" => ($mailtemplate_id) ? $mailtemplate->id : null,
"allow_on_skip" => ($allow_on_skip) ? 1 : 0,
"prevent_previous" => ($prevent_previous) ? 1 : 0,
];
$statusmailtemplate = PreordercampaignStatusnotificationMailtemplate::getFirst(["preordercampaign_id" => $campaign->id, "status_code" => $status_code]);
if($statusmailtemplate) {
$statusmailtemplate->update($mt_data);
$statusmailtemplate = PreordercampaignStatusnotificationMailtemplate::getFirst(["preordercampaign_id" => $campaign->id, "status_code" => $status_code]);
if($statusmailtemplate) {
$statusmailtemplate->update($mt_data);
} else {
$statusmailtemplate = PreordercampaignStatusnotificationMailtemplate::create($mt_data);
}
} else {
$statusmailtemplate = PreordercampaignStatusnotificationMailtemplate::create($mt_data);
$mt_data = [
"preordercampaign_id" => $campaign->id,
"notification_type" => "logical",
"logical_config" => json_encode(["type" => $status_code]),
"mailtemplate_id" => ($mailtemplate_id) ? $mailtemplate->id : null,
"allow_on_skip" => ($allow_on_skip) ? 1 : 0,
"prevent_previous" => ($prevent_previous) ? 1 : 0,
];
$statusmailtemplate = PreordercampaignStatusnotificationMailtemplate::getFirst(["preordercampaign_id" => $campaign->id, "logical_config" => json_encode(["type" => $status_code])]);
if($statusmailtemplate) {
$statusmailtemplate->update($mt_data);
} else {
$statusmailtemplate = PreordercampaignStatusnotificationMailtemplate::create($mt_data);
}
}
if(!$statusmailtemplate->save()) {

View File

@@ -46,7 +46,7 @@ class PreordercampaignStatusnotificationMailtemplate extends mfBaseModel {
$model = new PreordercampaignStatusnotificationMailtemplate();
$table_fields = [
"preordercampaign_id", "status_code", "mailtemplate_id", "allow_on_skip", "prevent_previous",
"preordercampaign_id", "status_code", "mailtemplate_id", "allow_on_skip", "prevent_previous","notification_type","logical_config",
"result","create_by","edit_by","create","edit"
];
@@ -174,6 +174,15 @@ class PreordercampaignStatusnotificationMailtemplate extends mfBaseModel {
}
}
if(array_key_exists("logical_config", $filter)) {
$logical_config = $filter['logical_config'];
if(is_array($logical_config) && count($logical_config)) {
$where .= " AND PreordercampaignStatusnotificationMailtemplate.notification_type='logical' AND PreordercampaignStatusnotificationMailtemplate.logical_config = '" . json_encode($logical_config) . "'";
} elseif(is_string($logical_config)) {
$where .= " AND PreordercampaignStatusnotificationMailtemplate.notification_type='logical' AND PreordercampaignStatusnotificationMailtemplate.logical_config LIKE '%" . $logical_config . "%'";
}
}
if(array_key_exists("mailtemplate_id", $filter)) {
$mailtemplate_id = $filter['mailtemplate_id'];
if(is_numeric($mailtemplate_id)) {

View File

@@ -0,0 +1,86 @@
<?php /** @noinspection ALL */
declare(strict_types = 1);
use Phinx\Migration\AbstractMigration;
final class PreorderNotificationModify extends AbstractMigration {
public function up(): void {
if ($this->getEnvironment() == "thetool") {
$PreorderNotificationTable = $this->table("PreordercampaignStatusnotificationMailtemplate");
if ($PreorderNotificationTable->hasColumn("status_code")) {
$PreorderNotificationTable
->changeColumn("status_code", "integer", ["null" => true])
->update();
}
if (!$PreorderNotificationTable->hasColumn("notification_type")) {
$PreorderNotificationTable
->addColumn("notification_type", "enum", [
"values" => ["status", "logical"],
"default" => "status",
"null" => false,
"after" => "status_code"
])
->update();
}
if (!$PreorderNotificationTable->hasColumn("logical_config")) {
$PreorderNotificationTable
->addColumn("logical_config", "json", [
"null" => true,
"after" => "notification_type"
])
->update();
}
if (!$PreorderNotificationTable->hasIndex(["notification_type"])) {
$PreorderNotificationTable
->addIndex(["notification_type"], ["name" => "idx_notification_type"])
->update();
}
if (!$PreorderNotificationTable->hasIndex(["status_code"])) {
$PreorderNotificationTable
->addIndex(["status_code"], ["name" => "idx_status_code"])
->update();
}
}
}
public function down(): void {
if ($this->getEnvironment() == "thetool") {
$PreorderNotificationTable = $this->table("PreordercampaignStatusnotificationMailtemplate");
if ($PreorderNotificationTable->hasIndex(["notification_type"])) {
$PreorderNotificationTable
->removeIndex(["notification_type"])
->update();
}
if ($PreorderNotificationTable->hasIndex(["status_code"])) {
$PreorderNotificationTable
->removeIndex(["status_code"])
->update();
}
if ($PreorderNotificationTable->hasColumn("logical_config")) {
$PreorderNotificationTable
->removeColumn("logical_config")
->update();
}
if ($PreorderNotificationTable->hasColumn("notification_type")) {
$PreorderNotificationTable
->removeColumn("notification_type")
->update();
}
if ($PreorderNotificationTable->hasColumn("status_code")) {
$PreorderNotificationTable
->changeColumn("status_code", "integer", ["null" => false])
->update();
}
}
}
}