diff --git a/database/migrations/2023_03_01_202857_create_properties_table.php b/database/migrations/2023_03_01_202857_create_bazar_properties_table.php similarity index 100% rename from database/migrations/2023_03_01_202857_create_properties_table.php rename to database/migrations/2023_03_01_202857_create_bazar_properties_table.php diff --git a/database/migrations/2023_03_01_202959_create_property_values_table.php b/database/migrations/2023_03_01_202959_create_bazar_property_values_table.php similarity index 100% rename from database/migrations/2023_03_01_202959_create_property_values_table.php rename to database/migrations/2023_03_01_202959_create_bazar_property_values_table.php diff --git a/resources/views/emails/customer-new-order.blade.php b/resources/views/mail/order-details.blade.php similarity index 92% rename from resources/views/emails/customer-new-order.blade.php rename to resources/views/mail/order-details.blade.php index c97294f1..3340bf38 100644 --- a/resources/views/emails/customer-new-order.blade.php +++ b/resources/views/mail/order-details.blade.php @@ -1,5 +1,4 @@ -@component ('mail::message') - + # Hello, {{ $order->address->name }}! ## Thank you for your order! @@ -9,14 +8,14 @@ # Order details -@component ('mail::table') + | Product | Quantity | Tax | Price | |:--------|:--------:|:---:|:-----:| @foreach ($order->items as $item) | {{ $item->name }} | {{ $item->quantity }} | {{ $item->formattedTax }} | {{ $item->formattedPrice }} | @endforeach | **Subtotal** ||| {{ $order->formattedSubtotal }} | -@endcomponent + **Discount**: {{ $order->formattedDiscount }} @@ -38,5 +37,4 @@ {{ $order->address->postcode }} {{ $order->address->city }}, {{ $order->address->countryName }} - -@endcomponent + diff --git a/src/Interfaces/Models/Order.php b/src/Interfaces/Models/Order.php index c9f30608..a8c8d3de 100644 --- a/src/Interfaces/Models/Order.php +++ b/src/Interfaces/Models/Order.php @@ -77,4 +77,9 @@ public function refundable(): bool; * Set the status by the given value. */ public function markAs(string $status): void; + + /** + * Send the order details notification. + */ + public function sendOrderDetailsNotification(): void; } diff --git a/src/Models/Order.php b/src/Models/Order.php index 675b97dd..e23b55ce 100644 --- a/src/Models/Order.php +++ b/src/Models/Order.php @@ -5,6 +5,7 @@ use Cone\Bazar\Database\Factories\OrderFactory; use Cone\Bazar\Exceptions\TransactionFailedException; use Cone\Bazar\Interfaces\Models\Order as Contract; +use Cone\Bazar\Notifications\OrderDetails; use Cone\Bazar\Support\Facades\Gateway; use Cone\Bazar\Traits\Addressable; use Cone\Bazar\Traits\InteractsWithDiscounts; @@ -20,6 +21,7 @@ use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Notification; use Illuminate\Support\Number; class Order extends Model implements Contract @@ -343,6 +345,19 @@ public function markAs(string $status): void } } + /** + * Send the order details notification. + */ + public function sendOrderDetailsNotification(): void + { + if (is_null($this->user)) { + Notification::route('mail', [$this->address->email => $this->address->name]) + ->notify(new OrderDetails($this)); + } else { + $this->user->notify(new OrderDetails($this)); + } + } + /** * Scope a query to only include orders with the given status. */ diff --git a/src/Notifications/OrderDetails.php b/src/Notifications/OrderDetails.php new file mode 100644 index 00000000..3d06d493 --- /dev/null +++ b/src/Notifications/OrderDetails.php @@ -0,0 +1,61 @@ +order = $order; + } + + /** + * Get the notification's delivery channels. + * + * @return array + */ + public function via(object $notifiable): array + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + */ + public function toMail(object $notifiable): MailMessage + { + return (new MailMessage()) + ->subject(__('Order Details')) + ->markdown('root::mail.order-details', [ + 'order' => $this->order, + ]); + } + + /** + * Get the array representation of the notification. + * + * @return array + */ + public function toArray(object $notifiable): array + { + return [ + // + ]; + } +}