From f420b145c6425e73e674222427e9d8701f098be6 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 9 Jan 2026 11:53:04 +0000 Subject: [PATCH] Change the email language --- admin/order_details.php | 59 +++++++------------ db/migrations/037_add_language_to_clients.sql | 1 + debug_price.log | 49 +++++++++++++++ includes/init.php | 16 ++++- templates/mail/en/order_shipped.php | 6 ++ templates/mail/en/payment_confirmation.php | 9 +++ templates/mail/pl/order_shipped.php | 6 ++ templates/mail/pl/payment_confirmation.php | 9 +++ 8 files changed, 117 insertions(+), 38 deletions(-) create mode 100644 db/migrations/037_add_language_to_clients.sql create mode 100644 templates/mail/en/order_shipped.php create mode 100644 templates/mail/en/payment_confirmation.php create mode 100644 templates/mail/pl/order_shipped.php create mode 100644 templates/mail/pl/payment_confirmation.php diff --git a/admin/order_details.php b/admin/order_details.php index 5b404e0..546f266 100644 --- a/admin/order_details.php +++ b/admin/order_details.php @@ -45,7 +45,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['status']) && get_user // Fetch order and client details for email $stmt = $pdo->prepare(" - SELECT o.*, c.name as client_company_name, u.email as client_email + SELECT o.*, c.name as client_company_name, c.language as client_language, u.email as client_email FROM orders o JOIN clients c ON o.client_id = c.id JOIN users u ON c.id = u.client_id @@ -56,36 +56,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['status']) && get_user if ($order_details_for_email && !empty($order_details_for_email['client_email'])) { $client_email = $order_details_for_email['client_email']; - $order_details_link = get_site_url() . '/order_details.php?id=' . $order_id; - $admin_email = getenv('MAIL_TO') ?: 'admin@example.com'; + $client_language = $order_details_for_email['client_language'] ?? 'en'; // 4. Client - Payment Confirmation - $subject_client = "Payment Confirmation for Order #{$order_id}"; - $body_html_client = "

Your payment for order #{$order_id} has been confirmed.

" - . "

Order Number: {$order_id}

" - . "

Paid Amount: " . format_money($order_details_for_email['total_amount'], get_lang(), $pdo) . "

" - . "

Thank you for your purchase!

" - . "

You can view your order details here: {$order_details_link}

"; - $body_text_client = "Your payment for order #{$order_id} has been confirmed.\n" - . "Order Number: {$order_id}\n" - . "Paid Amount: " . format_money($order_details_for_email['total_amount'], get_lang(), $pdo) . "\n" - . "Thank you for your purchase!\n" - . "View your order details here: {$order_details_link}"; - MailService::sendMail($client_email, $subject_client, $body_html_client, $body_text_client); + MailService::sendTemplatedMail( + $client_email, + $client_language, + 'payment_confirmation', + [ + 'order_id' => $order_id, + 'order_details_for_email' => $order_details_for_email + ] + ); + - // 5. Admin - Payment Confirmation - $subject_admin = "Payment Received for Order #{$order_id}"; - $body_html_admin = "

Payment has been confirmed for order #{$order_id}.

" - . "

Order Number: {$order_id}

" - . "

Client: {$order_details_for_email['client_company_name']}

" - . "

Paid Amount: " . format_money($order_details_for_email['total_amount'], get_lang(), $pdo) . "

" - . "

Payment Reference ID: (Online Payment)

"; // Placeholder - $body_text_admin = "Payment has been confirmed for order #{$order_id}.\n" - . "Order Number: {$order_id}\n" - . "Client: {$order_details_for_email['client_company_name']}\n" - . "Paid Amount: " . format_money($order_details_for_email['total_amount'], get_lang(), $pdo) . "\n" - . "Payment Reference ID: (Online Payment)"; // Placeholder - MailService::sendMail($admin_email, $subject_admin, $body_html_admin, $body_text_admin); } } @@ -94,7 +78,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['status']) && get_user // Fetch order and client details for email $stmt = $pdo->prepare(" - SELECT o.*, c.name as client_company_name, u.email as client_email + SELECT o.*, c.name as client_company_name, c.language as client_language, u.email as client_email FROM orders o JOIN clients c ON o.client_id = c.id JOIN users u ON c.id = u.client_id @@ -105,15 +89,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['status']) && get_user if ($order_details_for_email && !empty($order_details_for_email['client_email'])) { $client_email = $order_details_for_email['client_email']; - $order_details_link = get_site_url() . '/order_details.php?id=' . $order_id; - - $subject_client = "Your Order #{$order_id} has been shipped!"; - $body_html_client = "

Great news! Your order #{$order_id} has been shipped.

" - . "

You can track your order and view details here: {$order_details_link}

"; - $body_text_client = "Great news! Your order #{$order_id} has been shipped.\n" - . "You can track your order and view details here: {$order_details_link}"; + $client_language = $order_details_for_email['client_language'] ?? 'en'; - MailService::sendMail($client_email, $subject_client, $body_html_client, $body_text_client); + MailService::sendTemplatedMail( + $client_email, + $client_language, + 'order_shipped', + [ + 'order_id' => $order_id + ] + ); } } diff --git a/db/migrations/037_add_language_to_clients.sql b/db/migrations/037_add_language_to_clients.sql new file mode 100644 index 0000000..fb231b3 --- /dev/null +++ b/db/migrations/037_add_language_to_clients.sql @@ -0,0 +1 @@ +ALTER TABLE `clients` ADD `language` VARCHAR(2) NULL DEFAULT 'en' AFTER `credit_enabled`; \ No newline at end of file diff --git a/debug_price.log b/debug_price.log index 3ba4866..717d197 100644 --- a/debug_price.log +++ b/debug_price.log @@ -14717,3 +14717,52 @@ Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84 Found product price. Net: 233.2, Gross: 286.84 FINAL: Returning Net: 233.2, Gross: 286.84 --- +--- +START getEffectivePrice for product 1, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1111.00","price_gross":"1366.53"} +Found product price. Net: 1111, Gross: 1366.53 +FINAL: Returning Net: 1111, Gross: 1366.53 +--- +--- +START getEffectivePrice for product 2, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"1318.05","price_gross":"1621.20"} +Found product price. Net: 1318.05, Gross: 1621.2 +FINAL: Returning Net: 1318.05, Gross: 1621.2 +--- +--- +START getEffectivePrice for product 3, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 4, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"9.95","price_gross":"12.24"} +Found product price. Net: 9.95, Gross: 12.24 +FINAL: Returning Net: 9.95, Gross: 12.24 +--- +--- +START getEffectivePrice for product 5, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"68.00","price_gross":"83.64"} +Found product price. Net: 68, Gross: 83.64 +FINAL: Returning Net: 68, Gross: 83.64 +--- +--- +START getEffectivePrice for product 6, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"171.60","price_gross":"211.07"} +Found product price. Net: 171.6, Gross: 211.07 +FINAL: Returning Net: 171.6, Gross: 211.07 +--- +--- +START getEffectivePrice for product 7, client +Client price not found or not set, falling back to product price. +Product price query executed. Found: {"price_net":"233.20","price_gross":"286.84"} +Found product price. Net: 233.2, Gross: 286.84 +FINAL: Returning Net: 233.2, Gross: 286.84 +--- diff --git a/includes/init.php b/includes/init.php index b177425..5b9ff9b 100644 --- a/includes/init.php +++ b/includes/init.php @@ -10,7 +10,21 @@ require_once __DIR__ . '/helpers.php'; require_once __DIR__ . '/currency.php'; if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['lang'])) { - set_lang($_GET['lang']); + $new_lang = $_GET['lang']; + set_lang($new_lang); + + if (is_logged_in()) { + $user_id = $_SESSION['user_id']; + $stmt = db()->prepare("SELECT client_id FROM users WHERE id = ?"); + $stmt->execute([$user_id]); + $client_id = $stmt->fetchColumn(); + + if ($client_id) { + $stmt = db()->prepare("UPDATE clients SET language = ? WHERE id = ?"); + $stmt->execute([$new_lang, $client_id]); + } + } + $uri = $_SERVER['REQUEST_URI']; $url_parts = parse_url($uri); $path = $url_parts['path']; diff --git a/templates/mail/en/order_shipped.php b/templates/mail/en/order_shipped.php new file mode 100644 index 0000000..c05cb18 --- /dev/null +++ b/templates/mail/en/order_shipped.php @@ -0,0 +1,6 @@ + +

Great news! Your order # has been shipped.

+

You can track your order and view details here:

diff --git a/templates/mail/en/payment_confirmation.php b/templates/mail/en/payment_confirmation.php new file mode 100644 index 0000000..b7d963b --- /dev/null +++ b/templates/mail/en/payment_confirmation.php @@ -0,0 +1,9 @@ + +

Your payment for order # has been confirmed.

+

Order Number:

+

Paid Amount:

+

Thank you for your purchase!

+

You can view your order details here:

diff --git a/templates/mail/pl/order_shipped.php b/templates/mail/pl/order_shipped.php new file mode 100644 index 0000000..faafae7 --- /dev/null +++ b/templates/mail/pl/order_shipped.php @@ -0,0 +1,6 @@ + +

Dobre wieści! Twoje zamówienie # zostało wysłane.

+

Możesz śledzić swoje zamówienie i zobaczyć szczegóły tutaj:

diff --git a/templates/mail/pl/payment_confirmation.php b/templates/mail/pl/payment_confirmation.php new file mode 100644 index 0000000..9218f3a --- /dev/null +++ b/templates/mail/pl/payment_confirmation.php @@ -0,0 +1,9 @@ + +

Twoja płatność za zamówienie # została potwierdzona.

+

Numer zamówienia:

+

Zapłacona kwota:

+

Dziękujemy za zakup!

+

Możesz zobaczyć szczegóły zamówienia tutaj: