Skip to content

Commit

Permalink
move sendOrderConfirmationEmail() to Client model
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed May 19, 2024
1 parent 87670b4 commit 40cfa2f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/controllers/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
29 changes: 29 additions & 0 deletions src/models/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Steamy\Model;

use Exception;

class Client extends User
{
protected string $table = 'client';
Expand Down Expand Up @@ -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
);
}
}
29 changes: 0 additions & 29 deletions src/models/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

}

0 comments on commit 40cfa2f

Please sign in to comment.