From 2adf180c091715002af70fdefbb086e8e13eb50b Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Wed, 6 Aug 2025 14:10:18 +0200 Subject: [PATCH] Fixed Preorder order_date saving and getting setup price --- application/Preorder/PreorderController.php | 16 +++++++++++----- .../PreorderBillingController.php | 3 ++- scripts/preorder/custom_notifications/init.php | 2 ++ .../send-preorder-custom-new-notification.php | 8 +++++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php index 11f600844..9a11fefff 100644 --- a/application/Preorder/PreorderController.php +++ b/application/Preorder/PreorderController.php @@ -1168,11 +1168,17 @@ class PreorderController extends mfBaseController { } - - $orderdate_ts = Layout::dateToInt($order_date); - $preorder->order_date = $orderdate_ts; - if(!$preorder->save()) { - $this->log->debug(__METHOD__.": error saving orderdate"); + try { + $orderdate_dt = DateTime::createFromFormat("d.m.Y", $order_date); + $orderdate_dt->setTime(4, 0, 0); + $preorder->order_date = $orderdate_dt->getTimestamp(); + //$orderdate_ts = Layout::dateToInt($order_date); + if(!$preorder->save()) { + $this->log->debug(__METHOD__ . ": error saving orderdate"); + return false; + } + } catch (Exception $e) { + $this->log->debug(__METHOD__.": Exception: ".$e->getMessage()); return false; } diff --git a/application/PreorderBilling/PreorderBillingController.php b/application/PreorderBilling/PreorderBillingController.php index ce4cf2b60..e4b8222f2 100644 --- a/application/PreorderBilling/PreorderBillingController.php +++ b/application/PreorderBilling/PreorderBillingController.php @@ -203,8 +203,9 @@ class PreorderBillingController extends mfBaseController { } else { $order_date = new DateTime('@'.$preorder->create); } - $order_date->setTime(4,0,0); $order_date->setTimezone(new DateTimeZone("Europe/Vienna")); + $order_date->setTime(4,0,0); + if($order_date->format("Ymd") < $earliest_bill_date->format("Ymd")) { // start billing from 2025-01-01 diff --git a/scripts/preorder/custom_notifications/init.php b/scripts/preorder/custom_notifications/init.php index 777c220a7..332433c27 100644 --- a/scripts/preorder/custom_notifications/init.php +++ b/scripts/preorder/custom_notifications/init.php @@ -18,6 +18,8 @@ define("MFBASE_BYPASS_LOGIN", true); $db = FronkDB::singleton(); $db = $db->link; +$log = mfLoghandler::singleton(); + function logMessage($message): void { echo "[" . date("Y-m-d H:i:s") . "] " . $message . "\n"; } diff --git a/scripts/preorder/custom_notifications/send-preorder-custom-new-notification.php b/scripts/preorder/custom_notifications/send-preorder-custom-new-notification.php index 82ab9e014..7de5a1d87 100644 --- a/scripts/preorder/custom_notifications/send-preorder-custom-new-notification.php +++ b/scripts/preorder/custom_notifications/send-preorder-custom-new-notification.php @@ -3,6 +3,7 @@ global $db; require_once __DIR__.'/init.php'; + $earliest_order_date = new DateTime("2025-05-01"); $earliest_order_date->setTimezone(new DateTimeZone("Europe/Vienna")); @@ -37,6 +38,7 @@ WHERE p.type = 'order' AND psnl.id IS NULL -- No existing '300-custom-new-order' notification AND p.create > ".$earliest_order_date->getTimestamp()." -- no older than \$earliest_order_date AND p.create < (UNIX_TIMESTAMP(NOW()) - 7200) -- Only consider preorders older than 2 hours + AND p.id=22456 ORDER BY p.id ASC;"; $res = $db->query($sql); @@ -118,8 +120,10 @@ while($row = $res->fetch_assoc()) { } else { $order_date = new DateTime('@'.$preorder->create); } - $order_date->setTime(4,0,0); $order_date->setTimezone(new DateTimeZone("Europe/Vienna")); + $order_date->setTime(4,0,0); + + $product = PreorderProduct::getFirst(["type" => "enduser_setup"]); if(!$product) { @@ -144,6 +148,8 @@ while($row = $res->fetch_assoc()) { $price_setup *= 1.2; } + $log->debug(__FILE__.": Sending template $template_embed_name for Preorder ".$preorder->id." OAID ".$preorder->oaid); + sendPreorderEmail( $mailtemplate, $preordercampaign,