51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Shop;
|
|
|
|
use App\Models\Order;
|
|
use App\Notifications\Shop\NewOrder;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class SendShopMail implements ShouldQueue
|
|
{
|
|
use Dispatchable;
|
|
use InteractsWithQueue;
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
/** @var \App\Models\Order */
|
|
protected $order;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(Order $order)
|
|
{
|
|
$this->order = $order;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
if (! $this->order->confirmMailSent) {
|
|
/** @var \App\Models\Customer $customerModel */
|
|
$customerModel = $this->order->customer;
|
|
$customerModel->notify(new NewOrder($this->order));
|
|
|
|
$this->order->confirmMailSent = true;
|
|
$this->order->saveOrFail();
|
|
Log::debug('Shop mail is sent', $this->order->toArray());
|
|
} else {
|
|
Log::debug('Shop mail is already sent', $this->order->toArray());
|
|
}
|
|
}
|
|
}
|