@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
@@ -4,55 +4,37 @@ namespace Fleetbase\Storefront\Observers;
4
4
 
5
5
  use Fleetbase\Models\File;
6
6
  use Fleetbase\Storefront\Models\Product;
7
+ use Illuminate\Support\Facades\Log;
7
8
  use Illuminate\Support\Facades\Request;
8
9
 
9
10
  class ProductObserver
10
11
  {
11
12
  /**
12
- * Handle the Product "created" event.
13
+ * Handle the Product "saved" event.
13
14
  *
14
- * @param Product $product the Product that was created
15
+ * @param Product $product the Product that was saved
15
16
  */
16
- public function created(Product $product): void
17
+ public function saved(Product $product): void
17
18
  {
18
- $addonCategories = Request::input('product.addon_categories', []);
19
- $variants = Request::input('product.variants', []);
20
- $files = Request::input('product.files', []);
21
-
22
- // save addon categories
23
- $product->setAddonCategories($addonCategories);
24
-
25
- // save product variants
26
- $product->setProductVariants($variants);
27
-
28
- // set keys on files
29
- foreach ($files as $file) {
30
- $fileRecord = File::where('uuid', $file['uuid'])->first();
31
- $fileRecord->setKey($product);
32
- }
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);
19
+ try {
20
+ $addonCategories = Request::input('product.addon_categories', []);
21
+ $variants = Request::input('product.variants', []);
22
+ $files = Request::input('product.files', []);
23
+
24
+ // save addon categories
25
+ $product->setAddonCategories($addonCategories);
26
+
27
+ // save product variants
28
+ $product->setProductVariants($variants);
29
+
30
+ // set keys on files
31
+ foreach ($files as $file) {
32
+ $fileRecord = File::where('uuid', $file['uuid'])->first();
33
+ $fileRecord->setKey($product);
34
+ }
35
+ } catch (\Exception $e) {
36
+ Log::error($e->getMessage());
37
+ throw $e;
56
38
  }
57
39
  }
58
40
  }
@@ -24,9 +24,11 @@ class StorefrontServiceProvider extends CoreServiceProvider
24
24
  * @var array
25
25
  */
26
26
  public $observers = [
27
- \Fleetbase\Storefront\Models\Product::class => \Fleetbase\Storefront\Observers\ProductObserver::class,
28
- \Fleetbase\Storefront\Models\Network::class => \Fleetbase\Storefront\Observers\NetworkObserver::class,
29
- \Fleetbase\Models\Company::class => \Fleetbase\Storefront\Observers\CompanyObserver::class,
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
  /**
@@ -0,0 +1,127 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\Storefront\Support;
4
+
5
+ use Fleetbase\FleetOps\Models\Order;
6
+ use Fleetbase\Storefront\Models\Network;
7
+ use Fleetbase\Storefront\Models\NotificationChannel;
8
+ use Fleetbase\Storefront\Models\Store;
9
+ use Illuminate\Container\Container;
10
+ use Kreait\Laravel\Firebase\FirebaseProjectManager;
11
+ use NotificationChannels\Apn\ApnMessage;
12
+ use NotificationChannels\Fcm\FcmMessage;
13
+ use NotificationChannels\Fcm\Resources\Notification as FcmNotification;
14
+ use Pushok\AuthProvider\Token as PuskOkToken;
15
+ use Pushok\Client as PushOkClient;
16
+
17
+ class PushNotification
18
+ {
19
+ public static function createApnMessage(Order $order, string $title, string $body, string $status, $notifiable = null): ApnMessage
20
+ {
21
+ $storefront = static::getStorefrontFromOrder($order);
22
+ $client = static::getApnClient($storefront, $order);
23
+
24
+ return ApnMessage::create()
25
+ ->badge(1)
26
+ ->title($title)
27
+ ->body($body)
28
+ ->custom('type', $status)
29
+ ->custom('order', $order->uuid)
30
+ ->custom('id', $order->public_id)
31
+ ->action('view_order', ['id' => $order->public_id])
32
+ ->via($client);
33
+ }
34
+
35
+ public static function createFcmMessage(Order $order, string $title, string $body, string $status, $notifiable = null): FcmMessage
36
+ {
37
+ $storefront = static::getStorefrontFromOrder($order);
38
+ $notificationChannel = static::getNotificationChannel('apn', $storefront, $order);
39
+
40
+ // Configure FCM
41
+ static::configureFcm($notificationChannel);
42
+
43
+ // Get FCM Client using Notification Channel
44
+ $container = Container::getInstance();
45
+ $projectManager = new FirebaseProjectManager($container);
46
+ $client = $projectManager->project($notificationChannel->app_key)->messaging();
47
+
48
+ // Create Notification
49
+ $notification = new FcmNotification(
50
+ title: $title,
51
+ body: $body
52
+ );
53
+
54
+ return (new FcmMessage(notification: $notification))
55
+ ->setData(['order' => $order->uuid, 'id' => $order->public_id, 'type' => $status])
56
+ ->custom([
57
+ 'android' => [
58
+ 'notification' => [
59
+ 'color' => '#4391EA',
60
+ 'sound' => 'default',
61
+ ],
62
+ 'fcm_options' => [
63
+ 'analytics_label' => 'analytics',
64
+ ],
65
+ ],
66
+ 'apns' => [
67
+ 'payload' => [
68
+ 'aps' => [
69
+ 'sound' => 'default',
70
+ ],
71
+ ],
72
+ 'fcm_options' => [
73
+ 'analytics_label' => 'analytics',
74
+ ],
75
+ ],
76
+ ])
77
+ ->usingClient($client);
78
+ }
79
+
80
+ public static function configureFcm(NotificationChannel $notificationChannel)
81
+ {
82
+ // Convert the channel's config to an array.
83
+ $config = (array) $notificationChannel->config;
84
+
85
+ // Get the base firebase config.
86
+ $firebaseConfig = config('firebase.projects.app');
87
+
88
+ // Update the firebase config with values from the channel.
89
+ data_set($firebaseConfig, 'credentials.private_key', $config['firebase_credentials_json']);
90
+ data_set($firebaseConfig, 'database.url', $config['firebase_database_url']);
91
+
92
+ // Update the Laravel config for this project key.
93
+ config(['firebase.projects.' . $notificationChannel->app_key => $firebaseConfig]);
94
+
95
+ // Return the updated firebase config.
96
+ return $firebaseConfig;
97
+ }
98
+
99
+ public static function getNotificationChannel(string $scheme, Network|Store $storefront, ?Order $order = null): NotificationChannel
100
+ {
101
+ if ($order && $order->hasMeta('storefront_notification_channel')) {
102
+ return NotificationChannel::where([
103
+ 'owner_uuid' => $storefront->uuid,
104
+ 'app_key' => $order->getMeta('storefront_notification_channel'),
105
+ 'scheme' => $scheme,
106
+ ])->first();
107
+ }
108
+
109
+ return NotificationChannel::where([
110
+ 'owner_uuid' => $storefront->uuid,
111
+ 'scheme' => $scheme,
112
+ ])->first();
113
+ }
114
+
115
+ public static function getApnClient(Network|Store $storefront, ?Order $order = null): PushOkClient
116
+ {
117
+ $notificationChannel = static::getNotificationChannel('apn', $storefront, $order);
118
+ $config = (array) $notificationChannel->config;
119
+
120
+ return new PushOkClient(PuskOkToken::create($config));
121
+ }
122
+
123
+ public static function getStorefrontFromOrder(Order $order): Network|Store|null
124
+ {
125
+ return Storefront::findAbout($order->getMeta('storefront_id'));
126
+ }
127
+ }
@@ -75,6 +75,12 @@ Route::prefix(config('storefront.api.routing.prefix', 'storefront'))->namespace(
75
75
  $router->get('{id}', 'ProductController@find');
76
76
  });
77
77
 
78
+ // storefront/v1/food-trucks
79
+ $router->group(['prefix' => 'food-trucks'], function () use ($router) {
80
+ $router->get('/', 'FoodTruckController@query');
81
+ $router->get('{id}', 'FoodTruckController@find');
82
+ });
83
+
78
84
  // storefront/v1/reviews
79
85
  $router->group(['prefix' => 'reviews'], function () use ($router) {
80
86
  $router->get('/', 'ReviewController@query');
@@ -185,6 +191,10 @@ Route::prefix(config('storefront.api.routing.prefix', 'storefront'))->namespace(
185
191
  $router->fleetbaseRoutes('notification-channels');
186
192
  $router->fleetbaseRoutes('reviews');
187
193
  $router->fleetbaseRoutes('votes');
194
+ $router->fleetbaseRoutes('food-trucks');
195
+ $router->fleetbaseRoutes('catalogs');
196
+ $router->fleetbaseRoutes('catalog-categories');
197
+ $router->fleetbaseRoutes('catalog-hours');
188
198
  $router->group(
189
199
  [],
190
200
  function ($router) {
@@ -70,10 +70,15 @@ storefront:
70
70
  facebook: Facebook
71
71
  instagram: Instagram
72
72
  twitter: Twitter
73
+ food-trucks: Food Trucks
74
+ catalog: Catalog
75
+ catalogs: Catalogs
73
76
  sidebar:
74
77
  storefront: Storefront
75
78
  dashboard: Dashboard
76
79
  products: Products
80
+ catalogs: Catalogs
81
+ food-trucks: Food Trucks
77
82
  customers: Customers
78
83
  orders: Orders
79
84
  networks: Networks