@fleetbase/storefront-engine 0.3.23 → 0.3.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon/adapters/catalog.js +1 -0
- package/addon/adapters/food-truck.js +1 -0
- package/addon/components/customer-panel/orders.hbs +7 -1
- package/addon/components/modals/assign-food-truck-catalogs.hbs +14 -0
- package/addon/components/modals/create-catalog.hbs +96 -0
- package/addon/components/modals/create-first-store.hbs +6 -1
- package/addon/components/modals/create-food-truck.hbs +69 -0
- package/addon/components/modals/manage-addons.js +1 -15
- package/addon/components/order-panel.hbs +2 -2
- package/addon/components/widget/customers.hbs +5 -5
- package/addon/components/widget/orders.hbs +7 -4
- package/addon/components/widget/orders.js +11 -1
- package/addon/controllers/catalogs/index.js +121 -0
- package/addon/controllers/food-trucks/index.js +100 -0
- package/addon/models/catalog-category.js +6 -0
- package/addon/models/catalog-hour.js +72 -0
- package/addon/models/catalog.js +45 -0
- package/addon/models/food-truck.js +47 -0
- package/addon/models/product.js +1 -0
- package/addon/routes/catalogs/index.js +22 -0
- package/addon/routes/catalogs.js +3 -0
- package/addon/routes/food-trucks/index.js +22 -0
- package/addon/routes/food-trucks.js +3 -0
- package/addon/routes.js +6 -0
- package/addon/serializers/catalog-category.js +15 -0
- package/addon/serializers/catalog.js +16 -0
- package/addon/serializers/food-truck.js +18 -0
- package/addon/serializers/product-variant.js +0 -1
- package/addon/services/storefront.js +1 -1
- package/addon/styles/storefront-engine.css +15 -5
- package/addon/templates/application.hbs +14 -0
- package/addon/templates/catalogs/index.hbs +46 -0
- package/addon/templates/catalogs.hbs +1 -0
- package/addon/templates/customers/index.hbs +1 -1
- package/addon/templates/food-trucks/index.hbs +52 -0
- package/addon/templates/food-trucks.hbs +1 -0
- package/addon/templates/networks/index.hbs +14 -2
- package/addon/templates/products/index/category/new.hbs +10 -3
- package/addon/templates/products/index/index.hbs +1 -2
- package/addon/templates/products/index.hbs +16 -2
- package/app/adapters/catalog.js +1 -0
- package/app/adapters/food-truck.js +1 -0
- package/app/components/modals/assign-food-truck-catalogs.js +1 -0
- package/app/components/modals/create-catalog.js +1 -0
- package/app/components/modals/create-food-truck.js +1 -0
- package/app/controllers/catalogs/index.js +1 -0
- package/app/controllers/food-trucks/index.js +1 -0
- package/app/models/catalog-category.js +1 -0
- package/app/models/catalog-hour.js +1 -0
- package/app/models/catalog.js +1 -0
- package/app/models/food-truck.js +1 -0
- package/app/routes/catalogs/index.js +1 -0
- package/app/routes/catalogs.js +1 -0
- package/app/routes/food-trucks/index.js +1 -0
- package/app/routes/food-trucks.js +1 -0
- package/app/serializers/catalog-category.js +1 -0
- package/app/serializers/catalog.js +1 -0
- package/app/serializers/food-truck.js +1 -0
- package/app/templates/catalogs/index.js +1 -0
- package/app/templates/catalogs.js +1 -0
- package/app/templates/food-trucks/index.js +1 -0
- package/app/templates/food-trucks.js +1 -0
- package/composer.json +1 -1
- package/extension.json +1 -1
- package/package.json +1 -1
- package/server/migrations/2025_01_30_042853_create_catalogs_table.php +41 -0
- package/server/migrations/2025_01_30_044728_create_catalog_category_products_table.php +35 -0
- package/server/migrations/2025_01_30_050611_create_food_trucks_table.php +72 -0
- package/server/migrations/2025_01_30_052157_create_catalog_subjects_table.php +54 -0
- package/server/migrations/2025_01_30_052402_create_catalog_hours_table.php +39 -0
- package/server/src/Auth/Schemas/Storefront.php +16 -0
- package/server/src/Console/Commands/PurgeExpiredCarts.php +49 -0
- package/server/src/Http/Controllers/CatalogCategoryController.php +13 -0
- package/server/src/Http/Controllers/CatalogController.php +13 -0
- package/server/src/Http/Controllers/CatalogHourController.php +13 -0
- package/server/src/Http/Controllers/FoodTruckController.php +13 -0
- package/server/src/Http/Controllers/v1/CatalogController.php +38 -0
- package/server/src/Http/Controllers/v1/CategoryController.php +1 -1
- package/server/src/Http/Controllers/v1/FoodTruckController.php +39 -0
- package/server/src/Http/Controllers/v1/OrderController.php +43 -0
- package/server/src/Http/Controllers/v1/ProductController.php +1 -1
- package/server/src/Http/Controllers/v1/ReviewController.php +8 -6
- package/server/src/Http/Filter/FoodTruckFilter.php +37 -0
- package/server/src/Http/Resources/Catalog.php +34 -0
- package/server/src/Http/Resources/CatalogCategory.php +38 -0
- package/server/src/Http/Resources/CatalogProduct.php +55 -0
- package/server/src/Http/Resources/FoodTruck.php +42 -0
- package/server/src/Http/Resources/Product.php +2 -1
- package/server/src/Models/AddonCategory.php +12 -0
- package/server/src/Models/Cart.php +6 -0
- package/server/src/Models/Catalog.php +213 -0
- package/server/src/Models/CatalogCategory.php +118 -0
- package/server/src/Models/CatalogHour.php +46 -0
- package/server/src/Models/CatalogProduct.php +25 -0
- package/server/src/Models/CatalogSubject.php +70 -0
- package/server/src/Models/FoodTruck.php +182 -0
- package/server/src/Models/Product.php +16 -1
- package/server/src/Notifications/StorefrontOrderCanceled.php +80 -121
- package/server/src/Notifications/StorefrontOrderCompleted.php +86 -131
- package/server/src/Notifications/StorefrontOrderCreated.php +29 -15
- package/server/src/Notifications/StorefrontOrderDriverAssigned.php +96 -130
- package/server/src/Notifications/StorefrontOrderEnroute.php +89 -129
- package/server/src/Notifications/StorefrontOrderNearby.php +103 -132
- package/server/src/Notifications/StorefrontOrderPreparing.php +89 -134
- package/server/src/Notifications/StorefrontOrderReadyForPickup.php +89 -134
- package/server/src/Observers/CatalogObserver.php +40 -0
- package/server/src/Observers/FoodTruckObserver.php +24 -0
- package/server/src/Observers/ProductObserver.php +3 -27
- package/server/src/Providers/StorefrontServiceProvider.php +7 -3
- package/server/src/Support/PushNotification.php +127 -0
- package/server/src/routes.php +15 -0
- package/translations/en-us.yaml +5 -0
|
@@ -3,30 +3,55 @@
|
|
|
3
3
|
namespace Fleetbase\Storefront\Notifications;
|
|
4
4
|
|
|
5
5
|
use Fleetbase\FleetOps\Models\Order;
|
|
6
|
-
use Fleetbase\
|
|
7
|
-
use Fleetbase\Storefront\Models\
|
|
6
|
+
use Fleetbase\Storefront\Models\Network;
|
|
7
|
+
use Fleetbase\Storefront\Models\Store;
|
|
8
|
+
use Fleetbase\Storefront\Support\PushNotification;
|
|
8
9
|
use Fleetbase\Storefront\Support\Storefront;
|
|
9
|
-
// use Fleetbase\FleetOps\Support\Utils;
|
|
10
10
|
use Illuminate\Bus\Queueable;
|
|
11
|
-
// use Illuminate\Contracts\Queue\ShouldQueue;
|
|
12
11
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
13
12
|
use Illuminate\Notifications\Notification;
|
|
14
13
|
use NotificationChannels\Apn\ApnChannel;
|
|
15
|
-
use NotificationChannels\Apn\ApnMessage;
|
|
16
14
|
use NotificationChannels\Fcm\FcmChannel;
|
|
17
|
-
use NotificationChannels\Fcm\FcmMessage;
|
|
18
|
-
use NotificationChannels\Fcm\Resources\AndroidConfig;
|
|
19
|
-
use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
|
|
20
|
-
use NotificationChannels\Fcm\Resources\AndroidNotification;
|
|
21
|
-
use NotificationChannels\Fcm\Resources\ApnsConfig;
|
|
22
|
-
use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
|
|
23
|
-
use Pushok\AuthProvider\Token as PuskOkToken;
|
|
24
|
-
use Pushok\Client as PushOkClient;
|
|
25
15
|
|
|
26
16
|
class StorefrontOrderEnroute extends Notification
|
|
27
17
|
{
|
|
28
18
|
use Queueable;
|
|
29
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The order instance this notification is for.
|
|
22
|
+
*/
|
|
23
|
+
public Order $order;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The order instance this notification is for.
|
|
27
|
+
*/
|
|
28
|
+
public Store|Network $storefront;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The time the notification was sent.
|
|
32
|
+
*/
|
|
33
|
+
public string $sentAt;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The ID of the notification.
|
|
37
|
+
*/
|
|
38
|
+
public string $notificationId;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The notification subject.
|
|
42
|
+
*/
|
|
43
|
+
public string $subject;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The notification body.
|
|
47
|
+
*/
|
|
48
|
+
public string $body;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The notification order status.
|
|
52
|
+
*/
|
|
53
|
+
public string $status;
|
|
54
|
+
|
|
30
55
|
/**
|
|
31
56
|
* Create a new notification instance.
|
|
32
57
|
*
|
|
@@ -34,8 +59,14 @@ class StorefrontOrderEnroute extends Notification
|
|
|
34
59
|
*/
|
|
35
60
|
public function __construct(Order $order)
|
|
36
61
|
{
|
|
37
|
-
$this->order
|
|
38
|
-
$this->storefront
|
|
62
|
+
$this->order = $order;
|
|
63
|
+
$this->storefront = Storefront::findAbout($order->getMeta('storefront_id'));
|
|
64
|
+
$this->sentAt = now()->toDateTimeString();
|
|
65
|
+
$this->notificationId = uniqid('notification_');
|
|
66
|
+
|
|
67
|
+
$this->subject = 'Your order from ' . $this->storefront->name . ' is on the way!';
|
|
68
|
+
$this->body = 'Your order from ' . $this->storefront->name . ' has been picked up, we will update you when your order is nearby';
|
|
69
|
+
$this->status = 'order_enroute';
|
|
39
70
|
}
|
|
40
71
|
|
|
41
72
|
/**
|
|
@@ -45,24 +76,7 @@ class StorefrontOrderEnroute extends Notification
|
|
|
45
76
|
*/
|
|
46
77
|
public function via($notifiable)
|
|
47
78
|
{
|
|
48
|
-
|
|
49
|
-
$channels = [];
|
|
50
|
-
|
|
51
|
-
if (!$this->storefront) {
|
|
52
|
-
return $channels;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
$hasApnNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'apn'])->count();
|
|
56
|
-
$hasFcmNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'android'])->count();
|
|
57
|
-
|
|
58
|
-
if ($hasApnNotificationChannels) {
|
|
59
|
-
$channels[] = ApnChannel::class;
|
|
60
|
-
}
|
|
61
|
-
if ($hasFcmNotificationChannels) {
|
|
62
|
-
$channels[] = FcmChannel::class;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return $channels;
|
|
79
|
+
return ['mail', 'database', FcmChannel::class, ApnChannel::class];
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
/**
|
|
@@ -73,8 +87,8 @@ class StorefrontOrderEnroute extends Notification
|
|
|
73
87
|
public function toMail($notifiable)
|
|
74
88
|
{
|
|
75
89
|
$message = (new MailMessage())
|
|
76
|
-
->subject(
|
|
77
|
-
->line(
|
|
90
|
+
->subject($this->subject)
|
|
91
|
+
->line($this->body);
|
|
78
92
|
|
|
79
93
|
// $message->action('View Details', Utils::consoleUrl('', ['shift' => 'fleet-ops/orders/view/' . $this->order->public_id]));
|
|
80
94
|
|
|
@@ -84,111 +98,57 @@ class StorefrontOrderEnroute extends Notification
|
|
|
84
98
|
/**
|
|
85
99
|
* Get the firebase cloud message representation of the notification.
|
|
86
100
|
*
|
|
87
|
-
* @return
|
|
101
|
+
* @return \NotificationChannels\Fcm\FcmMessage
|
|
88
102
|
*/
|
|
89
103
|
public function toFcm($notifiable)
|
|
90
104
|
{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
->
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
->setAndroid(
|
|
99
|
-
AndroidConfig::create()
|
|
100
|
-
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
|
|
101
|
-
->setNotification(AndroidNotification::create()->setColor('#4391EA'))
|
|
102
|
-
)->setApns(
|
|
103
|
-
ApnsConfig::create()
|
|
104
|
-
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
return $message;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
public function fcmProject($notifiable, $message)
|
|
111
|
-
{
|
|
112
|
-
$about = Storefront::findAbout($this->order->getMeta('storefront_id'));
|
|
113
|
-
|
|
114
|
-
if ($this->order->hasMeta('storefront_notification_channel')) {
|
|
115
|
-
$notificationChannel = NotificationChannel::where([
|
|
116
|
-
'owner_uuid' => $about->uuid,
|
|
117
|
-
'app_key' => $this->order->getMeta('storefront_notification_channel'),
|
|
118
|
-
'scheme' => 'fcm',
|
|
119
|
-
])->first();
|
|
120
|
-
} else {
|
|
121
|
-
$notificationChannel = NotificationChannel::where([
|
|
122
|
-
'owner_uuid' => $about->uuid,
|
|
123
|
-
'scheme' => 'fcm',
|
|
124
|
-
])->first();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (!$notificationChannel) {
|
|
128
|
-
return 'app';
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
$this->configureFcm($notificationChannel);
|
|
132
|
-
|
|
133
|
-
return $notificationChannel->app_key;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
public function configureFcm($notificationChannel)
|
|
137
|
-
{
|
|
138
|
-
$config = (array) $notificationChannel->config;
|
|
139
|
-
$fcmConfig = config('firebase.projects.app');
|
|
140
|
-
|
|
141
|
-
// set credentials
|
|
142
|
-
Utils::set($fcmConfig, 'credentials.file', $config['firebase_credentials_json']);
|
|
143
|
-
|
|
144
|
-
// set db url
|
|
145
|
-
Utils::set($fcmConfig, 'database.url', $config['firebase_database_url']);
|
|
146
|
-
|
|
147
|
-
config('firebase.projects.' . $notificationChannel->app_key, $fcmConfig);
|
|
148
|
-
|
|
149
|
-
return $fcmConfig;
|
|
105
|
+
return PushNotification::createFcmMessage(
|
|
106
|
+
$this->order,
|
|
107
|
+
$this->subject,
|
|
108
|
+
$this->body,
|
|
109
|
+
$this->status,
|
|
110
|
+
$notifiable
|
|
111
|
+
);
|
|
150
112
|
}
|
|
151
113
|
|
|
152
114
|
/**
|
|
153
115
|
* Get the apns message representation of the notification.
|
|
154
116
|
*
|
|
155
|
-
* @return
|
|
117
|
+
* @return \NotificationChannels\Apn\ApnMessage
|
|
156
118
|
*/
|
|
157
119
|
public function toApn($notifiable)
|
|
158
120
|
{
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
$
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
} else {
|
|
168
|
-
$notificationChannel = NotificationChannel::where([
|
|
169
|
-
'owner_uuid' => $about->uuid,
|
|
170
|
-
'scheme' => 'apn',
|
|
171
|
-
])->first();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
$config = (array) $notificationChannel->config;
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
$channelClient = new PushOkClient(PuskOkToken::create($config));
|
|
178
|
-
} catch (\Exception $e) {
|
|
179
|
-
// stop silently
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
$message = ApnMessage::create()
|
|
184
|
-
->badge(1)
|
|
185
|
-
->title('Your order from ' . $this->storefront->name . ' is on the way!')
|
|
186
|
-
->body('Your order from ' . $this->storefront->name . ' has been picked up, we will update you when your order is nearby')
|
|
187
|
-
->custom('type', 'order_enroute')
|
|
188
|
-
->custom('order', $this->order->uuid)
|
|
189
|
-
->custom('id', $this->order->public_id)
|
|
190
|
-
->via($channelClient);
|
|
121
|
+
return PushNotification::createApnMessage(
|
|
122
|
+
$this->order,
|
|
123
|
+
$this->subject,
|
|
124
|
+
$this->body,
|
|
125
|
+
$this->status,
|
|
126
|
+
$notifiable
|
|
127
|
+
);
|
|
128
|
+
}
|
|
191
129
|
|
|
192
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Get the array representation of the notification.
|
|
132
|
+
*/
|
|
133
|
+
public function toArray($notifiable): array
|
|
134
|
+
{
|
|
135
|
+
$this->order->loadMissing(['customer', 'company']);
|
|
136
|
+
$customer = $this->order->customer;
|
|
137
|
+
$company = $this->order->company;
|
|
138
|
+
|
|
139
|
+
return [
|
|
140
|
+
'notifiable' => $notifiable->public_id,
|
|
141
|
+
'notification_id' => $this->notificationId,
|
|
142
|
+
'sent_at' => $this->sentAt,
|
|
143
|
+
'subject' => $this->subject,
|
|
144
|
+
'message' => $this->status,
|
|
145
|
+
'storefront' => $this->storefront->name,
|
|
146
|
+
'storefront_id' => $this->storefront->public_id,
|
|
147
|
+
'id' => $customer->public_id,
|
|
148
|
+
'email' => $customer->email,
|
|
149
|
+
'phone' => $customer->phone,
|
|
150
|
+
'companyId' => $company->public_id,
|
|
151
|
+
'company' => $company->name,
|
|
152
|
+
];
|
|
193
153
|
}
|
|
194
154
|
}
|
|
@@ -3,41 +3,83 @@
|
|
|
3
3
|
namespace Fleetbase\Storefront\Notifications;
|
|
4
4
|
|
|
5
5
|
use Fleetbase\FleetOps\Models\Order;
|
|
6
|
-
use Fleetbase\
|
|
7
|
-
use Fleetbase\Storefront\Models\
|
|
6
|
+
use Fleetbase\Storefront\Models\Network;
|
|
7
|
+
use Fleetbase\Storefront\Models\Store;
|
|
8
|
+
use Fleetbase\Storefront\Support\PushNotification;
|
|
8
9
|
use Fleetbase\Storefront\Support\Storefront;
|
|
9
|
-
|
|
10
|
+
use Fleetbase\Support\Utils;
|
|
10
11
|
use Illuminate\Bus\Queueable;
|
|
11
|
-
// use Illuminate\Contracts\Queue\ShouldQueue;
|
|
12
12
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
13
13
|
use Illuminate\Notifications\Notification;
|
|
14
14
|
use NotificationChannels\Apn\ApnChannel;
|
|
15
|
-
use NotificationChannels\Apn\ApnMessage;
|
|
16
15
|
use NotificationChannels\Fcm\FcmChannel;
|
|
17
|
-
use NotificationChannels\Fcm\FcmMessage;
|
|
18
|
-
use NotificationChannels\Fcm\Resources\AndroidConfig;
|
|
19
|
-
use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
|
|
20
|
-
use NotificationChannels\Fcm\Resources\AndroidNotification;
|
|
21
|
-
use NotificationChannels\Fcm\Resources\ApnsConfig;
|
|
22
|
-
use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
|
|
23
|
-
use Pushok\AuthProvider\Token as PuskOkToken;
|
|
24
|
-
use Pushok\Client as PushOkClient;
|
|
25
16
|
|
|
26
17
|
class StorefrontOrderNearby extends Notification
|
|
27
18
|
{
|
|
28
19
|
use Queueable;
|
|
29
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The order instance this notification is for.
|
|
23
|
+
*/
|
|
24
|
+
public Order $order;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The order instance this notification is for.
|
|
28
|
+
*/
|
|
29
|
+
public Store|Network $storefront;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The time the notification was sent.
|
|
33
|
+
*/
|
|
34
|
+
public string $sentAt;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The ID of the notification.
|
|
38
|
+
*/
|
|
39
|
+
public string $notificationId;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The distance the driver is from the customer.
|
|
43
|
+
*/
|
|
44
|
+
public int $distance = 0;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The estimated time remaining before the driver reaches the customer.
|
|
48
|
+
*/
|
|
49
|
+
public int $time = 0;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The notification subject.
|
|
53
|
+
*/
|
|
54
|
+
public string $subject;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The notification body.
|
|
58
|
+
*/
|
|
59
|
+
public string $body;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The notification order status.
|
|
63
|
+
*/
|
|
64
|
+
public string $status;
|
|
65
|
+
|
|
30
66
|
/**
|
|
31
67
|
* Create a new notification instance.
|
|
32
68
|
*
|
|
33
69
|
* @return void
|
|
34
70
|
*/
|
|
35
|
-
public function __construct(Order $order, $distance = 0, $time = 0)
|
|
71
|
+
public function __construct(Order $order, int $distance = 0, int $time = 0)
|
|
36
72
|
{
|
|
37
|
-
$this->order
|
|
38
|
-
$this->storefront
|
|
39
|
-
$this->distance
|
|
40
|
-
$this->time
|
|
73
|
+
$this->order = $order;
|
|
74
|
+
$this->storefront = Storefront::findAbout($order->getMeta('storefront_id'));
|
|
75
|
+
$this->distance = $distance;
|
|
76
|
+
$this->time = $time;
|
|
77
|
+
$this->sentAt = now()->toDateTimeString();
|
|
78
|
+
$this->notificationId = uniqid('notification_');
|
|
79
|
+
|
|
80
|
+
$this->subject = 'Your order is nearby!';
|
|
81
|
+
$this->body = 'Your order from ' . $this->storefront->name . ' is reaching in ' . Utils::formatSeconds($time);
|
|
82
|
+
$this->status = 'order_nearby';
|
|
41
83
|
}
|
|
42
84
|
|
|
43
85
|
/**
|
|
@@ -47,24 +89,7 @@ class StorefrontOrderNearby extends Notification
|
|
|
47
89
|
*/
|
|
48
90
|
public function via($notifiable)
|
|
49
91
|
{
|
|
50
|
-
|
|
51
|
-
$channels = [];
|
|
52
|
-
|
|
53
|
-
if (!$this->storefront) {
|
|
54
|
-
return $channels;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
$hasApnNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'apn'])->count();
|
|
58
|
-
$hasFcmNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'android'])->count();
|
|
59
|
-
|
|
60
|
-
if ($hasApnNotificationChannels) {
|
|
61
|
-
$channels[] = ApnChannel::class;
|
|
62
|
-
}
|
|
63
|
-
if ($hasFcmNotificationChannels) {
|
|
64
|
-
$channels[] = FcmChannel::class;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return $channels;
|
|
92
|
+
return ['mail', 'database', FcmChannel::class, ApnChannel::class];
|
|
68
93
|
}
|
|
69
94
|
|
|
70
95
|
/**
|
|
@@ -75,8 +100,8 @@ class StorefrontOrderNearby extends Notification
|
|
|
75
100
|
public function toMail($notifiable)
|
|
76
101
|
{
|
|
77
102
|
$message = (new MailMessage())
|
|
78
|
-
->subject(
|
|
79
|
-
->line(
|
|
103
|
+
->subject($this->subject)
|
|
104
|
+
->line($this->body);
|
|
80
105
|
|
|
81
106
|
// $message->action('View Details', Utils::consoleUrl('', ['shift' => 'fleet-ops/orders/view/' . $this->order->public_id]));
|
|
82
107
|
|
|
@@ -86,111 +111,57 @@ class StorefrontOrderNearby extends Notification
|
|
|
86
111
|
/**
|
|
87
112
|
* Get the firebase cloud message representation of the notification.
|
|
88
113
|
*
|
|
89
|
-
* @return
|
|
114
|
+
* @return \NotificationChannels\Fcm\FcmMessage
|
|
90
115
|
*/
|
|
91
116
|
public function toFcm($notifiable)
|
|
92
117
|
{
|
|
93
|
-
|
|
94
|
-
->
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
->setAndroid(
|
|
101
|
-
AndroidConfig::create()
|
|
102
|
-
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
|
|
103
|
-
->setNotification(AndroidNotification::create()->setColor('#4391EA'))
|
|
104
|
-
)->setApns(
|
|
105
|
-
ApnsConfig::create()
|
|
106
|
-
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
return $message;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public function fcmProject($notifiable, $message)
|
|
113
|
-
{
|
|
114
|
-
$about = Storefront::findAbout($this->order->getMeta('storefront_id'));
|
|
115
|
-
|
|
116
|
-
if ($this->order->hasMeta('storefront_notification_channel')) {
|
|
117
|
-
$notificationChannel = NotificationChannel::where([
|
|
118
|
-
'owner_uuid' => $about->uuid,
|
|
119
|
-
'app_key' => $this->order->getMeta('storefront_notification_channel'),
|
|
120
|
-
'scheme' => 'fcm',
|
|
121
|
-
])->first();
|
|
122
|
-
} else {
|
|
123
|
-
$notificationChannel = NotificationChannel::where([
|
|
124
|
-
'owner_uuid' => $about->uuid,
|
|
125
|
-
'scheme' => 'fcm',
|
|
126
|
-
])->first();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (!$notificationChannel) {
|
|
130
|
-
return 'app';
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
$this->configureFcm($notificationChannel);
|
|
134
|
-
|
|
135
|
-
return $notificationChannel->app_key;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
public function configureFcm($notificationChannel)
|
|
139
|
-
{
|
|
140
|
-
$config = (array) $notificationChannel->config;
|
|
141
|
-
$fcmConfig = config('firebase.projects.app');
|
|
142
|
-
|
|
143
|
-
// set credentials
|
|
144
|
-
Utils::set($fcmConfig, 'credentials.file', $config['firebase_credentials_json']);
|
|
145
|
-
|
|
146
|
-
// set db url
|
|
147
|
-
Utils::set($fcmConfig, 'database.url', $config['firebase_database_url']);
|
|
148
|
-
|
|
149
|
-
config('firebase.projects.' . $notificationChannel->app_key, $fcmConfig);
|
|
150
|
-
|
|
151
|
-
return $fcmConfig;
|
|
118
|
+
return PushNotification::createFcmMessage(
|
|
119
|
+
$this->order,
|
|
120
|
+
$this->subject,
|
|
121
|
+
$this->body,
|
|
122
|
+
$this->status,
|
|
123
|
+
$notifiable
|
|
124
|
+
);
|
|
152
125
|
}
|
|
153
126
|
|
|
154
127
|
/**
|
|
155
128
|
* Get the apns message representation of the notification.
|
|
156
129
|
*
|
|
157
|
-
* @return
|
|
130
|
+
* @return \NotificationChannels\Apn\ApnMessage
|
|
158
131
|
*/
|
|
159
132
|
public function toApn($notifiable)
|
|
160
133
|
{
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
$
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
} else {
|
|
170
|
-
$notificationChannel = NotificationChannel::where([
|
|
171
|
-
'owner_uuid' => $about->uuid,
|
|
172
|
-
'scheme' => 'apn',
|
|
173
|
-
])->first();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
$config = (array) $notificationChannel->config;
|
|
177
|
-
|
|
178
|
-
try {
|
|
179
|
-
$channelClient = new PushOkClient(PuskOkToken::create($config));
|
|
180
|
-
} catch (\Exception $e) {
|
|
181
|
-
// stop silently
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
$message = ApnMessage::create()
|
|
186
|
-
->badge(1)
|
|
187
|
-
->title('Your order is nearby')
|
|
188
|
-
->body('Your order from ' . $this->storefront->name . ' is reaching in ' . Utils::formatSeconds($this->time))
|
|
189
|
-
->custom('type', 'order_nearby')
|
|
190
|
-
->custom('order', $this->order->uuid)
|
|
191
|
-
->custom('id', $this->order->public_id)
|
|
192
|
-
->via($channelClient);
|
|
134
|
+
return PushNotification::createApnMessage(
|
|
135
|
+
$this->order,
|
|
136
|
+
$this->subject,
|
|
137
|
+
$this->body,
|
|
138
|
+
$this->status,
|
|
139
|
+
$notifiable
|
|
140
|
+
);
|
|
141
|
+
}
|
|
193
142
|
|
|
194
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Get the array representation of the notification.
|
|
145
|
+
*/
|
|
146
|
+
public function toArray($notifiable): array
|
|
147
|
+
{
|
|
148
|
+
$this->order->loadMissing(['customer', 'company']);
|
|
149
|
+
$customer = $this->order->customer;
|
|
150
|
+
$company = $this->order->company;
|
|
151
|
+
|
|
152
|
+
return [
|
|
153
|
+
'notifiable' => $notifiable->public_id,
|
|
154
|
+
'notification_id' => $this->notificationId,
|
|
155
|
+
'sent_at' => $this->sentAt,
|
|
156
|
+
'subject' => $this->subject,
|
|
157
|
+
'message' => $this->status,
|
|
158
|
+
'storefront' => $this->storefront->name,
|
|
159
|
+
'storefront_id' => $this->storefront->public_id,
|
|
160
|
+
'id' => $customer->public_id,
|
|
161
|
+
'email' => $customer->email,
|
|
162
|
+
'phone' => $customer->phone,
|
|
163
|
+
'companyId' => $company->public_id,
|
|
164
|
+
'company' => $company->name,
|
|
165
|
+
];
|
|
195
166
|
}
|
|
196
167
|
}
|