50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Core\Order\Notifications;
|
|
|
|
use Illuminate\Notifications\AnonymousNotifiable;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Support\Facades\Notification as NotificationFacade;
|
|
use Modules\Core\Notification\BaseNotification;
|
|
use Modules\Core\Order\Events\OrderDelivered;
|
|
|
|
class OrderDeliveredNotification extends BaseNotification
|
|
{
|
|
public function __construct(private readonly OrderDelivered $event) {}
|
|
|
|
public static function getKey(): string
|
|
{
|
|
return 'order.delivered.customer.mail';
|
|
}
|
|
|
|
public static function listensTo(): string
|
|
{
|
|
return OrderDelivered::class;
|
|
}
|
|
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['mail'];
|
|
}
|
|
|
|
public function notifiable(): AnonymousNotifiable
|
|
{
|
|
$order = $this->event->order;
|
|
|
|
$email = $order->billingAddress?->contact_email ?? $order->shippingAddress?->contact_email;
|
|
|
|
return NotificationFacade::route('mail', $email);
|
|
}
|
|
|
|
public function toMail(object $notifiable): MailMessage
|
|
{
|
|
$order = $this->event->order;
|
|
|
|
return (new MailMessage)
|
|
->subject(__('Your order :reference has been delivered', ['reference' => $order->reference]))
|
|
->view('core::order.notifications.delivered', [
|
|
'reference' => $order->reference,
|
|
]);
|
|
}
|
|
}
|