Refactor customer email retrieval logic in booking and email handling

- Replace direct wash certificate email retrieval with `getWashCertificateEmail` method.
- Fallback to default email if no certificate-specific email exists.
- Adjust email assignment in booking notifications to use consistent logic.
This commit is contained in:
Jeppe Bundgaard
2025-11-27 10:50:49 +01:00
parent 2ec936225c
commit 542596b5a0
2 changed files with 6 additions and 4 deletions
+2 -1
View File
@@ -348,6 +348,7 @@ class email implements email_i
$customer->requireSelected();
$recipient_name = $customer->getCustomerName((int)$customer->customer_number->value());
$recipient_email = $customer->email->value();
$customer_contact_email = ($recipient_email ?: '');
// Check if the customer has a booking-specific email provided
if (!empty($customer->wash_certificate_email->value())) {
$recipient_email = (string)$customer->wash_certificate_email->value();
@@ -362,7 +363,7 @@ class email implements email_i
$order_booking->id,
$recipient_name,
$customer->customer_number->value(),
$customer->email->value(),
$customer_contact_email,
$order_booking->reference->value(),
$order_booking->reg_1->value(),
$order_booking->reg_2->value(),
@@ -185,9 +185,10 @@ class order_bookings_o extends db
// Check if the customer has a phone number
$country_code = $customer->phone_country_code->value();
$customer_phone = $customer->phone->value();
$customer_email = !empty($customer->wash_certificate_email->value())
? $customer->wash_certificate_email->value()
: $customer->email->value();
$customer_email = $customer->getWashCertificateEmail();
if (!$customer_email) {
$customer_email = $customer->email->value();
}
if (empty($customer_phone) && empty($customer_email)) {
return;
}