@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
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Models;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\FleetOps\Models\ServiceArea;
|
|
6
|
+
use Fleetbase\FleetOps\Models\Vehicle;
|
|
7
|
+
use Fleetbase\FleetOps\Models\Zone;
|
|
8
|
+
use Fleetbase\Storefront\Http\Resources\FoodTruck as FoodTruckResource;
|
|
9
|
+
use Fleetbase\Traits\HasApiModelBehavior;
|
|
10
|
+
use Fleetbase\Traits\HasPublicid;
|
|
11
|
+
use Fleetbase\Traits\HasUuid;
|
|
12
|
+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
13
|
+
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
14
|
+
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
|
15
|
+
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
16
|
+
use Illuminate\Support\Str;
|
|
17
|
+
|
|
18
|
+
class FoodTruck extends StorefrontModel
|
|
19
|
+
{
|
|
20
|
+
use HasUuid;
|
|
21
|
+
use HasPublicid;
|
|
22
|
+
use HasApiModelBehavior;
|
|
23
|
+
use SoftDeletes;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The default database connection to use.
|
|
27
|
+
*
|
|
28
|
+
* @var string
|
|
29
|
+
*/
|
|
30
|
+
protected $connection = 'storefront';
|
|
31
|
+
|
|
32
|
+
protected $resource = FoodTruckResource::class;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The type of public ID to generate.
|
|
36
|
+
*
|
|
37
|
+
* @var string
|
|
38
|
+
*/
|
|
39
|
+
protected $publicIdType = 'food_truck';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The table associated with the model.
|
|
43
|
+
*
|
|
44
|
+
* @var string
|
|
45
|
+
*/
|
|
46
|
+
protected $table = 'food_trucks';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The attributes that are mass assignable.
|
|
50
|
+
*
|
|
51
|
+
* @var array
|
|
52
|
+
*/
|
|
53
|
+
protected $fillable = [
|
|
54
|
+
'uuid',
|
|
55
|
+
'vehicle_uuid',
|
|
56
|
+
'store_uuid',
|
|
57
|
+
'company_uuid',
|
|
58
|
+
'created_by_uuid',
|
|
59
|
+
'service_area_uuid',
|
|
60
|
+
'zone_uuid',
|
|
61
|
+
'status',
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get the store that owns this food truck.
|
|
66
|
+
*/
|
|
67
|
+
public function store(): BelongsTo
|
|
68
|
+
{
|
|
69
|
+
return $this->belongsTo(Store::class, 'store_uuid', 'uuid');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get the vehicle that is the food truck.
|
|
74
|
+
*/
|
|
75
|
+
public function vehicle(): BelongsTo
|
|
76
|
+
{
|
|
77
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Vehicle::class, 'vehicle_uuid', 'uuid');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get the service area the food truck is assigned to.
|
|
82
|
+
*/
|
|
83
|
+
public function serviceArea(): BelongsTo
|
|
84
|
+
{
|
|
85
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(ServiceArea::class, 'service_area_uuid', 'uuid');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Get the zone the food truck is assigned to.
|
|
90
|
+
*/
|
|
91
|
+
public function zone(): BelongsTo
|
|
92
|
+
{
|
|
93
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Zone::class, 'zone_uuid', 'uuid');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Polymorphic relationship to the CatalogSubject pivot.
|
|
98
|
+
* This allows you to retrieve all catalogs assigned to this food truck.
|
|
99
|
+
*/
|
|
100
|
+
public function catalogAssignments(): MorphMany
|
|
101
|
+
{
|
|
102
|
+
return $this->morphMany(CatalogSubject::class, 'subject', 'subject_type', 'subject_uuid');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The catalogs assigned to this food truck.
|
|
107
|
+
*/
|
|
108
|
+
public function catalogs(): MorphToMany
|
|
109
|
+
{
|
|
110
|
+
return $this->morphToMany(
|
|
111
|
+
Catalog::class,
|
|
112
|
+
'subject',
|
|
113
|
+
'catalog_subjects',
|
|
114
|
+
'subject_uuid',
|
|
115
|
+
'catalog_uuid',
|
|
116
|
+
)->using(CatalogSubject::class)
|
|
117
|
+
->withTimestamps()
|
|
118
|
+
->wherePivotNull('deleted_at');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Sync the given catalogs to this food truck by creating or deleting pivot rows
|
|
123
|
+
* in catalog_subjects. If pivot rows are polymorphic, also filter by subject_type.
|
|
124
|
+
*
|
|
125
|
+
* @return $this
|
|
126
|
+
*/
|
|
127
|
+
public function setCatalogs(array $catalogs = []): FoodTruck
|
|
128
|
+
{
|
|
129
|
+
// Ensure 'catalogs' relationship is loaded
|
|
130
|
+
$this->loadMissing('catalogs');
|
|
131
|
+
|
|
132
|
+
// Collect existing catalogs
|
|
133
|
+
$existingCatalogs = $this->catalogs;
|
|
134
|
+
|
|
135
|
+
// Extract incoming UUIDs
|
|
136
|
+
$incomingUuids = collect($catalogs)
|
|
137
|
+
->map(function ($item) {
|
|
138
|
+
// If it's already a Catalog model, use its uuid
|
|
139
|
+
if ($item instanceof Catalog) {
|
|
140
|
+
return $item->uuid;
|
|
141
|
+
}
|
|
142
|
+
// If it's a string UUID, return as is
|
|
143
|
+
if (is_string($item) && Str::isUuid($item)) {
|
|
144
|
+
return $item;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// If it's an array/object with a 'uuid' key, return that
|
|
148
|
+
return data_get($item, 'uuid');
|
|
149
|
+
})
|
|
150
|
+
->filter(fn ($uuid) => Str::isUuid($uuid))
|
|
151
|
+
->unique()
|
|
152
|
+
->values();
|
|
153
|
+
|
|
154
|
+
// Remove pivot rows for catalogs not in incoming list
|
|
155
|
+
$existingCatalogs
|
|
156
|
+
->whereNotIn('uuid', $incomingUuids)
|
|
157
|
+
->each(function (Catalog $catalog) {
|
|
158
|
+
CatalogSubject::where([
|
|
159
|
+
'catalog_uuid' => $catalog->uuid,
|
|
160
|
+
'subject_uuid' => $this->uuid,
|
|
161
|
+
'subject_type' => get_class($this),
|
|
162
|
+
])->delete();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Create or restore pivot rows for each incoming
|
|
166
|
+
foreach ($incomingUuids as $catalogUuid) {
|
|
167
|
+
CatalogSubject::firstOrCreate(
|
|
168
|
+
[
|
|
169
|
+
'catalog_uuid' => $catalogUuid,
|
|
170
|
+
'subject_uuid' => $this->uuid,
|
|
171
|
+
'subject_type' => get_class($this),
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
'company_uuid' => $this->company_uuid,
|
|
175
|
+
'created_by_uuid'=> session('user'),
|
|
176
|
+
]
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return $this;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -224,6 +224,21 @@ class Product extends StorefrontModel
|
|
|
224
224
|
return $this->belongsTo(Store::class);
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
/**
|
|
228
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
229
|
+
*/
|
|
230
|
+
public function catalogCategories()
|
|
231
|
+
{
|
|
232
|
+
return $this->belongsToMany(
|
|
233
|
+
CatalogCategory::class,
|
|
234
|
+
'catalog_category_product',
|
|
235
|
+
'product_uuid',
|
|
236
|
+
'catalog_category_uuid'
|
|
237
|
+
)
|
|
238
|
+
->using(CatalogProduct::class)
|
|
239
|
+
->withTimestamps();
|
|
240
|
+
}
|
|
241
|
+
|
|
227
242
|
/**
|
|
228
243
|
* @return array
|
|
229
244
|
*/
|
|
@@ -494,7 +509,7 @@ class Product extends StorefrontModel
|
|
|
494
509
|
*/
|
|
495
510
|
public function createAsEntity(array $additionalAttributes = []): Entity
|
|
496
511
|
{
|
|
497
|
-
$entity = $this->toEntity();
|
|
512
|
+
$entity = $this->toEntity($additionalAttributes);
|
|
498
513
|
$entity->save();
|
|
499
514
|
|
|
500
515
|
return $entity;
|
|
@@ -3,23 +3,15 @@
|
|
|
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 Illuminate\Bus\Queueable;
|
|
10
11
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
11
12
|
use Illuminate\Notifications\Notification;
|
|
12
13
|
use NotificationChannels\Apn\ApnChannel;
|
|
13
|
-
use NotificationChannels\Apn\ApnMessage;
|
|
14
14
|
use NotificationChannels\Fcm\FcmChannel;
|
|
15
|
-
use NotificationChannels\Fcm\FcmMessage;
|
|
16
|
-
use NotificationChannels\Fcm\Resources\AndroidConfig;
|
|
17
|
-
use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
|
|
18
|
-
use NotificationChannels\Fcm\Resources\AndroidNotification;
|
|
19
|
-
use NotificationChannels\Fcm\Resources\ApnsConfig;
|
|
20
|
-
use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
|
|
21
|
-
use Pushok\AuthProvider\Token as PuskOkToken;
|
|
22
|
-
use Pushok\Client as PushOkClient;
|
|
23
15
|
|
|
24
16
|
class StorefrontOrderCanceled extends Notification
|
|
25
17
|
{
|
|
@@ -27,17 +19,38 @@ class StorefrontOrderCanceled extends Notification
|
|
|
27
19
|
|
|
28
20
|
/**
|
|
29
21
|
* The order instance this notification is for.
|
|
30
|
-
*
|
|
31
|
-
* @var Order
|
|
32
22
|
*/
|
|
33
|
-
public $order;
|
|
23
|
+
public Order $order;
|
|
34
24
|
|
|
35
25
|
/**
|
|
36
26
|
* The order instance this notification is for.
|
|
37
|
-
*
|
|
38
|
-
* @var \Fleetbase\Storefront\Models\Store|\Fleetbase\Storefront\Models\Network
|
|
39
27
|
*/
|
|
40
|
-
public $storefront;
|
|
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;
|
|
41
54
|
|
|
42
55
|
/**
|
|
43
56
|
* Create a new notification instance.
|
|
@@ -46,18 +59,22 @@ class StorefrontOrderCanceled extends Notification
|
|
|
46
59
|
*/
|
|
47
60
|
public function __construct(Order $order)
|
|
48
61
|
{
|
|
49
|
-
$this->order
|
|
50
|
-
$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 . ' was canceled';
|
|
68
|
+
$this->body = 'Your order from ' . $this->storefront->name . ' has been canceled, if your card has been charged you will be refunded.';
|
|
69
|
+
$this->status = 'order_canceled';
|
|
51
70
|
}
|
|
52
71
|
|
|
53
72
|
/**
|
|
54
73
|
* Get the notification's delivery channels.
|
|
55
|
-
*
|
|
56
|
-
* @return array
|
|
57
74
|
*/
|
|
58
|
-
public function via($notifiable)
|
|
75
|
+
public function via($notifiable): array
|
|
59
76
|
{
|
|
60
|
-
return ['mail', FcmChannel::class, ApnChannel::class];
|
|
77
|
+
return ['mail', 'database', FcmChannel::class, ApnChannel::class];
|
|
61
78
|
}
|
|
62
79
|
|
|
63
80
|
/**
|
|
@@ -68,125 +85,67 @@ class StorefrontOrderCanceled extends Notification
|
|
|
68
85
|
public function toMail($notifiable)
|
|
69
86
|
{
|
|
70
87
|
$message = (new MailMessage())
|
|
71
|
-
->subject(
|
|
72
|
-
->line(
|
|
88
|
+
->subject($this->subject)
|
|
89
|
+
->line($this->body)
|
|
73
90
|
->line('No further action is necessary.');
|
|
74
91
|
|
|
75
|
-
// $message->action('View Details', Utils::consoleUrl('', ['shift' => 'fleet-ops/orders/view/' . $this->order->public_id]));
|
|
76
|
-
|
|
77
92
|
return $message;
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
/**
|
|
81
96
|
* Get the firebase cloud message representation of the notification.
|
|
82
97
|
*
|
|
83
|
-
* @return
|
|
98
|
+
* @return \NotificationChannels\Fcm\FcmMessage
|
|
84
99
|
*/
|
|
85
100
|
public function toFcm($notifiable)
|
|
86
101
|
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
->setAndroid(
|
|
95
|
-
AndroidConfig::create()
|
|
96
|
-
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
|
|
97
|
-
->setNotification(AndroidNotification::create()->setColor('#4391EA'))
|
|
98
|
-
)->setApns(
|
|
99
|
-
ApnsConfig::create()
|
|
100
|
-
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
return $message;
|
|
102
|
+
return PushNotification::createFcmMessage(
|
|
103
|
+
$this->order,
|
|
104
|
+
$this->subject,
|
|
105
|
+
$this->body,
|
|
106
|
+
$this->status,
|
|
107
|
+
$notifiable
|
|
108
|
+
);
|
|
104
109
|
}
|
|
105
110
|
|
|
106
111
|
/**
|
|
107
112
|
* Get the apns message representation of the notification.
|
|
108
113
|
*
|
|
109
|
-
* @return
|
|
114
|
+
* @return \NotificationChannels\Apn\ApnMessage
|
|
110
115
|
*/
|
|
111
116
|
public function toApn($notifiable)
|
|
112
117
|
{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
$
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
])->first();
|
|
121
|
-
} else {
|
|
122
|
-
$notificationChannel = NotificationChannel::where([
|
|
123
|
-
'owner_uuid' => $about->uuid,
|
|
124
|
-
'scheme' => 'apn',
|
|
125
|
-
])->first();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
$config = (array) $notificationChannel->config;
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
$channelClient = new PushOkClient(PuskOkToken::create($config));
|
|
132
|
-
} catch (\Exception $e) {
|
|
133
|
-
app('sentry')->captureException($e);
|
|
134
|
-
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
$message = ApnMessage::create()
|
|
139
|
-
->badge(1)
|
|
140
|
-
->title('Your order from ' . $this->storefront->name . ' was canceled')
|
|
141
|
-
->body('Your order from ' . $this->storefront->name . ' has been canceled, if your card has been charged you will be refunded.')
|
|
142
|
-
->custom('type', 'order_canceled')
|
|
143
|
-
->custom('order', $this->order->uuid)
|
|
144
|
-
->custom('id', $this->order->public_id)
|
|
145
|
-
->action('view_order', ['id' => $this->order->public_id])
|
|
146
|
-
->via($channelClient);
|
|
147
|
-
|
|
148
|
-
return $message;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
public function fcmProject($notifiable, $message)
|
|
152
|
-
{
|
|
153
|
-
$about = Storefront::findAbout($this->order->getMeta('storefront_id'));
|
|
154
|
-
|
|
155
|
-
if ($this->order->hasMeta('storefront_notification_channel')) {
|
|
156
|
-
$notificationChannel = NotificationChannel::where([
|
|
157
|
-
'owner_uuid' => $about->uuid,
|
|
158
|
-
'app_key' => $this->order->getMeta('storefront_notification_channel'),
|
|
159
|
-
'scheme' => 'fcm',
|
|
160
|
-
])->first();
|
|
161
|
-
} else {
|
|
162
|
-
$notificationChannel = NotificationChannel::where([
|
|
163
|
-
'owner_uuid' => $about->uuid,
|
|
164
|
-
'scheme' => 'fcm',
|
|
165
|
-
])->first();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (!$notificationChannel) {
|
|
169
|
-
return 'app';
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
$this->configureFcm($notificationChannel);
|
|
173
|
-
|
|
174
|
-
return $notificationChannel->app_key;
|
|
118
|
+
return PushNotification::createApnMessage(
|
|
119
|
+
$this->order,
|
|
120
|
+
$this->subject,
|
|
121
|
+
$this->body,
|
|
122
|
+
$this->status,
|
|
123
|
+
$notifiable
|
|
124
|
+
);
|
|
175
125
|
}
|
|
176
126
|
|
|
177
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Get the array representation of the notification.
|
|
129
|
+
*/
|
|
130
|
+
public function toArray($notifiable): array
|
|
178
131
|
{
|
|
179
|
-
$
|
|
180
|
-
$
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
132
|
+
$this->order->loadMissing(['customer', 'company']);
|
|
133
|
+
$customer = $this->order->customer;
|
|
134
|
+
$company = $this->order->company;
|
|
135
|
+
|
|
136
|
+
return [
|
|
137
|
+
'notifiable' => $notifiable->public_id,
|
|
138
|
+
'notification_id' => $this->notificationId,
|
|
139
|
+
'sent_at' => $this->sentAt,
|
|
140
|
+
'subject' => $this->subject,
|
|
141
|
+
'message' => $this->body,
|
|
142
|
+
'storefront' => $this->storefront->name,
|
|
143
|
+
'storefront_id' => $this->storefront->public_id,
|
|
144
|
+
'id' => $customer->public_id,
|
|
145
|
+
'email' => $customer->email,
|
|
146
|
+
'phone' => $customer->phone,
|
|
147
|
+
'companyId' => $company->public_id,
|
|
148
|
+
'company' => $company->name,
|
|
149
|
+
];
|
|
191
150
|
}
|
|
192
151
|
}
|