diff --git a/src/controllers/Cart.php b/src/controllers/Cart.php index 57c2e20..5f93ec9 100644 --- a/src/controllers/Cart.php +++ b/src/controllers/Cart.php @@ -124,7 +124,7 @@ private function handleCheckout(): void // send confirmation email if order was successfully saved if ($success_order) { try { - (new Mailer())->sendOrderConfirmationEmail($new_order); + $signed_client->sendOrderConfirmationEmail($new_order); } catch (Exception $e) { error_log($e->getMessage()); } diff --git a/src/models/Client.php b/src/models/Client.php index 8b68493..549365c 100644 --- a/src/models/Client.php +++ b/src/models/Client.php @@ -4,6 +4,8 @@ namespace Steamy\Model; +use Exception; + class Client extends User { protected string $table = 'client'; @@ -293,4 +295,31 @@ public function toArray(): array return $base_array; } + + + /** + * @throws Exception + */ + public function sendOrderConfirmationEmail(Order $order): bool + { + $store = $order->getStore(); + if (empty($store)) { + throw new Exception('Invalid store.'); + } + + $client_full_name = ucfirst($this->first_name) . " " . ucfirst($this->last_name); + + // fill email template and save to a variable + ob_start(); + require_once __DIR__ . '/../views/mails/OrderConfirmation.php'; + $html_message = ob_get_contents(); + ob_end_clean(); + + $mailer = new Mailer(); + return $mailer->sendMail( + $this->email, + "Order Confirmation | Steamy Sips", + $html_message + ); + } } \ No newline at end of file diff --git a/src/models/Mailer.php b/src/models/Mailer.php index 7f8f3f8..4591c35 100644 --- a/src/models/Mailer.php +++ b/src/models/Mailer.php @@ -92,34 +92,5 @@ public function sendMail(string $email, string $subject, string $html_message, s // Send the message return $this->mail->send(); } - - /** - * @throws Exception - */ - public function sendOrderConfirmationEmail(Order $order): bool - { - $client = Client::getByID($order->getClientID()); - if (empty($client)) { - return false; - } - - $store = $order->getStore(); - if (empty($store)) { - return false; - } - - // fill email template and save to a variable - ob_start(); - require_once __DIR__ . '/../views/mails/OrderConfirmation.php'; - $html_message = ob_get_contents(); - ob_end_clean(); - - return $this->sendMail( - $client->getEmail(), - "Order Confirmation | Steamy Sips", - $html_message - ); - } - }