62 lines
1.9 KiB
PHP
62 lines
1.9 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\OrderStatusUpdated;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* "Your order is ready to collect" — fires on the same OrderStatusUpdated
|
||
|
|
* event Modules\Core\Order\Notifications\OrderStatusUpdatedNotification
|
||
|
|
* listens to, but only for the 'ready-for-pickup' transition; that other
|
||
|
|
* notification suppresses itself for this same transition (see its own
|
||
|
|
* via()) so a customer gets this richer, pickup-specific email instead of
|
||
|
|
* the generic "order updated" one, not both.
|
||
|
|
*/
|
||
|
|
class OrderPickupReadyNotification extends BaseNotification
|
||
|
|
{
|
||
|
|
public function __construct(private readonly OrderStatusUpdated $event) {}
|
||
|
|
|
||
|
|
public static function getKey(): string
|
||
|
|
{
|
||
|
|
return 'order.pickup_ready.customer.mail';
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function listensTo(): string
|
||
|
|
{
|
||
|
|
return OrderStatusUpdated::class;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function via(object $notifiable): array
|
||
|
|
{
|
||
|
|
if ($this->event->newStatus !== 'ready-for-pickup') {
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
|
||
|
|
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 is ready for pickup', ['reference' => $order->reference]))
|
||
|
|
->view('core::order.notifications.pickup-ready', [
|
||
|
|
'reference' => $order->reference,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|