Change the email language
This commit is contained in:
parent
9f667f62ba
commit
f420b145c6
@ -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 = "<p>Your payment for order #{$order_id} has been confirmed.</p>"
|
||||
. "<p><strong>Order Number:</strong> {$order_id}</p>"
|
||||
. "<p><strong>Paid Amount:</strong> " . format_money($order_details_for_email['total_amount'], get_lang(), $pdo) . "</p>"
|
||||
. "<p>Thank you for your purchase!</p>"
|
||||
. "<p>You can view your order details here: <a href='{$order_details_link}'>{$order_details_link}</a></p>";
|
||||
$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 = "<p>Payment has been confirmed for order #{$order_id}.</p>"
|
||||
. "<p><strong>Order Number:</strong> {$order_id}</p>"
|
||||
. "<p><strong>Client:</strong> {$order_details_for_email['client_company_name']}</p>"
|
||||
. "<p><strong>Paid Amount:</strong> " . format_money($order_details_for_email['total_amount'], get_lang(), $pdo) . "</p>"
|
||||
. "<p><strong>Payment Reference ID:</strong> (Online Payment)</p>"; // 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 = "<p>Great news! Your order #{$order_id} has been shipped.</p>"
|
||||
. "<p>You can track your order and view details here: <a href='{$order_details_link}'>{$order_details_link}</a></p>";
|
||||
$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
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1
db/migrations/037_add_language_to_clients.sql
Normal file
1
db/migrations/037_add_language_to_clients.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE `clients` ADD `language` VARCHAR(2) NULL DEFAULT 'en' AFTER `credit_enabled`;
|
||||
@ -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
|
||||
---
|
||||
|
||||
@ -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'];
|
||||
|
||||
6
templates/mail/en/order_shipped.php
Normal file
6
templates/mail/en/order_shipped.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$subject = "Your Order #{$order_id} has been shipped!";
|
||||
$order_details_link = get_site_url() . '/order_details.php?id=' . $order_id;
|
||||
?>
|
||||
<p>Great news! Your order #<?php echo $order_id; ?> has been shipped.</p>
|
||||
<p>You can track your order and view details here: <a href="<?php echo $order_details_link; ?>"><?php echo $order_details_link; ?></a></p>
|
||||
9
templates/mail/en/payment_confirmation.php
Normal file
9
templates/mail/en/payment_confirmation.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$subject = "Payment Confirmation for Order #{$order_id}";
|
||||
$order_details_link = get_site_url() . '/order_details.php?id=' . $order_id;
|
||||
?>
|
||||
<p>Your payment for order #<?php echo $order_id; ?> has been confirmed.</p>
|
||||
<p><strong>Order Number:</strong> <?php echo $order_id; ?></p>
|
||||
<p><strong>Paid Amount:</strong> <?php echo format_money($order_details_for_email['total_amount'], $lang, $db); ?></p>
|
||||
<p>Thank you for your purchase!</p>
|
||||
<p>You can view your order details here: <a href="<?php echo $order_details_link; ?>"><?php echo $order_details_link; ?></a></p>
|
||||
6
templates/mail/pl/order_shipped.php
Normal file
6
templates/mail/pl/order_shipped.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$subject = "Twoje zamówienie #{$order_id} zostało wysłane!";
|
||||
$order_details_link = get_site_url() . '/order_details.php?id=' . $order_id;
|
||||
?>
|
||||
<p>Dobre wieści! Twoje zamówienie #<?php echo $order_id; ?> zostało wysłane.</p>
|
||||
<p>Możesz śledzić swoje zamówienie i zobaczyć szczegóły tutaj: <a href="<?php echo $order_details_link; ?>"><?php echo $order_details_link; ?></a></p>
|
||||
9
templates/mail/pl/payment_confirmation.php
Normal file
9
templates/mail/pl/payment_confirmation.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$subject = "Potwierdzenie płatności za zamówienie #{$order_id}";
|
||||
$order_details_link = get_site_url() . '/order_details.php?id=' . $order_id;
|
||||
?>
|
||||
<p>Twoja płatność za zamówienie #<?php echo $order_id; ?> została potwierdzona.</p>
|
||||
<p><strong>Numer zamówienia:</strong> <?php echo $order_id; ?></p>
|
||||
<p><strong>Zapłacona kwota:</strong> <?php echo format_money($order_details_for_email['total_amount'], $lang, $db); ?></p>
|
||||
<p>Dziękujemy za zakup!</p>
|
||||
<p>Możesz zobaczyć szczegóły zamówienia tutaj: <a href="<?php echo $order_details_link; ?>"><?php echo $order_details_link; ?></a></p>
|
||||
Loading…
x
Reference in New Issue
Block a user