When a purchase causes an offer's ``stock_current`` to drop to or below its ``minimum_ondemand`` threshold, an email is sent to ``commande@jardinenvie.com`` using an editable mail template (Spatie ``MailTemplate``). The check runs in ``OfferStocks::decreaseStock()`` after updating stock. Only threshold-crossing events trigger the alert (not every low-stock sale). Failures are caught and logged to avoid disrupting the order flow.
44 lines
993 B
PHP
44 lines
993 B
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Models\Core\Mail\MailTemplate;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Mailables\Address;
|
|
use Illuminate\Mail\Mailables\Envelope;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Spatie\MailTemplates\TemplateMailable;
|
|
|
|
class AlerteStock extends TemplateMailable
|
|
{
|
|
use Queueable, SerializesModels;
|
|
|
|
public $subject;
|
|
|
|
public $article;
|
|
|
|
public $offre;
|
|
|
|
public $stock_restant;
|
|
|
|
public $seuil;
|
|
|
|
protected static $templateModelClass = MailTemplate::class;
|
|
|
|
public function __construct($offer)
|
|
{
|
|
$this->article = $offer->article->title ?? 'Article #'.$offer->article_id;
|
|
$this->offre = $offer->id;
|
|
$this->stock_restant = $offer->stock_current;
|
|
$this->seuil = $offer->minimum_ondemand;
|
|
}
|
|
|
|
public function envelope()
|
|
{
|
|
return new Envelope(
|
|
from: new Address('boutique@jardinenvie.com', 'Jardin\'en\'Vie'),
|
|
subject: $this->subject,
|
|
);
|
|
}
|
|
}
|