Files
WitShop/app/Mail/OrderConfirmationMail.php
marcoandClaude Sonnet 4.6 5dad8b9324
Deploy to Production (witstore.wende.it) / deploy (push) Successful in 7s
Add email templates, page layouts, and shop themes (template system)
- E-Mail-Templates: DB-gespeicherte HTML-Templates mit {{placeholder}}-System,
  Admin-UI zum Bearbeiten von Betreff und Body, alle 4 Mailables aktualisiert
- Seiten-Layouts: 4 Layouts für CMS-Seiten (Standard, Sidebar, Volle Breite, Landing),
  Layout-Auswahl im Admin-Formular
- Shop-Themes: 5 Farbthemen via CSS-Variablen, Picker in Einstellungen
- Deployment: EmailTemplateSeeder wird automatisch beim Deploy ausgeführt

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-20 22:04:54 +02:00

88 lines
4.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Mail;
use App\Models\EmailTemplate;
use App\Models\Order;
use App\Models\Setting;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class OrderConfirmationMail extends Mailable
{
use Queueable, SerializesModels;
public function __construct(public Order $order) {}
public function build()
{
$order = $this->order;
$template = EmailTemplate::getByKey('order_confirmation');
if (!$template) {
return $this
->subject('Bestellbestätigung ' . $order->order_number . ' – ' . Setting::get('shop_name'))
->view('emails.order_confirmation');
}
$itemRows = '';
foreach ($order->items as $item) {
$variant = $item->variant_label ? ' <small>(' . e($item->variant_label) . ')</small>' : '';
$itemRows .= '<tr>'
. '<td style="padding:8px;border-bottom:1px solid #eee">' . e($item->product_name) . $variant . '</td>'
. '<td style="padding:8px;border-bottom:1px solid #eee">' . $item->quantity . '</td>'
. '<td style="padding:8px;border-bottom:1px solid #eee">' . number_format($item->unit_price, 2, ',', '.') . ' €</td>'
. '<td style="padding:8px;border-bottom:1px solid #eee">' . number_format($item->line_total, 2, ',', '.') . ' €</td>'
. '</tr>';
}
$itemsTable = '<table style="width:100%;border-collapse:collapse">'
. '<thead><tr>'
. '<th style="padding:8px;background:#f8fafc;text-align:left">Artikel</th>'
. '<th style="padding:8px;background:#f8fafc;text-align:left">Menge</th>'
. '<th style="padding:8px;background:#f8fafc;text-align:left">Einzelpreis</th>'
. '<th style="padding:8px;background:#f8fafc;text-align:left">Gesamt</th>'
. '</tr></thead><tbody>' . $itemRows . '</tbody>'
. '<tfoot>'
. '<tr><td colspan="3" style="padding:8px">Zwischensumme</td><td style="padding:8px">' . number_format($order->subtotal, 2, ',', '.') . ' €</td></tr>'
. '<tr><td colspan="3" style="padding:8px">Versand</td><td style="padding:8px">' . number_format($order->shipping_cost, 2, ',', '.') . ' €</td></tr>'
. '<tr style="font-weight:bold"><td colspan="3" style="padding:8px">Gesamt (inkl. MwSt.)</td><td style="padding:8px">' . number_format($order->total, 2, ',', '.') . ' €</td></tr>'
. '</tfoot></table>';
if ($order->payment_method === 'prepayment') {
$paymentInfo = '<div style="background:#f8fafc;padding:16px;border-radius:8px;margin:16px 0">'
. '<strong>Bitte überweisen Sie den Betrag auf folgendes Konto:</strong><br>'
. 'Empfänger: ' . e(Setting::get('shop_owner')) . '<br>'
. 'Bank: ' . e(Setting::get('bank_name')) . '<br>'
. 'IBAN: ' . e(Setting::get('bank_iban')) . '<br>'
. 'BIC: ' . e(Setting::get('bank_bic')) . '<br>'
. 'Verwendungszweck: <strong>' . e($order->order_number) . '</strong><br>'
. 'Betrag: <strong>' . number_format($order->total, 2, ',', '.') . ' €</strong>'
. '</div>';
} else {
$days = Setting::get('invoice_payment_days', 14);
$paymentInfo = '<div style="background:#f8fafc;padding:16px;border-radius:8px;margin:16px 0">'
. 'Sie erhalten Ihre Rechnung separat per E-Mail.<br>'
. 'Zahlungsziel: ' . $days . ' Tage nach Rechnungserhalt.'
. '</div>';
}
$customerName = $order->billingAddress()?->full_name ?? $order->guest_email;
$data = [
'customer_name' => $customerName,
'order_number' => $order->order_number,
'order_total' => number_format($order->total, 2, ',', '.'),
'payment_info' => $paymentInfo,
'order_items_table' => $itemsTable,
'shop_name' => Setting::get('shop_name'),
'shop_email' => Setting::get('shop_email'),
'shop_address' => Setting::get('shop_address'),
];
return $this
->subject($template->renderSubject($data))
->html($template->renderBody($data));
}
}