@fleetbase/storefront-engine 0.3.24 → 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/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 +13 -3
- 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/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 +1 -0
- 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 +84 -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 +5 -3
- package/server/src/Support/PushNotification.php +127 -0
- package/server/src/routes.php +10 -0
- package/translations/en-us.yaml +5 -0
|
@@ -2,37 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\Storefront\Notifications;
|
|
4
4
|
|
|
5
|
-
use Exception;
|
|
6
5
|
use Fleetbase\FleetOps\Models\Order;
|
|
7
|
-
use Fleetbase\FleetOps\Support\Utils;
|
|
8
6
|
use Fleetbase\Storefront\Models\Network;
|
|
9
|
-
use Fleetbase\Storefront\Models\NotificationChannel;
|
|
10
7
|
use Fleetbase\Storefront\Models\Store;
|
|
8
|
+
use Fleetbase\Storefront\Support\PushNotification;
|
|
11
9
|
use Fleetbase\Storefront\Support\Storefront;
|
|
12
|
-
// use Fleetbase\FleetOps\Support\Utils;
|
|
13
10
|
use Illuminate\Bus\Queueable;
|
|
14
|
-
// use Illuminate\Contracts\Queue\ShouldQueue;
|
|
15
11
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
16
12
|
use Illuminate\Notifications\Notification;
|
|
17
13
|
use NotificationChannels\Apn\ApnChannel;
|
|
18
|
-
use NotificationChannels\Apn\ApnMessage;
|
|
19
14
|
use NotificationChannels\Fcm\FcmChannel;
|
|
20
|
-
use NotificationChannels\Fcm\FcmMessage;
|
|
21
|
-
use NotificationChannels\Fcm\Resources\AndroidConfig;
|
|
22
|
-
use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
|
|
23
|
-
use NotificationChannels\Fcm\Resources\AndroidNotification;
|
|
24
|
-
use NotificationChannels\Fcm\Resources\ApnsConfig;
|
|
25
|
-
use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
|
|
26
|
-
use Pushok\AuthProvider\Token as PuskOkToken;
|
|
27
|
-
use Pushok\Client as PushOkClient;
|
|
28
15
|
|
|
29
16
|
class StorefrontOrderPreparing extends Notification
|
|
30
17
|
{
|
|
31
18
|
use Queueable;
|
|
32
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The order instance this notification is for.
|
|
22
|
+
*/
|
|
33
23
|
public Order $order;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The order instance this notification is for.
|
|
27
|
+
*/
|
|
34
28
|
public Store|Network $storefront;
|
|
35
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
|
+
|
|
36
55
|
/**
|
|
37
56
|
* Create a new notification instance.
|
|
38
57
|
*
|
|
@@ -40,8 +59,14 @@ class StorefrontOrderPreparing extends Notification
|
|
|
40
59
|
*/
|
|
41
60
|
public function __construct(Order $order)
|
|
42
61
|
{
|
|
43
|
-
$this->order
|
|
44
|
-
$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 being prepared!';
|
|
68
|
+
$this->body = 'Your order is getting started.';
|
|
69
|
+
$this->status = 'order_preparing';
|
|
45
70
|
}
|
|
46
71
|
|
|
47
72
|
/**
|
|
@@ -51,24 +76,7 @@ class StorefrontOrderPreparing extends Notification
|
|
|
51
76
|
*/
|
|
52
77
|
public function via($notifiable)
|
|
53
78
|
{
|
|
54
|
-
|
|
55
|
-
$channels = [];
|
|
56
|
-
|
|
57
|
-
if (!$this->storefront) {
|
|
58
|
-
return $channels;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
$hasApnNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'apn'])->count();
|
|
62
|
-
$hasFcmNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'android'])->count();
|
|
63
|
-
|
|
64
|
-
if ($hasApnNotificationChannels) {
|
|
65
|
-
$channels[] = ApnChannel::class;
|
|
66
|
-
}
|
|
67
|
-
if ($hasFcmNotificationChannels) {
|
|
68
|
-
$channels[] = FcmChannel::class;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return $channels;
|
|
79
|
+
return ['mail', 'database', FcmChannel::class, ApnChannel::class];
|
|
72
80
|
}
|
|
73
81
|
|
|
74
82
|
/**
|
|
@@ -79,8 +87,8 @@ class StorefrontOrderPreparing extends Notification
|
|
|
79
87
|
public function toMail($notifiable)
|
|
80
88
|
{
|
|
81
89
|
$message = (new MailMessage())
|
|
82
|
-
->subject(
|
|
83
|
-
->line(
|
|
90
|
+
->subject($this->subject)
|
|
91
|
+
->line($this->body);
|
|
84
92
|
|
|
85
93
|
// $message->action('View Details', Utils::consoleUrl('', ['shift' => 'fleet-ops/orders/view/' . $this->order->public_id]));
|
|
86
94
|
|
|
@@ -90,115 +98,57 @@ class StorefrontOrderPreparing extends Notification
|
|
|
90
98
|
/**
|
|
91
99
|
* Get the firebase cloud message representation of the notification.
|
|
92
100
|
*
|
|
93
|
-
* @return
|
|
101
|
+
* @return \NotificationChannels\Fcm\FcmMessage
|
|
94
102
|
*/
|
|
95
103
|
public function toFcm($notifiable)
|
|
96
104
|
{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
->
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
->setAndroid(
|
|
105
|
-
AndroidConfig::create()
|
|
106
|
-
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
|
|
107
|
-
->setNotification(AndroidNotification::create()->setColor('#4391EA'))
|
|
108
|
-
)->setApns(
|
|
109
|
-
ApnsConfig::create()
|
|
110
|
-
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
return $message;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
public function fcmProject($notifiable, $message)
|
|
117
|
-
{
|
|
118
|
-
$about = Storefront::findAbout($this->order->getMeta('storefront_id'));
|
|
119
|
-
|
|
120
|
-
if ($this->order->hasMeta('storefront_notification_channel')) {
|
|
121
|
-
$notificationChannel = NotificationChannel::where([
|
|
122
|
-
'owner_uuid' => $about->uuid,
|
|
123
|
-
'app_key' => $this->order->getMeta('storefront_notification_channel'),
|
|
124
|
-
'scheme' => 'fcm',
|
|
125
|
-
])->first();
|
|
126
|
-
} else {
|
|
127
|
-
$notificationChannel = NotificationChannel::where([
|
|
128
|
-
'owner_uuid' => $about->uuid,
|
|
129
|
-
'scheme' => 'fcm',
|
|
130
|
-
])->first();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (!$notificationChannel) {
|
|
134
|
-
return 'app';
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
$this->configureFcm($notificationChannel);
|
|
138
|
-
|
|
139
|
-
return $notificationChannel->app_key;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public function configureFcm($notificationChannel)
|
|
143
|
-
{
|
|
144
|
-
$config = (array) $notificationChannel->config;
|
|
145
|
-
$fcmConfig = config('firebase.projects.app');
|
|
146
|
-
|
|
147
|
-
// set credentials
|
|
148
|
-
Utils::set($fcmConfig, 'credentials.file', $config['firebase_credentials_json']);
|
|
149
|
-
|
|
150
|
-
// set db url
|
|
151
|
-
Utils::set($fcmConfig, 'database.url', $config['firebase_database_url']);
|
|
152
|
-
|
|
153
|
-
config('firebase.projects.' . $notificationChannel->app_key, $fcmConfig);
|
|
154
|
-
|
|
155
|
-
return $fcmConfig;
|
|
105
|
+
return PushNotification::createFcmMessage(
|
|
106
|
+
$this->order,
|
|
107
|
+
$this->subject,
|
|
108
|
+
$this->body,
|
|
109
|
+
$this->status,
|
|
110
|
+
$notifiable
|
|
111
|
+
);
|
|
156
112
|
}
|
|
157
113
|
|
|
158
114
|
/**
|
|
159
115
|
* Get the apns message representation of the notification.
|
|
160
116
|
*
|
|
161
|
-
* @return
|
|
117
|
+
* @return \NotificationChannels\Apn\ApnMessage
|
|
162
118
|
*/
|
|
163
119
|
public function toApn($notifiable)
|
|
164
120
|
{
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
$
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
} else {
|
|
174
|
-
$notificationChannel = NotificationChannel::where([
|
|
175
|
-
'owner_uuid' => $about->uuid,
|
|
176
|
-
'scheme' => 'apn',
|
|
177
|
-
])->first();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
$config = (array) $notificationChannel->config;
|
|
181
|
-
|
|
182
|
-
$message = ApnMessage::create()
|
|
183
|
-
->badge(1)
|
|
184
|
-
->title('Your order from ' . $this->storefront->name . ' is being prepared')
|
|
185
|
-
->body('Your order is getting started.')
|
|
186
|
-
->custom('type', 'order_preparing')
|
|
187
|
-
->custom('order', $this->order->uuid)
|
|
188
|
-
->custom('id', $this->order->public_id);
|
|
189
|
-
|
|
190
|
-
try {
|
|
191
|
-
$channelClient = new PushOkClient(PuskOkToken::create($config));
|
|
192
|
-
} catch (\Exception $e) {
|
|
193
|
-
// report to sentry the exception
|
|
194
|
-
app('sentry')->captureException($e);
|
|
195
|
-
|
|
196
|
-
// return the apn message to be sent by fleetbase defaults anyway -- backup
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
$message = $message->via($channelClient);
|
|
121
|
+
return PushNotification::createApnMessage(
|
|
122
|
+
$this->order,
|
|
123
|
+
$this->subject,
|
|
124
|
+
$this->body,
|
|
125
|
+
$this->status,
|
|
126
|
+
$notifiable
|
|
127
|
+
);
|
|
128
|
+
}
|
|
201
129
|
|
|
202
|
-
|
|
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
|
+
];
|
|
203
153
|
}
|
|
204
154
|
}
|
|
@@ -2,32 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\Storefront\Notifications;
|
|
4
4
|
|
|
5
|
-
use Exception;
|
|
6
5
|
use Fleetbase\FleetOps\Models\Order;
|
|
7
|
-
use Fleetbase\
|
|
8
|
-
use Fleetbase\Storefront\Models\
|
|
6
|
+
use Fleetbase\Storefront\Models\Network;
|
|
7
|
+
use Fleetbase\Storefront\Models\Store;
|
|
8
|
+
use Fleetbase\Storefront\Support\PushNotification;
|
|
9
9
|
use Fleetbase\Storefront\Support\Storefront;
|
|
10
|
-
// use Fleetbase\FleetOps\Support\Utils;
|
|
11
10
|
use Illuminate\Bus\Queueable;
|
|
12
|
-
// use Illuminate\Contracts\Queue\ShouldQueue;
|
|
13
11
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
14
12
|
use Illuminate\Notifications\Notification;
|
|
15
13
|
use NotificationChannels\Apn\ApnChannel;
|
|
16
|
-
use NotificationChannels\Apn\ApnMessage;
|
|
17
14
|
use NotificationChannels\Fcm\FcmChannel;
|
|
18
|
-
use NotificationChannels\Fcm\FcmMessage;
|
|
19
|
-
use NotificationChannels\Fcm\Resources\AndroidConfig;
|
|
20
|
-
use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
|
|
21
|
-
use NotificationChannels\Fcm\Resources\AndroidNotification;
|
|
22
|
-
use NotificationChannels\Fcm\Resources\ApnsConfig;
|
|
23
|
-
use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
|
|
24
|
-
use Pushok\AuthProvider\Token as PuskOkToken;
|
|
25
|
-
use Pushok\Client as PushOkClient;
|
|
26
15
|
|
|
27
16
|
class StorefrontOrderReadyForPickup extends Notification
|
|
28
17
|
{
|
|
29
18
|
use Queueable;
|
|
30
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
|
+
|
|
31
55
|
/**
|
|
32
56
|
* Create a new notification instance.
|
|
33
57
|
*
|
|
@@ -35,8 +59,14 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
35
59
|
*/
|
|
36
60
|
public function __construct(Order $order)
|
|
37
61
|
{
|
|
38
|
-
$this->order
|
|
39
|
-
$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 ready for pickup!';
|
|
68
|
+
$this->body = 'You can proceed to pickup your order.';
|
|
69
|
+
$this->status = 'order_ready';
|
|
40
70
|
}
|
|
41
71
|
|
|
42
72
|
/**
|
|
@@ -46,24 +76,7 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
46
76
|
*/
|
|
47
77
|
public function via($notifiable)
|
|
48
78
|
{
|
|
49
|
-
|
|
50
|
-
$channels = [];
|
|
51
|
-
|
|
52
|
-
if (!$this->storefront) {
|
|
53
|
-
return $channels;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
$hasApnNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'apn'])->count();
|
|
57
|
-
$hasFcmNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'android'])->count();
|
|
58
|
-
|
|
59
|
-
if ($hasApnNotificationChannels) {
|
|
60
|
-
$channels[] = ApnChannel::class;
|
|
61
|
-
}
|
|
62
|
-
if ($hasFcmNotificationChannels) {
|
|
63
|
-
$channels[] = FcmChannel::class;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return $channels;
|
|
79
|
+
return ['mail', 'database', FcmChannel::class, ApnChannel::class];
|
|
67
80
|
}
|
|
68
81
|
|
|
69
82
|
/**
|
|
@@ -74,8 +87,8 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
74
87
|
public function toMail($notifiable)
|
|
75
88
|
{
|
|
76
89
|
$message = (new MailMessage())
|
|
77
|
-
->subject(
|
|
78
|
-
->line(
|
|
90
|
+
->subject($this->subject)
|
|
91
|
+
->line($this->body);
|
|
79
92
|
|
|
80
93
|
// $message->action('View Details', Utils::consoleUrl('', ['shift' => 'fleet-ops/orders/view/' . $this->order->public_id]));
|
|
81
94
|
|
|
@@ -85,115 +98,57 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
85
98
|
/**
|
|
86
99
|
* Get the firebase cloud message representation of the notification.
|
|
87
100
|
*
|
|
88
|
-
* @return
|
|
101
|
+
* @return \NotificationChannels\Fcm\FcmMessage
|
|
89
102
|
*/
|
|
90
103
|
public function toFcm($notifiable)
|
|
91
104
|
{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
->
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
->setAndroid(
|
|
100
|
-
AndroidConfig::create()
|
|
101
|
-
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
|
|
102
|
-
->setNotification(AndroidNotification::create()->setColor('#4391EA'))
|
|
103
|
-
)->setApns(
|
|
104
|
-
ApnsConfig::create()
|
|
105
|
-
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
return $message;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public function fcmProject($notifiable, $message)
|
|
112
|
-
{
|
|
113
|
-
$about = Storefront::findAbout($this->order->getMeta('storefront_id'));
|
|
114
|
-
|
|
115
|
-
if ($this->order->hasMeta('storefront_notification_channel')) {
|
|
116
|
-
$notificationChannel = NotificationChannel::where([
|
|
117
|
-
'owner_uuid' => $about->uuid,
|
|
118
|
-
'app_key' => $this->order->getMeta('storefront_notification_channel'),
|
|
119
|
-
'scheme' => 'fcm',
|
|
120
|
-
])->first();
|
|
121
|
-
} else {
|
|
122
|
-
$notificationChannel = NotificationChannel::where([
|
|
123
|
-
'owner_uuid' => $about->uuid,
|
|
124
|
-
'scheme' => 'fcm',
|
|
125
|
-
])->first();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (!$notificationChannel) {
|
|
129
|
-
return 'app';
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
$this->configureFcm($notificationChannel);
|
|
133
|
-
|
|
134
|
-
return $notificationChannel->app_key;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public function configureFcm($notificationChannel)
|
|
138
|
-
{
|
|
139
|
-
$config = (array) $notificationChannel->config;
|
|
140
|
-
$fcmConfig = config('firebase.projects.app');
|
|
141
|
-
|
|
142
|
-
// set credentials
|
|
143
|
-
Utils::set($fcmConfig, 'credentials.file', $config['firebase_credentials_json']);
|
|
144
|
-
|
|
145
|
-
// set db url
|
|
146
|
-
Utils::set($fcmConfig, 'database.url', $config['firebase_database_url']);
|
|
147
|
-
|
|
148
|
-
config('firebase.projects.' . $notificationChannel->app_key, $fcmConfig);
|
|
149
|
-
|
|
150
|
-
return $fcmConfig;
|
|
105
|
+
return PushNotification::createFcmMessage(
|
|
106
|
+
$this->order,
|
|
107
|
+
$this->subject,
|
|
108
|
+
$this->body,
|
|
109
|
+
$this->status,
|
|
110
|
+
$notifiable
|
|
111
|
+
);
|
|
151
112
|
}
|
|
152
113
|
|
|
153
114
|
/**
|
|
154
115
|
* Get the apns message representation of the notification.
|
|
155
116
|
*
|
|
156
|
-
* @return
|
|
117
|
+
* @return \NotificationChannels\Apn\ApnMessage
|
|
157
118
|
*/
|
|
158
119
|
public function toApn($notifiable)
|
|
159
120
|
{
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
$
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
} else {
|
|
169
|
-
$notificationChannel = NotificationChannel::where([
|
|
170
|
-
'owner_uuid' => $about->uuid,
|
|
171
|
-
'scheme' => 'apn',
|
|
172
|
-
])->first();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
$config = (array) $notificationChannel->config;
|
|
176
|
-
|
|
177
|
-
$message = ApnMessage::create()
|
|
178
|
-
->badge(1)
|
|
179
|
-
->title('Your order from ' . $this->storefront->name . ' is ready for pickup!')
|
|
180
|
-
->body('You can proceed to pickup your order.')
|
|
181
|
-
->custom('type', 'order_ready')
|
|
182
|
-
->custom('order', $this->order->uuid)
|
|
183
|
-
->custom('id', $this->order->public_id);
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
$channelClient = new PushOkClient(PuskOkToken::create($config));
|
|
187
|
-
} catch (\Exception $e) {
|
|
188
|
-
// report to sentry the exception
|
|
189
|
-
app('sentry')->captureException($e);
|
|
190
|
-
|
|
191
|
-
// return the apn message to be sent by fleetbase defaults anyway -- backup
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
$message = $message->via($channelClient);
|
|
121
|
+
return PushNotification::createApnMessage(
|
|
122
|
+
$this->order,
|
|
123
|
+
$this->subject,
|
|
124
|
+
$this->body,
|
|
125
|
+
$this->status,
|
|
126
|
+
$notifiable
|
|
127
|
+
);
|
|
128
|
+
}
|
|
196
129
|
|
|
197
|
-
|
|
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
|
+
];
|
|
198
153
|
}
|
|
199
154
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Observers;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Storefront\Models\Catalog;
|
|
6
|
+
use Fleetbase\Storefront\Models\CatalogCategory;
|
|
7
|
+
use Fleetbase\Storefront\Models\CatalogProduct;
|
|
8
|
+
use Illuminate\Support\Facades\Request;
|
|
9
|
+
|
|
10
|
+
class CatalogObserver
|
|
11
|
+
{
|
|
12
|
+
/**
|
|
13
|
+
* Handle the Catalog "saved" event.
|
|
14
|
+
*
|
|
15
|
+
* @param Catalog $catalog the Catalog that was saved
|
|
16
|
+
*/
|
|
17
|
+
public function saved(Catalog $catalog): void
|
|
18
|
+
{
|
|
19
|
+
$categories = Request::input('catalog.categories', []);
|
|
20
|
+
$catalog->setCategories($categories);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Handle the Catalog "deleted" event.
|
|
25
|
+
*
|
|
26
|
+
* @param Catalog $catalog the Catalog that was created
|
|
27
|
+
*/
|
|
28
|
+
public function deleted(Catalog $catalog): void
|
|
29
|
+
{
|
|
30
|
+
// Delete all the catalog category records
|
|
31
|
+
$categories = CatalogCategory::where('owner_uuid', $catalog->uuid)->get();
|
|
32
|
+
foreach ($categories as $category) {
|
|
33
|
+
// Delete the category product records
|
|
34
|
+
CatalogProduct::where('catalog_category_uuid', $category->uuid)->delete();
|
|
35
|
+
|
|
36
|
+
// Delete the category itself
|
|
37
|
+
$category->delete();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Observers;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Storefront\Models\FoodTruck;
|
|
6
|
+
use Illuminate\Support\Facades\Request;
|
|
7
|
+
|
|
8
|
+
class FoodTruckObserver
|
|
9
|
+
{
|
|
10
|
+
/**
|
|
11
|
+
* Handle the FoodTruck "saved" event.
|
|
12
|
+
*
|
|
13
|
+
* @param FoodTruck $foodTruck the FoodTruck that was saved
|
|
14
|
+
*/
|
|
15
|
+
public function saved(FoodTruck $foodTruck): void
|
|
16
|
+
{
|
|
17
|
+
try {
|
|
18
|
+
$catalogs = Request::input('foodTruck.catalogs', []);
|
|
19
|
+
$foodTruck->setCatalogs($catalogs);
|
|
20
|
+
} catch (\Exception $e) {
|
|
21
|
+
dd($e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -9,11 +9,11 @@ use Illuminate\Support\Facades\Request;
|
|
|
9
9
|
class ProductObserver
|
|
10
10
|
{
|
|
11
11
|
/**
|
|
12
|
-
* Handle the Product "
|
|
12
|
+
* Handle the Product "saved" event.
|
|
13
13
|
*
|
|
14
|
-
* @param Product $product the Product that was
|
|
14
|
+
* @param Product $product the Product that was saved
|
|
15
15
|
*/
|
|
16
|
-
public function
|
|
16
|
+
public function saved(Product $product): void
|
|
17
17
|
{
|
|
18
18
|
$addonCategories = Request::input('product.addon_categories', []);
|
|
19
19
|
$variants = Request::input('product.variants', []);
|
|
@@ -31,28 +31,4 @@ class ProductObserver
|
|
|
31
31
|
$fileRecord->setKey($product);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Handle the Product "updated" event.
|
|
37
|
-
*
|
|
38
|
-
* @param Product $product the Product that was created
|
|
39
|
-
*/
|
|
40
|
-
public function updated(Product $product): void
|
|
41
|
-
{
|
|
42
|
-
$addonCategories = Request::input('product.addon_categories', []);
|
|
43
|
-
$variants = Request::input('product.variants', []);
|
|
44
|
-
$files = Request::input('product.files', []);
|
|
45
|
-
|
|
46
|
-
// save addon categories
|
|
47
|
-
$product->setAddonCategories($addonCategories);
|
|
48
|
-
|
|
49
|
-
// save product variants
|
|
50
|
-
$product->setProductVariants($variants);
|
|
51
|
-
|
|
52
|
-
// set keys on files
|
|
53
|
-
foreach ($files as $file) {
|
|
54
|
-
$fileRecord = File::where('uuid', $file['uuid'])->first();
|
|
55
|
-
$fileRecord->setKey($product);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
34
|
}
|
|
@@ -24,9 +24,11 @@ class StorefrontServiceProvider extends CoreServiceProvider
|
|
|
24
24
|
* @var array
|
|
25
25
|
*/
|
|
26
26
|
public $observers = [
|
|
27
|
-
\Fleetbase\Storefront\Models\Product::class
|
|
28
|
-
\Fleetbase\Storefront\Models\Network::class
|
|
29
|
-
\Fleetbase\Models\
|
|
27
|
+
\Fleetbase\Storefront\Models\Product::class => \Fleetbase\Storefront\Observers\ProductObserver::class,
|
|
28
|
+
\Fleetbase\Storefront\Models\Network::class => \Fleetbase\Storefront\Observers\NetworkObserver::class,
|
|
29
|
+
\Fleetbase\Storefront\Models\Catalog::class => \Fleetbase\Storefront\Observers\CatalogObserver::class,
|
|
30
|
+
\Fleetbase\Storefront\Models\FoodTruck::class => \Fleetbase\Storefront\Observers\FoodTruckObserver::class,
|
|
31
|
+
\Fleetbase\Models\Company::class => \Fleetbase\Storefront\Observers\CompanyObserver::class,
|
|
30
32
|
];
|
|
31
33
|
|
|
32
34
|
/**
|