File: D:/HostingSpaces/blijegasten/blijegasten.be/app/Komma/Shop/Orders/OrderMailService.php
<?php
namespace App\Komma\Shop\Orders\Kms;
use App\Komma\Auth\AuthMailService;
use App\Komma\Shop\Orders\Mail\OrderPayLaterCustomer;
use App\Komma\Shop\Orders\Mail\OrderStatusUpdatedCustomer;
use App\Komma\Shop\Orders\Mail\OrderStatusUpdatedStaff;
use App\Komma\Shop\Orders\Models\Order;
use App\Komma\Users\Models\KmsUserRole;
use App\Komma\Users\Models\KmsUser;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
/**
* Class OrderMailService
*
* A service responsible for sending mails about orders to staff and customers
*
* @see AuthMailService
* @package App\Komma\Shop\Orders\Kms
*/
class OrderMailService implements OrderMailServiceInterface
{
/**
* Mail a customer about their current order status.
*
* @param Order $order
* @param bool $failSilentlyWhenTranslationsMissing When false a proper exception is thrown when the mail translations don't exist. When true, the mail just does not get sent.
*/
public function mailCustomerAboutCurrentOrderStatus(Order $order, bool $failSilentlyWhenTranslationsMissing = false)
{
//Verify translations
if (__('shop/orders.mail.' . $order->status . '.customer') === 'shop/orders.mail.' . $order->status . '.customer') {
//Translations do not exist.
if(!$failSilentlyWhenTranslationsMissing) throw new \RuntimeException('Could not build a mailable for a customers order with an order status of: ' . $order->status . '. The translations are not present. Most likely by design.');
return;
}
Log::debug('OrderMailService: Notifying customer with email address "'.$order->email.'" (shipping email) about order status change.');
Mail::to($order->email)->send(new OrderStatusUpdatedCustomer($order));
}
/**
* Mail a customer a pay later link.
*
* @param Order $order
*/
public function mailCustomerPayLater(Order $order)
{
Log::debug('OrderMailService: Notifying customer with email address "'.$order->email.'" (shipping email) about order status change.');
Mail::to($order->email)->send(new OrderPayLaterCustomer($order));
}
/**
* Mail Staff about an order's current status.
*
* @param Order $order
* @param bool $failSilentlyWhenTranslationsMissing When false a proper exception is thrown when the mail translations don't exist. When true, the mail just does not get sent.
*/
public function mailStaffAboutCurrentOrderStatus(Order $order, bool $failSilentlyWhenTranslationsMissing = false)
{
//Verify translations
if (__('shop/orders.mail.' . $order->status . '.staff') === 'shop/orders.mail.' . $order->status . '.staff') {
//Translations do not exist.
if(!$failSilentlyWhenTranslationsMissing) throw new \RuntimeException('Could not build a mailable for a customers order with an order status of: ' . $order->status . '. The translations are not present. Most likely by design.');
return;
}
Mail::to(config('site.mailTo'))->send(new OrderStatusUpdatedStaff($order));
// KmsUser::whereIn('role', [KmsUserRole::Admin])->get(['id', 'email'])->each(function(KmsUser $staffMember) use($order) {
// Log::debug('OrderMailService: Notifying staffMember with email address "'.$staffMember->email.'" about order status change.');
// Mail::to($staffMember->email)->send(new OrderStatusUpdatedStaff($order, $staffMember));
// });
}
}