diff --git a/Layout/default/Preordercampaign/Form.php b/Layout/default/Preordercampaign/Form.php
index 0288a27fa..c141cf45b 100644
--- a/Layout/default/Preordercampaign/Form.php
+++ b/Layout/default/Preordercampaign/Form.php
@@ -462,6 +462,50 @@
+
+ statusnotifcation_mailtemplates);exit;
+ ?>
+
+
+
+
+
+
+
diff --git a/application/Preordercampaign/Preordercampaign.php b/application/Preordercampaign/Preordercampaign.php
index bdaec2012..5c71227cf 100644
--- a/application/Preordercampaign/Preordercampaign.php
+++ b/application/Preordercampaign/Preordercampaign.php
@@ -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;
}
diff --git a/application/Preordercampaign/PreordercampaignController.php b/application/Preordercampaign/PreordercampaignController.php
index 64124729c..20d50b281 100644
--- a/application/Preordercampaign/PreordercampaignController.php
+++ b/application/Preordercampaign/PreordercampaignController.php
@@ -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()) {
diff --git a/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php b/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php
index 86b7b8756..1fadfecbc 100644
--- a/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php
+++ b/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php
@@ -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)) {
diff --git a/db/migrations/20250604140000_preorder_notification_modify.php b/db/migrations/20250604140000_preorder_notification_modify.php
new file mode 100644
index 000000000..c8d02f227
--- /dev/null
+++ b/db/migrations/20250604140000_preorder_notification_modify.php
@@ -0,0 +1,86 @@
+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();
+ }
+ }
+ }
+}
\ No newline at end of file