Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Jan 19, 2024
1 parent 0fb1c39 commit 19567ef
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@component ('mail::message')

<x-mail::message>
# Hello, {{ $order->address->name }}!

## Thank you for your order!
Expand All @@ -9,14 +8,14 @@

# Order details

@component ('mail::table')
<x-mail::table>
| Product | Quantity | Tax | Price |
|:--------|:--------:|:---:|:-----:|
@foreach ($order->items as $item)
| {{ $item->name }} | {{ $item->quantity }} | {{ $item->formattedTax }} | {{ $item->formattedPrice }} |
@endforeach
| **Subtotal** ||| {{ $order->formattedSubtotal }} |
@endcomponent
</x-mail::table>

**Discount**: {{ $order->formattedDiscount }}

Expand All @@ -38,5 +37,4 @@
{{ $order->address->postcode }}
{{ $order->address->city }},
{{ $order->address->countryName }}

@endcomponent
<x-mail::message>
5 changes: 5 additions & 0 deletions src/Interfaces/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 15 additions & 0 deletions src/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down
61 changes: 61 additions & 0 deletions src/Notifications/OrderDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Cone\Bazar\Notifications;

use Cone\Bazar\Models\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class OrderDetails extends Notification implements ShouldQueue
{
use Queueable;

/**
* The order instance.
*/
protected Order $order;

/**
* Create a new notification instance.
*/
public function __construct(Order $order)
{
$this->order = $order;
}

/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
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<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
//
];
}
}

0 comments on commit 19567ef

Please sign in to comment.