@fleetbase/storefront-engine 0.3.24 → 0.3.26

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.
Files changed (115) hide show
  1. package/addon/adapters/catalog.js +1 -0
  2. package/addon/adapters/food-truck.js +1 -0
  3. package/addon/components/customer-panel/orders.hbs +7 -1
  4. package/addon/components/modals/assign-food-truck-catalogs.hbs +14 -0
  5. package/addon/components/modals/create-catalog.hbs +96 -0
  6. package/addon/components/modals/create-first-store.hbs +6 -1
  7. package/addon/components/modals/create-food-truck.hbs +69 -0
  8. package/addon/components/modals/manage-addons.js +1 -15
  9. package/addon/components/order-panel.hbs +2 -2
  10. package/addon/components/widget/customers.hbs +5 -5
  11. package/addon/components/widget/orders.hbs +7 -4
  12. package/addon/components/widget/orders.js +11 -1
  13. package/addon/controllers/catalogs/index.js +121 -0
  14. package/addon/controllers/food-trucks/index.js +100 -0
  15. package/addon/models/catalog-category.js +6 -0
  16. package/addon/models/catalog-hour.js +72 -0
  17. package/addon/models/catalog.js +45 -0
  18. package/addon/models/food-truck.js +47 -0
  19. package/addon/models/product.js +1 -0
  20. package/addon/routes/catalogs/index.js +22 -0
  21. package/addon/routes/catalogs.js +3 -0
  22. package/addon/routes/food-trucks/index.js +22 -0
  23. package/addon/routes/food-trucks.js +3 -0
  24. package/addon/routes.js +6 -0
  25. package/addon/serializers/catalog-category.js +15 -0
  26. package/addon/serializers/catalog.js +16 -0
  27. package/addon/serializers/food-truck.js +18 -0
  28. package/addon/serializers/product-variant.js +0 -1
  29. package/addon/styles/storefront-engine.css +15 -5
  30. package/addon/templates/application.hbs +14 -0
  31. package/addon/templates/catalogs/index.hbs +46 -0
  32. package/addon/templates/catalogs.hbs +1 -0
  33. package/addon/templates/customers/index.hbs +1 -1
  34. package/addon/templates/food-trucks/index.hbs +52 -0
  35. package/addon/templates/food-trucks.hbs +1 -0
  36. package/addon/templates/networks/index.hbs +14 -2
  37. package/addon/templates/products/index/category/new.hbs +10 -3
  38. package/addon/templates/products/index/index.hbs +1 -2
  39. package/addon/templates/products/index.hbs +16 -2
  40. package/app/adapters/catalog.js +1 -0
  41. package/app/adapters/food-truck.js +1 -0
  42. package/app/components/modals/assign-food-truck-catalogs.js +1 -0
  43. package/app/components/modals/create-catalog.js +1 -0
  44. package/app/components/modals/create-food-truck.js +1 -0
  45. package/app/controllers/catalogs/index.js +1 -0
  46. package/app/controllers/food-trucks/index.js +1 -0
  47. package/app/models/catalog-category.js +1 -0
  48. package/app/models/catalog-hour.js +1 -0
  49. package/app/models/catalog.js +1 -0
  50. package/app/models/food-truck.js +1 -0
  51. package/app/routes/catalogs/index.js +1 -0
  52. package/app/routes/catalogs.js +1 -0
  53. package/app/routes/food-trucks/index.js +1 -0
  54. package/app/routes/food-trucks.js +1 -0
  55. package/app/serializers/catalog-category.js +1 -0
  56. package/app/serializers/catalog.js +1 -0
  57. package/app/serializers/food-truck.js +1 -0
  58. package/app/templates/catalogs/index.js +1 -0
  59. package/app/templates/catalogs.js +1 -0
  60. package/app/templates/food-trucks/index.js +1 -0
  61. package/app/templates/food-trucks.js +1 -0
  62. package/composer.json +1 -1
  63. package/extension.json +1 -1
  64. package/package.json +1 -1
  65. package/server/migrations/2025_01_30_042853_create_catalogs_table.php +41 -0
  66. package/server/migrations/2025_01_30_044728_create_catalog_category_products_table.php +35 -0
  67. package/server/migrations/2025_01_30_050611_create_food_trucks_table.php +72 -0
  68. package/server/migrations/2025_01_30_052157_create_catalog_subjects_table.php +54 -0
  69. package/server/migrations/2025_01_30_052402_create_catalog_hours_table.php +39 -0
  70. package/server/src/Auth/Schemas/Storefront.php +16 -0
  71. package/server/src/Console/Commands/PurgeExpiredCarts.php +13 -3
  72. package/server/src/Http/Controllers/CatalogCategoryController.php +13 -0
  73. package/server/src/Http/Controllers/CatalogController.php +13 -0
  74. package/server/src/Http/Controllers/CatalogHourController.php +13 -0
  75. package/server/src/Http/Controllers/FoodTruckController.php +13 -0
  76. package/server/src/Http/Controllers/v1/CatalogController.php +38 -0
  77. package/server/src/Http/Controllers/v1/CategoryController.php +1 -1
  78. package/server/src/Http/Controllers/v1/CheckoutController.php +4 -0
  79. package/server/src/Http/Controllers/v1/CustomerController.php +5 -1
  80. package/server/src/Http/Controllers/v1/FoodTruckController.php +39 -0
  81. package/server/src/Http/Controllers/v1/ProductController.php +1 -1
  82. package/server/src/Http/Controllers/v1/ReviewController.php +8 -6
  83. package/server/src/Http/Controllers/v1/StoreController.php +10 -0
  84. package/server/src/Http/Filter/FoodTruckFilter.php +37 -0
  85. package/server/src/Http/Resources/Catalog.php +34 -0
  86. package/server/src/Http/Resources/CatalogCategory.php +38 -0
  87. package/server/src/Http/Resources/CatalogProduct.php +55 -0
  88. package/server/src/Http/Resources/FoodTruck.php +42 -0
  89. package/server/src/Http/Resources/Product.php +1 -0
  90. package/server/src/Http/Resources/ReviewCustomer.php +2 -0
  91. package/server/src/Models/AddonCategory.php +12 -0
  92. package/server/src/Models/Cart.php +6 -0
  93. package/server/src/Models/Catalog.php +213 -0
  94. package/server/src/Models/CatalogCategory.php +118 -0
  95. package/server/src/Models/CatalogHour.php +46 -0
  96. package/server/src/Models/CatalogProduct.php +25 -0
  97. package/server/src/Models/CatalogSubject.php +70 -0
  98. package/server/src/Models/FoodTruck.php +182 -0
  99. package/server/src/Models/Product.php +29 -2
  100. package/server/src/Models/Review.php +2 -2
  101. package/server/src/Notifications/StorefrontOrderCanceled.php +80 -121
  102. package/server/src/Notifications/StorefrontOrderCompleted.php +86 -131
  103. package/server/src/Notifications/StorefrontOrderCreated.php +29 -15
  104. package/server/src/Notifications/StorefrontOrderDriverAssigned.php +96 -130
  105. package/server/src/Notifications/StorefrontOrderEnroute.php +89 -129
  106. package/server/src/Notifications/StorefrontOrderNearby.php +103 -132
  107. package/server/src/Notifications/StorefrontOrderPreparing.php +84 -134
  108. package/server/src/Notifications/StorefrontOrderReadyForPickup.php +89 -134
  109. package/server/src/Observers/CatalogObserver.php +40 -0
  110. package/server/src/Observers/FoodTruckObserver.php +24 -0
  111. package/server/src/Observers/ProductObserver.php +23 -41
  112. package/server/src/Providers/StorefrontServiceProvider.php +5 -3
  113. package/server/src/Support/PushNotification.php +127 -0
  114. package/server/src/routes.php +10 -0
  115. 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
+ }
@@ -48,12 +48,19 @@ class Product extends StorefrontModel
48
48
  */
49
49
  protected $table = 'products';
50
50
 
51
+ /**
52
+ * The default database connection to use.
53
+ *
54
+ * @var string
55
+ */
56
+ protected $connection = 'storefront';
57
+
51
58
  /**
52
59
  * These attributes that can be queried.
53
60
  *
54
61
  * @var array
55
62
  */
56
- protected $searchableColumns = ['name', 'description'];
63
+ protected $searchableColumns = ['name', 'description', 'tags'];
57
64
 
58
65
  /**
59
66
  * The attributes that are mass assignable.
@@ -224,6 +231,21 @@ class Product extends StorefrontModel
224
231
  return $this->belongsTo(Store::class);
225
232
  }
226
233
 
234
+ /**
235
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
236
+ */
237
+ public function catalogCategories()
238
+ {
239
+ return $this->belongsToMany(
240
+ CatalogCategory::class,
241
+ 'catalog_category_product',
242
+ 'product_uuid',
243
+ 'catalog_category_uuid'
244
+ )
245
+ ->using(CatalogProduct::class)
246
+ ->withTimestamps();
247
+ }
248
+
227
249
  /**
228
250
  * @return array
229
251
  */
@@ -368,6 +390,11 @@ class Product extends StorefrontModel
368
390
  $option['additional_cost'] = Utils::numbersOnly($option['additional_cost']);
369
391
  }
370
392
 
393
+ // additional cost can never be null
394
+ if ($option['additional_cost'] === null) {
395
+ $option['additional_cost'] = 0;
396
+ }
397
+
371
398
  $productVariantOptionInput = Arr::except($option, ['uuid', 'created_at', 'updated_at']);
372
399
  ProductVariantOption::where('uuid', $option['uuid'])->update($productVariantOptionInput);
373
400
  continue;
@@ -494,7 +521,7 @@ class Product extends StorefrontModel
494
521
  */
495
522
  public function createAsEntity(array $additionalAttributes = []): Entity
496
523
  {
497
- $entity = $this->toEntity();
524
+ $entity = $this->toEntity($additionalAttributes);
498
525
  $entity->save();
499
526
 
500
527
  return $entity;
@@ -2,8 +2,8 @@
2
2
 
3
3
  namespace Fleetbase\Storefront\Models;
4
4
 
5
- use Fleetbase\FleetOps\Models\Contact;
6
5
  use Fleetbase\Models\File;
6
+ use Fleetbase\Models\User;
7
7
  use Fleetbase\Traits\HasApiModelBehavior;
8
8
  use Fleetbase\Traits\HasPublicid;
9
9
  use Fleetbase\Traits\HasUuid;
@@ -84,7 +84,7 @@ class Review extends StorefrontModel
84
84
  */
85
85
  public function customer()
86
86
  {
87
- return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Contact::class);
87
+ return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Customer::class);
88
88
  }
89
89
 
90
90
  /**
@@ -3,23 +3,15 @@
3
3
  namespace Fleetbase\Storefront\Notifications;
4
4
 
5
5
  use Fleetbase\FleetOps\Models\Order;
6
- use Fleetbase\FleetOps\Support\Utils;
7
- use Fleetbase\Storefront\Models\NotificationChannel;
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 = $order->setRelations([]);
50
- $this->storefront = Storefront::findAbout($this->order->getMeta('storefront_id'));
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('Your order from ' . $this->storefront->name . ' was canceled')
72
- ->line('Your order from ' . $this->storefront->name . ' has been canceled, if your card has been charged you will be refunded.')
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 array
98
+ * @return \NotificationChannels\Fcm\FcmMessage
84
99
  */
85
100
  public function toFcm($notifiable)
86
101
  {
87
- $notification = \NotificationChannels\Fcm\Resources\Notification::create()
88
- ->setTitle('Your order from ' . $this->storefront->name . ' was canceled')
89
- ->setBody('Your order from ' . $this->storefront->name . ' has been canceled, if your card has been charged you will be refunded.');
90
-
91
- $message = FcmMessage::create()
92
- ->setData(['order' => $this->order->uuid, 'id' => $this->order->public_id, 'type' => 'order_canceled'])
93
- ->setNotification($notification)
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 array
114
+ * @return \NotificationChannels\Apn\ApnMessage
110
115
  */
111
116
  public function toApn($notifiable)
112
117
  {
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' => 'apn',
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
- public function configureFcm($notificationChannel)
127
+ /**
128
+ * Get the array representation of the notification.
129
+ */
130
+ public function toArray($notifiable): array
178
131
  {
179
- $config = (array) $notificationChannel->config;
180
- $fcmConfig = config('firebase.projects.app');
181
-
182
- // set credentials
183
- Utils::set($fcmConfig, 'credentials.file', $config['firebase_credentials_json']);
184
-
185
- // set db url
186
- Utils::set($fcmConfig, 'database.url', $config['firebase_database_url']);
187
-
188
- config('firebase.projects.' . $notificationChannel->app_key, $fcmConfig);
189
-
190
- return $fcmConfig;
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
  }