114 lines
4 KiB
PHP
114 lines
4 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications\Shop;
|
|
|
|
use App\Enums\Shop\OrderType;
|
|
use App\Models\Order;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
|
|
|
class NewOrder extends Notification
|
|
{
|
|
/**
|
|
* The order instance.
|
|
*
|
|
* @var \App\Models\Order
|
|
*/
|
|
protected $order;
|
|
|
|
/**
|
|
* Create a new message instance.
|
|
*
|
|
* @param \App\Models\Order $order
|
|
* @return void
|
|
*/
|
|
public function __construct(Order $order)
|
|
{
|
|
$this->order = $order;
|
|
}
|
|
|
|
/**
|
|
* Get the notification's delivery channels.
|
|
*
|
|
* @return array<int, string>
|
|
*/
|
|
public function via(): array
|
|
{
|
|
return ['mail'];
|
|
}
|
|
|
|
/**
|
|
* Get the mail representation of the notification.
|
|
*
|
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
*/
|
|
public function toMail(): \Illuminate\Notifications\Messages\MailMessage
|
|
{
|
|
return (new MailMessage())
|
|
->template('notifications::email-club')
|
|
->subject(trans('Récapitulation de votre commande - :site_name', [
|
|
'site_name' => config('app.name')
|
|
]))
|
|
->greeting(trans('Merci pour votre achat !'))
|
|
->line(trans("Votre commande a bien été prise en compte et sera traité sous les meilleurs délais."))
|
|
->line(trans("Vous pouvez retrouver le récapitulif de votre commande en pièce jointe."))
|
|
->lineIf(
|
|
$this->order->payementType->equals(OrderType::check),
|
|
trans("Si vous avez choisi un payement par chèque, veuillez l'envoyer à l'adresse suivante :")
|
|
)
|
|
->lineIf(
|
|
$this->order->payementType->equals(OrderType::check),
|
|
trans("LDC - Les Départ'Aimants Le Gaulois ZI St Laurent - CS 50925 72302 Sablé sur Sarthe")
|
|
)
|
|
->attachData($this->makePdfFile(), 'recapitulatif_commande_le_gaulois.pdf');
|
|
}
|
|
|
|
/**
|
|
* Create the recap of the order.
|
|
*
|
|
* @return string
|
|
*/
|
|
private function makePdfFile(): string
|
|
{
|
|
return LaravelMpdf::loadHTML(
|
|
view('club.pages.shop.template-pdf-order', $this->order->exportToOrderMailData())->render(),
|
|
[
|
|
'mode' => '',
|
|
'format' => 'A4',
|
|
'default_font_size' => '12',
|
|
'default_font' => 'sans-serif',
|
|
'margin_left' => 0,
|
|
'margin_right' => 0,
|
|
'margin_top' => 0,
|
|
'margin_bottom' => 0,
|
|
'margin_header' => 0,
|
|
'margin_footer' => 0,
|
|
'orientation' => 'P',
|
|
'title' => trans('Commande Le Gaulois'),
|
|
'author' => 'Le Gaulois',
|
|
'watermark' => '',
|
|
'show_watermark' => false,
|
|
'show_watermark_image' => false,
|
|
'display_mode' => 'fullpage',
|
|
'watermark_font' => 'sans-serif',
|
|
'watermark_text_alpha' => 0.1,
|
|
'watermark_image_path' => '',
|
|
'watermark_image_alpha' => 0.2,
|
|
'watermark_image_size' => 'D',
|
|
'watermark_image_position' => 'P',
|
|
'custom_font_dir' => base_path('resources/assets/fonts/'),
|
|
'custom_font_data' => [
|
|
'bouton-base' => [
|
|
'R' => 'BourtonBase.ttf'
|
|
]
|
|
],
|
|
'auto_language_detection' => false,
|
|
'temp_dir' => storage_path('app'),
|
|
'pdfa' => false,
|
|
'pdfaauto' => false,
|
|
'use_active_forms' => false,
|
|
]
|
|
)->output();
|
|
}
|
|
}
|