@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.
- 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/CheckoutController.php +4 -0
- package/server/src/Http/Controllers/v1/CustomerController.php +5 -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/Controllers/v1/StoreController.php +10 -0
- 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/Http/Resources/ReviewCustomer.php +2 -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 +29 -2
- package/server/src/Models/Review.php +2 -2
- 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 +23 -41
- 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
|
@@ -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 "
|
|
13
|
+
* Handle the Product "saved" event.
|
|
13
14
|
*
|
|
14
|
-
* @param Product $product the Product that was
|
|
15
|
+
* @param Product $product the Product that was saved
|
|
15
16
|
*/
|
|
16
|
-
public function
|
|
17
|
+
public function saved(Product $product): void
|
|
17
18
|
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
$
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
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
|
/**
|
|
@@ -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
|
+
}
|
package/server/src/routes.php
CHANGED
|
@@ -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) {
|
package/translations/en-us.yaml
CHANGED
|
@@ -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
|