@fleetbase/storefront-engine 0.2.4 → 0.2.6
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/README.md +4 -4
- package/addon/components/modals/import-products.hbs +1 -1
- package/addon/components/schedule-manager.hbs +2 -2
- package/addon/components/widget/customers.hbs +1 -1
- package/addon/components/widget/customers.js +7 -4
- package/addon/components/widget/orders.js +4 -0
- package/addon/controllers/base-controller.js +31 -0
- package/addon/controllers/networks/index/network.js +2 -2
- package/addon/controllers/networks/index.js +3 -2
- package/addon/controllers/products/index/category/new.js +14 -11
- package/addon/controllers/products/index/category.js +2 -2
- package/addon/controllers/products/index/index.js +2 -2
- package/addon/controllers/products/index.js +2 -3
- package/addon/models/network.js +0 -1
- package/addon/models/product-addon-category.js +10 -1
- package/addon/models/product-variant.js +0 -2
- package/addon/models/product.js +35 -2
- package/addon/routes/customers/index.js +11 -1
- package/addon/routes/networks/index.js +9 -0
- package/addon/routes/orders/index.js +11 -1
- package/addon/routes/products/index.js +8 -2
- package/addon/serializers/product.js +16 -0
- package/addon/services/storefront.js +81 -0
- package/addon/templates/networks/index/network/stores.hbs +2 -2
- package/addon/templates/networks/index/network.hbs +1 -1
- package/addon/templates/products/index/category/new.hbs +3 -3
- package/addon/templates/products/index/category.hbs +20 -3
- package/app/controllers/base-controller.js +1 -0
- package/assets/sounds/storefront_order_alert.mp3 +0 -0
- package/composer.json +3 -3
- package/config/environment.js +11 -1
- package/extension.json +1 -1
- package/index.js +15 -0
- package/package.json +132 -125
- package/server/src/Auth/Schemas/Storefront.php +31 -39
- package/server/src/Console/Commands/NotifyStorefrontOrderNearby.php +9 -11
- package/server/src/Expansions/ContactFilterExpansion.php +36 -0
- package/server/src/Expansions/EntityExpansion.php +12 -12
- package/server/src/Expansions/OrderFilterExpansion.php +31 -0
- package/server/src/Expansions/VendorFilterExpansion.php +36 -0
- package/server/src/Http/Controllers/ActionController.php +9 -11
- package/server/src/Http/Controllers/AddonCategoryController.php +1 -1
- package/server/src/Http/Controllers/CustomerController.php +1 -1
- package/server/src/Http/Controllers/GatewayController.php +1 -1
- package/server/src/Http/Controllers/MetricsController.php +17 -17
- package/server/src/Http/Controllers/NetworkController.php +16 -26
- package/server/src/Http/Controllers/NotificationChannelController.php +1 -1
- package/server/src/Http/Controllers/OrderController.php +18 -22
- package/server/src/Http/Controllers/ProductAddonCategoryController.php +1 -2
- package/server/src/Http/Controllers/ProductAddonController.php +1 -2
- package/server/src/Http/Controllers/ProductController.php +89 -44
- package/server/src/Http/Controllers/ProductHourController.php +1 -1
- package/server/src/Http/Controllers/ProductVariantController.php +1 -1
- package/server/src/Http/Controllers/ProductVariantOptionController.php +1 -1
- package/server/src/Http/Controllers/ReviewController.php +1 -1
- package/server/src/Http/Controllers/StoreController.php +1 -2
- package/server/src/Http/Controllers/StoreHourController.php +1 -1
- package/server/src/Http/Controllers/StoreLocationController.php +1 -1
- package/server/src/Http/Controllers/StorefrontController.php +0 -2
- package/server/src/Http/Controllers/VoteController.php +1 -1
- package/server/src/Http/Controllers/v1/CartController.php +16 -26
- package/server/src/Http/Controllers/v1/CategoryController.php +3 -4
- package/server/src/Http/Controllers/v1/CheckoutController.php +283 -286
- package/server/src/Http/Controllers/v1/CustomerController.php +54 -67
- package/server/src/Http/Controllers/v1/GatewayControllerController.php +0 -2
- package/server/src/Http/Controllers/v1/NetworkController.php +26 -23
- package/server/src/Http/Controllers/v1/PaymentMethodController.php +0 -2
- package/server/src/Http/Controllers/v1/ProductController.php +1 -4
- package/server/src/Http/Controllers/v1/ReviewController.php +31 -35
- package/server/src/Http/Controllers/v1/ServiceQuoteController.php +57 -53
- package/server/src/Http/Controllers/v1/StoreController.php +8 -16
- package/server/src/Http/Filter/AddonCategoryFilter.php +1 -1
- package/server/src/Http/Filter/OrderFilter.php +2 -2
- package/server/src/Http/Middleware/SetStorefrontSession.php +9 -20
- package/server/src/Http/Requests/AddStoreToNetworkCategory.php +3 -3
- package/server/src/Http/Requests/CreateCustomerRequest.php +5 -7
- package/server/src/Http/Requests/CreateReviewRequest.php +4 -5
- package/server/src/Http/Requests/GetServiceQuoteFromCart.php +2 -2
- package/server/src/Http/Requests/InitializeCheckoutRequest.php +5 -5
- package/server/src/Http/Requests/NetworkActionRequest.php +2 -2
- package/server/src/Http/Requests/VerifyCreateCustomerRequest.php +2 -2
- package/server/src/Http/Resources/Cart.php +20 -11
- package/server/src/Http/Resources/Category.php +12 -11
- package/server/src/Http/Resources/Customer.php +15 -14
- package/server/src/Http/Resources/Gateway.php +12 -11
- package/server/src/Http/Resources/Media.php +9 -8
- package/server/src/Http/Resources/Network.php +33 -28
- package/server/src/Http/Resources/Product.php +89 -81
- package/server/src/Http/Resources/Review.php +14 -13
- package/server/src/Http/Resources/ReviewCustomer.php +12 -11
- package/server/src/Http/Resources/Store.php +39 -33
- package/server/src/Http/Resources/StoreHour.php +9 -8
- package/server/src/Http/Resources/StoreLocation.php +9 -9
- package/server/src/Imports/ProductsImport.php +0 -2
- package/server/src/Jobs/DownloadProductImageUrl.php +7 -4
- package/server/src/Listeners/HandleOrderCompleted.php +2 -1
- package/server/src/Listeners/HandleOrderDispatched.php +2 -1
- package/server/src/Listeners/HandleOrderDriverAssigned.php +2 -1
- package/server/src/Listeners/HandleOrderStarted.php +4 -3
- package/server/src/Mail/StorefrontNetworkInvite.php +7 -6
- package/server/src/Models/AddonCategory.php +2 -4
- package/server/src/Models/Cart.php +117 -124
- package/server/src/Models/Checkout.php +14 -12
- package/server/src/Models/Customer.php +9 -9
- package/server/src/Models/Gateway.php +22 -22
- package/server/src/Models/Network.php +41 -52
- package/server/src/Models/NetworkStore.php +6 -5
- package/server/src/Models/NotificationChannel.php +11 -9
- package/server/src/Models/PaymentMethod.php +9 -7
- package/server/src/Models/Product.php +152 -30
- package/server/src/Models/ProductAddon.php +14 -11
- package/server/src/Models/ProductAddonCategory.php +9 -8
- package/server/src/Models/ProductHour.php +6 -5
- package/server/src/Models/ProductStoreLocation.php +7 -5
- package/server/src/Models/ProductVariant.php +15 -11
- package/server/src/Models/ProductVariantOption.php +12 -9
- package/server/src/Models/Review.php +9 -7
- package/server/src/Models/Store.php +68 -84
- package/server/src/Models/StoreHour.php +6 -5
- package/server/src/Models/StoreLocation.php +12 -8
- package/server/src/Models/StorefrontModel.php +1 -1
- package/server/src/Models/Vote.php +8 -6
- package/server/src/Notifications/StorefrontOrderCanceled.php +15 -19
- package/server/src/Notifications/StorefrontOrderCompleted.php +15 -19
- package/server/src/Notifications/StorefrontOrderCreated.php +31 -36
- package/server/src/Notifications/StorefrontOrderDriverAssigned.php +15 -20
- package/server/src/Notifications/StorefrontOrderEnroute.php +14 -19
- package/server/src/Notifications/StorefrontOrderNearby.php +16 -21
- package/server/src/Notifications/StorefrontOrderPreparing.php +15 -18
- package/server/src/Notifications/StorefrontOrderReadyForPickup.php +15 -18
- package/server/src/Observers/NetworkObserver.php +2 -3
- package/server/src/Observers/ProductObserver.php +17 -33
- package/server/src/Providers/EventServiceProvider.php +15 -4
- package/server/src/Providers/StorefrontServiceProvider.php +8 -10
- package/server/src/Support/Metrics.php +12 -12
- package/server/src/Support/OrderConfig.php +3 -2
- package/server/src/Support/QPay.php +22 -20
- package/server/src/Support/Storefront.php +18 -17
- package/server/src/routes.php +1 -1
- package/tsconfig.declarations.json +10 -0
|
@@ -4,25 +4,25 @@ namespace Fleetbase\Storefront\Notifications;
|
|
|
4
4
|
|
|
5
5
|
use Exception;
|
|
6
6
|
use Fleetbase\FleetOps\Models\Order;
|
|
7
|
+
use Fleetbase\FleetOps\Support\Utils;
|
|
7
8
|
use Fleetbase\Storefront\Models\NotificationChannel;
|
|
8
9
|
use Fleetbase\Storefront\Support\Storefront;
|
|
9
|
-
use Fleetbase\FleetOps\Support\Utils;
|
|
10
10
|
// use Fleetbase\FleetOps\Support\Utils;
|
|
11
11
|
use Illuminate\Bus\Queueable;
|
|
12
12
|
// use Illuminate\Contracts\Queue\ShouldQueue;
|
|
13
13
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
14
14
|
use Illuminate\Notifications\Notification;
|
|
15
|
-
use NotificationChannels\Fcm\FcmChannel;
|
|
16
|
-
use NotificationChannels\Fcm\FcmMessage;
|
|
17
15
|
use NotificationChannels\Apn\ApnChannel;
|
|
18
16
|
use NotificationChannels\Apn\ApnMessage;
|
|
17
|
+
use NotificationChannels\Fcm\FcmChannel;
|
|
18
|
+
use NotificationChannels\Fcm\FcmMessage;
|
|
19
19
|
use NotificationChannels\Fcm\Resources\AndroidConfig;
|
|
20
20
|
use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
|
|
21
21
|
use NotificationChannels\Fcm\Resources\AndroidNotification;
|
|
22
22
|
use NotificationChannels\Fcm\Resources\ApnsConfig;
|
|
23
23
|
use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
|
|
24
|
-
use Pushok\Client as PushOkClient;
|
|
25
24
|
use Pushok\AuthProvider\Token as PuskOkToken;
|
|
25
|
+
use Pushok\Client as PushOkClient;
|
|
26
26
|
|
|
27
27
|
class StorefrontOrderPreparing extends Notification
|
|
28
28
|
{
|
|
@@ -35,14 +35,13 @@ class StorefrontOrderPreparing extends Notification
|
|
|
35
35
|
*/
|
|
36
36
|
public function __construct(Order $order)
|
|
37
37
|
{
|
|
38
|
-
$this->order
|
|
38
|
+
$this->order = $order->setRelations([]);
|
|
39
39
|
$this->storefront = Storefront::findAbout($this->order->getMeta('storefront_id'));
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Get the notification's delivery channels.
|
|
44
44
|
*
|
|
45
|
-
* @param mixed $notifiable
|
|
46
45
|
* @return array
|
|
47
46
|
*/
|
|
48
47
|
public function via($notifiable)
|
|
@@ -70,12 +69,11 @@ class StorefrontOrderPreparing extends Notification
|
|
|
70
69
|
/**
|
|
71
70
|
* Get the mail representation of the notification.
|
|
72
71
|
*
|
|
73
|
-
* @param mixed $notifiable
|
|
74
72
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
75
73
|
*/
|
|
76
74
|
public function toMail($notifiable)
|
|
77
75
|
{
|
|
78
|
-
$message = (new MailMessage)
|
|
76
|
+
$message = (new MailMessage())
|
|
79
77
|
->subject('Your order from ' . $this->storefront->name . ' is being prepared')
|
|
80
78
|
->line('Your order is getting started.');
|
|
81
79
|
|
|
@@ -87,7 +85,6 @@ class StorefrontOrderPreparing extends Notification
|
|
|
87
85
|
/**
|
|
88
86
|
* Get the firebase cloud message representation of the notification.
|
|
89
87
|
*
|
|
90
|
-
* @param mixed $notifiable
|
|
91
88
|
* @return array
|
|
92
89
|
*/
|
|
93
90
|
public function toFcm($notifiable)
|
|
@@ -118,13 +115,13 @@ class StorefrontOrderPreparing extends Notification
|
|
|
118
115
|
if ($this->order->hasMeta('storefront_notification_channel')) {
|
|
119
116
|
$notificationChannel = NotificationChannel::where([
|
|
120
117
|
'owner_uuid' => $about->uuid,
|
|
121
|
-
'app_key'
|
|
122
|
-
'scheme'
|
|
118
|
+
'app_key' => $this->order->getMeta('storefront_notification_channel'),
|
|
119
|
+
'scheme' => 'fcm',
|
|
123
120
|
])->first();
|
|
124
121
|
} else {
|
|
125
122
|
$notificationChannel = NotificationChannel::where([
|
|
126
123
|
'owner_uuid' => $about->uuid,
|
|
127
|
-
'scheme'
|
|
124
|
+
'scheme' => 'fcm',
|
|
128
125
|
])->first();
|
|
129
126
|
}
|
|
130
127
|
|
|
@@ -139,7 +136,7 @@ class StorefrontOrderPreparing extends Notification
|
|
|
139
136
|
|
|
140
137
|
public function configureFcm($notificationChannel)
|
|
141
138
|
{
|
|
142
|
-
$config
|
|
139
|
+
$config = (array) $notificationChannel->config;
|
|
143
140
|
$fcmConfig = config('firebase.projects.app');
|
|
144
141
|
|
|
145
142
|
// set credentials
|
|
@@ -156,7 +153,6 @@ class StorefrontOrderPreparing extends Notification
|
|
|
156
153
|
/**
|
|
157
154
|
* Get the apns message representation of the notification.
|
|
158
155
|
*
|
|
159
|
-
* @param mixed $notifiable
|
|
160
156
|
* @return array
|
|
161
157
|
*/
|
|
162
158
|
public function toApn($notifiable)
|
|
@@ -166,13 +162,13 @@ class StorefrontOrderPreparing extends Notification
|
|
|
166
162
|
if ($this->order->hasMeta('storefront_notification_channel')) {
|
|
167
163
|
$notificationChannel = NotificationChannel::where([
|
|
168
164
|
'owner_uuid' => $about->uuid,
|
|
169
|
-
'app_key'
|
|
170
|
-
'scheme'
|
|
165
|
+
'app_key' => $this->order->getMeta('storefront_notification_channel'),
|
|
166
|
+
'scheme' => 'apn',
|
|
171
167
|
])->first();
|
|
172
168
|
} else {
|
|
173
169
|
$notificationChannel = NotificationChannel::where([
|
|
174
170
|
'owner_uuid' => $about->uuid,
|
|
175
|
-
'scheme'
|
|
171
|
+
'scheme' => 'apn',
|
|
176
172
|
])->first();
|
|
177
173
|
}
|
|
178
174
|
|
|
@@ -188,9 +184,10 @@ class StorefrontOrderPreparing extends Notification
|
|
|
188
184
|
|
|
189
185
|
try {
|
|
190
186
|
$channelClient = new PushOkClient(PuskOkToken::create($config));
|
|
191
|
-
} catch (Exception $e) {
|
|
187
|
+
} catch (\Exception $e) {
|
|
192
188
|
// report to sentry the exception
|
|
193
189
|
app('sentry')->captureException($e);
|
|
190
|
+
|
|
194
191
|
// return the apn message to be sent by fleetbase defaults anyway -- backup
|
|
195
192
|
return;
|
|
196
193
|
}
|
|
@@ -4,25 +4,25 @@ namespace Fleetbase\Storefront\Notifications;
|
|
|
4
4
|
|
|
5
5
|
use Exception;
|
|
6
6
|
use Fleetbase\FleetOps\Models\Order;
|
|
7
|
+
use Fleetbase\FleetOps\Support\Utils;
|
|
7
8
|
use Fleetbase\Storefront\Models\NotificationChannel;
|
|
8
9
|
use Fleetbase\Storefront\Support\Storefront;
|
|
9
|
-
use Fleetbase\FleetOps\Support\Utils;
|
|
10
10
|
// use Fleetbase\FleetOps\Support\Utils;
|
|
11
11
|
use Illuminate\Bus\Queueable;
|
|
12
12
|
// use Illuminate\Contracts\Queue\ShouldQueue;
|
|
13
13
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
14
14
|
use Illuminate\Notifications\Notification;
|
|
15
|
-
use NotificationChannels\Fcm\FcmChannel;
|
|
16
|
-
use NotificationChannels\Fcm\FcmMessage;
|
|
17
15
|
use NotificationChannels\Apn\ApnChannel;
|
|
18
16
|
use NotificationChannels\Apn\ApnMessage;
|
|
17
|
+
use NotificationChannels\Fcm\FcmChannel;
|
|
18
|
+
use NotificationChannels\Fcm\FcmMessage;
|
|
19
19
|
use NotificationChannels\Fcm\Resources\AndroidConfig;
|
|
20
20
|
use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
|
|
21
21
|
use NotificationChannels\Fcm\Resources\AndroidNotification;
|
|
22
22
|
use NotificationChannels\Fcm\Resources\ApnsConfig;
|
|
23
23
|
use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
|
|
24
|
-
use Pushok\Client as PushOkClient;
|
|
25
24
|
use Pushok\AuthProvider\Token as PuskOkToken;
|
|
25
|
+
use Pushok\Client as PushOkClient;
|
|
26
26
|
|
|
27
27
|
class StorefrontOrderReadyForPickup extends Notification
|
|
28
28
|
{
|
|
@@ -35,14 +35,13 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
35
35
|
*/
|
|
36
36
|
public function __construct(Order $order)
|
|
37
37
|
{
|
|
38
|
-
$this->order
|
|
38
|
+
$this->order = $order->setRelations([]);
|
|
39
39
|
$this->storefront = Storefront::findAbout($this->order->getMeta('storefront_id'));
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Get the notification's delivery channels.
|
|
44
44
|
*
|
|
45
|
-
* @param mixed $notifiable
|
|
46
45
|
* @return array
|
|
47
46
|
*/
|
|
48
47
|
public function via($notifiable)
|
|
@@ -70,12 +69,11 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
70
69
|
/**
|
|
71
70
|
* Get the mail representation of the notification.
|
|
72
71
|
*
|
|
73
|
-
* @param mixed $notifiable
|
|
74
72
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
75
73
|
*/
|
|
76
74
|
public function toMail($notifiable)
|
|
77
75
|
{
|
|
78
|
-
$message = (new MailMessage)
|
|
76
|
+
$message = (new MailMessage())
|
|
79
77
|
->subject('Your order from ' . $this->storefront->name . ' is ready for pickup!')
|
|
80
78
|
->line('You can proceed to pickup your order.');
|
|
81
79
|
|
|
@@ -87,7 +85,6 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
87
85
|
/**
|
|
88
86
|
* Get the firebase cloud message representation of the notification.
|
|
89
87
|
*
|
|
90
|
-
* @param mixed $notifiable
|
|
91
88
|
* @return array
|
|
92
89
|
*/
|
|
93
90
|
public function toFcm($notifiable)
|
|
@@ -118,13 +115,13 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
118
115
|
if ($this->order->hasMeta('storefront_notification_channel')) {
|
|
119
116
|
$notificationChannel = NotificationChannel::where([
|
|
120
117
|
'owner_uuid' => $about->uuid,
|
|
121
|
-
'app_key'
|
|
122
|
-
'scheme'
|
|
118
|
+
'app_key' => $this->order->getMeta('storefront_notification_channel'),
|
|
119
|
+
'scheme' => 'fcm',
|
|
123
120
|
])->first();
|
|
124
121
|
} else {
|
|
125
122
|
$notificationChannel = NotificationChannel::where([
|
|
126
123
|
'owner_uuid' => $about->uuid,
|
|
127
|
-
'scheme'
|
|
124
|
+
'scheme' => 'fcm',
|
|
128
125
|
])->first();
|
|
129
126
|
}
|
|
130
127
|
|
|
@@ -139,7 +136,7 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
139
136
|
|
|
140
137
|
public function configureFcm($notificationChannel)
|
|
141
138
|
{
|
|
142
|
-
$config
|
|
139
|
+
$config = (array) $notificationChannel->config;
|
|
143
140
|
$fcmConfig = config('firebase.projects.app');
|
|
144
141
|
|
|
145
142
|
// set credentials
|
|
@@ -156,7 +153,6 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
156
153
|
/**
|
|
157
154
|
* Get the apns message representation of the notification.
|
|
158
155
|
*
|
|
159
|
-
* @param mixed $notifiable
|
|
160
156
|
* @return array
|
|
161
157
|
*/
|
|
162
158
|
public function toApn($notifiable)
|
|
@@ -166,13 +162,13 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
166
162
|
if ($this->order->hasMeta('storefront_notification_channel')) {
|
|
167
163
|
$notificationChannel = NotificationChannel::where([
|
|
168
164
|
'owner_uuid' => $about->uuid,
|
|
169
|
-
'app_key'
|
|
170
|
-
'scheme'
|
|
165
|
+
'app_key' => $this->order->getMeta('storefront_notification_channel'),
|
|
166
|
+
'scheme' => 'apn',
|
|
171
167
|
])->first();
|
|
172
168
|
} else {
|
|
173
169
|
$notificationChannel = NotificationChannel::where([
|
|
174
170
|
'owner_uuid' => $about->uuid,
|
|
175
|
-
'scheme'
|
|
171
|
+
'scheme' => 'apn',
|
|
176
172
|
])->first();
|
|
177
173
|
}
|
|
178
174
|
|
|
@@ -188,9 +184,10 @@ class StorefrontOrderReadyForPickup extends Notification
|
|
|
188
184
|
|
|
189
185
|
try {
|
|
190
186
|
$channelClient = new PushOkClient(PuskOkToken::create($config));
|
|
191
|
-
} catch (Exception $e) {
|
|
187
|
+
} catch (\Exception $e) {
|
|
192
188
|
// report to sentry the exception
|
|
193
189
|
app('sentry')->captureException($e);
|
|
190
|
+
|
|
194
191
|
// return the apn message to be sent by fleetbase defaults anyway -- backup
|
|
195
192
|
return;
|
|
196
193
|
}
|
|
@@ -10,8 +10,7 @@ class NetworkObserver
|
|
|
10
10
|
/**
|
|
11
11
|
* Handle the Network "updated" event.
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @return void
|
|
13
|
+
* @param \Fleetbase\Storefront\Models\Network $network the Network that is updating
|
|
15
14
|
*/
|
|
16
15
|
public function updating(Network $network): void
|
|
17
16
|
{
|
|
@@ -32,7 +31,7 @@ class NetworkObserver
|
|
|
32
31
|
}
|
|
33
32
|
)
|
|
34
33
|
->values()
|
|
35
|
-
->toArray()
|
|
34
|
+
->toArray(),
|
|
36
35
|
];
|
|
37
36
|
}
|
|
38
37
|
)->toArray();
|
|
@@ -2,49 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\Storefront\Observers;
|
|
4
4
|
|
|
5
|
-
use Fleetbase\Models\File;
|
|
6
5
|
use Fleetbase\FleetOps\Support\Utils;
|
|
6
|
+
use Fleetbase\Models\File;
|
|
7
7
|
use Fleetbase\Storefront\Models\Product;
|
|
8
8
|
use Fleetbase\Storefront\Models\ProductAddonCategory;
|
|
9
9
|
use Fleetbase\Storefront\Models\ProductVariant;
|
|
10
10
|
use Fleetbase\Storefront\Models\ProductVariantOption;
|
|
11
|
-
use Illuminate\Support\Facades\Request;
|
|
12
11
|
use Illuminate\Support\Arr;
|
|
12
|
+
use Illuminate\Support\Facades\Request;
|
|
13
|
+
use Illuminate\Support\Str;
|
|
13
14
|
|
|
14
15
|
class ProductObserver
|
|
15
16
|
{
|
|
16
17
|
/**
|
|
17
18
|
* Handle the Product "created" event.
|
|
18
19
|
*
|
|
19
|
-
* @param
|
|
20
|
-
* @return void
|
|
20
|
+
* @param \Fleetbase\Storefront\Models\Product $product the Product that was created
|
|
21
21
|
*/
|
|
22
22
|
public function created(Product $product): void
|
|
23
23
|
{
|
|
24
|
-
$addonCategories = Request::input('product.addon_categories');
|
|
25
|
-
$variants
|
|
26
|
-
$files
|
|
24
|
+
$addonCategories = Request::input('product.addon_categories', []);
|
|
25
|
+
$variants = Request::input('product.variants', []);
|
|
26
|
+
$files = Request::input('product.files', []);
|
|
27
27
|
|
|
28
28
|
// save addon categories
|
|
29
|
-
|
|
30
|
-
$addonCategory['product_uuid'] = $product->uuid;
|
|
31
|
-
|
|
32
|
-
ProductAddonCategory::create(Arr::except($addonCategory, ['category']));
|
|
33
|
-
}
|
|
29
|
+
$product->setAddonCategories($addonCategories);
|
|
34
30
|
|
|
35
31
|
// save product variants
|
|
36
|
-
|
|
37
|
-
$variant['created_by_uuid'] = Request::session()->get('user');
|
|
38
|
-
$variant['company_uuid'] = Request::session()->get('company');
|
|
39
|
-
$variant['product_uuid'] = $product->uuid;
|
|
40
|
-
|
|
41
|
-
$productVariant = ProductVariant::create(Arr::except($variant, ['options']));
|
|
42
|
-
|
|
43
|
-
foreach ($variant['options'] as $option) {
|
|
44
|
-
$option['product_variant_uuid'] = $productVariant->uuid;
|
|
45
|
-
ProductVariantOption::create($option);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
32
|
+
$product->setProductVariants($variants);
|
|
48
33
|
|
|
49
34
|
// set keys on files
|
|
50
35
|
foreach ($files as $file) {
|
|
@@ -56,17 +41,16 @@ class ProductObserver
|
|
|
56
41
|
/**
|
|
57
42
|
* Handle the Product "updated" event.
|
|
58
43
|
*
|
|
59
|
-
* @param
|
|
60
|
-
* @return void
|
|
44
|
+
* @param \Fleetbase\Storefront\Models\Product $product the Product that was created
|
|
61
45
|
*/
|
|
62
46
|
public function updated(Product $product): void
|
|
63
47
|
{
|
|
64
|
-
$
|
|
65
|
-
$variants
|
|
48
|
+
$addonCategories = Request::input('product.addon_categories', []);
|
|
49
|
+
$variants = Request::input('product.variants', []);
|
|
66
50
|
|
|
67
51
|
// update addon categories
|
|
68
|
-
foreach ($
|
|
69
|
-
if (
|
|
52
|
+
foreach ($addonCategories as $productAddonCategory) {
|
|
53
|
+
if (isset($productAddonCategory['uuid']) && Str::isUuid($productAddonCategory['uuid'])) {
|
|
70
54
|
ProductAddonCategory::where('uuid', $productAddonCategory['uuid'])->update(Arr::except($productAddonCategory, ['uuid', 'name', 'category']));
|
|
71
55
|
continue;
|
|
72
56
|
}
|
|
@@ -78,7 +62,7 @@ class ProductObserver
|
|
|
78
62
|
|
|
79
63
|
// update product variants
|
|
80
64
|
foreach ($variants as $variant) {
|
|
81
|
-
if (
|
|
65
|
+
if (isset($variant['uuid']) && Str::isUuid($variant['uuid'])) {
|
|
82
66
|
// update product variante
|
|
83
67
|
ProductVariant::where('uuid', $variant['uuid'])->update(Arr::except($variant, ['uuid', 'options']));
|
|
84
68
|
|
|
@@ -104,8 +88,8 @@ class ProductObserver
|
|
|
104
88
|
|
|
105
89
|
// create new variant
|
|
106
90
|
$variant['created_by_uuid'] = Request::session()->get('user');
|
|
107
|
-
$variant['company_uuid']
|
|
108
|
-
$variant['product_uuid']
|
|
91
|
+
$variant['company_uuid'] = Request::session()->get('company');
|
|
92
|
+
$variant['product_uuid'] = $product->uuid;
|
|
109
93
|
|
|
110
94
|
$productVariant = ProductVariant::create(Arr::except($variant, ['options']));
|
|
111
95
|
|
|
@@ -2,22 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\Storefront\Providers;
|
|
4
4
|
|
|
5
|
+
use Fleetbase\Storefront\Models\Product;
|
|
6
|
+
use Fleetbase\Storefront\Observers\ProductObserver;
|
|
5
7
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
|
6
8
|
|
|
7
9
|
class EventServiceProvider extends ServiceProvider
|
|
8
10
|
{
|
|
11
|
+
/**
|
|
12
|
+
* The model observers for your application.
|
|
13
|
+
*
|
|
14
|
+
* @var array
|
|
15
|
+
*/
|
|
16
|
+
// protected $observers = [
|
|
17
|
+
// Product::class => [ProductObserver::class],
|
|
18
|
+
// ];
|
|
19
|
+
|
|
9
20
|
/**
|
|
10
21
|
* The event listener mappings for the application.
|
|
11
22
|
*
|
|
12
23
|
* @var array
|
|
13
24
|
*/
|
|
14
25
|
protected $listen = [
|
|
15
|
-
|
|
26
|
+
/*
|
|
16
27
|
* Order Events
|
|
17
28
|
*/
|
|
18
|
-
\Fleetbase\FleetOps\Events\OrderStarted::class
|
|
19
|
-
\Fleetbase\FleetOps\Events\OrderDispatched::class
|
|
20
|
-
\Fleetbase\FleetOps\Events\OrderCompleted::class
|
|
29
|
+
\Fleetbase\FleetOps\Events\OrderStarted::class => [\Fleetbase\Storefront\Listeners\HandleOrderStarted::class],
|
|
30
|
+
\Fleetbase\FleetOps\Events\OrderDispatched::class => [\Fleetbase\Storefront\Listeners\HandleOrderDispatched::class],
|
|
31
|
+
\Fleetbase\FleetOps\Events\OrderCompleted::class => [\Fleetbase\Storefront\Listeners\HandleOrderCompleted::class],
|
|
21
32
|
\Fleetbase\FleetOps\Events\OrderDriverAssigned::class => [\Fleetbase\Storefront\Listeners\HandleOrderDriverAssigned::class],
|
|
22
33
|
];
|
|
23
34
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\Storefront\Providers;
|
|
4
4
|
|
|
5
|
-
use Fleetbase\Providers\CoreServiceProvider;
|
|
6
5
|
use Fleetbase\FleetOps\Providers\FleetOpsServiceProvider;
|
|
6
|
+
use Fleetbase\Providers\CoreServiceProvider;
|
|
7
7
|
|
|
8
8
|
if (!class_exists(CoreServiceProvider::class)) {
|
|
9
9
|
throw new \Exception('Storefront cannot be loaded without `fleetbase/core-api` installed!');
|
|
@@ -15,8 +15,6 @@ if (!class_exists(FleetOpsServiceProvider::class)) {
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Storefront service provider.
|
|
18
|
-
*
|
|
19
|
-
* @package \Fleetbase\Storefront\Providers
|
|
20
18
|
*/
|
|
21
19
|
class StorefrontServiceProvider extends CoreServiceProvider
|
|
22
20
|
{
|
|
@@ -37,7 +35,7 @@ class StorefrontServiceProvider extends CoreServiceProvider
|
|
|
37
35
|
*/
|
|
38
36
|
public $middleware = [
|
|
39
37
|
'storefront.api' => [
|
|
40
|
-
'throttle:
|
|
38
|
+
'throttle:80,1',
|
|
41
39
|
\Illuminate\Session\Middleware\StartSession::class,
|
|
42
40
|
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
|
43
41
|
\Fleetbase\Storefront\Http\Middleware\SetStorefrontSession::class,
|
|
@@ -54,15 +52,15 @@ class StorefrontServiceProvider extends CoreServiceProvider
|
|
|
54
52
|
* @var array
|
|
55
53
|
*/
|
|
56
54
|
public $commands = [
|
|
57
|
-
\Fleetbase\Storefront\Console\Commands\NotifyStorefrontOrderNearby::class
|
|
55
|
+
\Fleetbase\Storefront\Console\Commands\NotifyStorefrontOrderNearby::class,
|
|
58
56
|
];
|
|
59
57
|
|
|
60
58
|
/**
|
|
61
59
|
* Register any application services.
|
|
62
60
|
*
|
|
63
|
-
* Within the register method, you should only bind things into the
|
|
64
|
-
* service container. You should never attempt to register any event
|
|
65
|
-
* listeners, routes, or any other piece of functionality within the
|
|
61
|
+
* Within the register method, you should only bind things into the
|
|
62
|
+
* service container. You should never attempt to register any event
|
|
63
|
+
* listeners, routes, or any other piece of functionality within the
|
|
66
64
|
* register method.
|
|
67
65
|
*
|
|
68
66
|
* More information on this can be found in the Laravel documentation:
|
|
@@ -81,8 +79,8 @@ class StorefrontServiceProvider extends CoreServiceProvider
|
|
|
81
79
|
*
|
|
82
80
|
* @return void
|
|
83
81
|
*
|
|
84
|
-
* @throws \Exception
|
|
85
|
-
* @throws \Exception
|
|
82
|
+
* @throws \Exception if the `fleetbase/core-api` package is not installed
|
|
83
|
+
* @throws \Exception if the `fleetbase/fleetops-api` package is not installed
|
|
86
84
|
*/
|
|
87
85
|
public function boot()
|
|
88
86
|
{
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\Storefront\Support;
|
|
4
4
|
|
|
5
|
+
use Fleetbase\FleetOps\Models\Order;
|
|
5
6
|
use Fleetbase\Models\Company;
|
|
6
7
|
use Fleetbase\Storefront\Models\Network;
|
|
7
|
-
use Fleetbase\Storefront\Models\Store;
|
|
8
8
|
use Fleetbase\Storefront\Models\Product;
|
|
9
|
-
use Fleetbase\
|
|
9
|
+
use Fleetbase\Storefront\Models\Store;
|
|
10
10
|
use Illuminate\Support\Carbon;
|
|
11
11
|
use Illuminate\Support\Str;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Metrics service to pull analyitcs and metrics from Storefront.
|
|
15
|
-
*
|
|
15
|
+
*
|
|
16
16
|
* Ex:
|
|
17
17
|
* $metrics = Metrics::new($company)->withTotalStores()->withOrdersCanceled()->get();
|
|
18
18
|
*/
|
|
@@ -23,15 +23,15 @@ class Metrics
|
|
|
23
23
|
protected Company $company;
|
|
24
24
|
protected array $metrics = [];
|
|
25
25
|
|
|
26
|
-
public static function new(Company $company,
|
|
26
|
+
public static function new(Company $company, \DateTime $start = null, \DateTime $end = null): Metrics
|
|
27
27
|
{
|
|
28
28
|
$start = $start === null ? Carbon::create(1900)->toDateTime() : $start;
|
|
29
|
-
$end
|
|
29
|
+
$end = $end === null ? Carbon::tomorrow()->toDateTime() : $end;
|
|
30
30
|
|
|
31
31
|
return (new static())->setCompany($company)->between($start, $end);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
public static function forCompany(Company $company,
|
|
34
|
+
public static function forCompany(Company $company, \DateTime $start = null, \DateTime $end = null): Metrics
|
|
35
35
|
{
|
|
36
36
|
return static::new($company, $start, $end);
|
|
37
37
|
}
|
|
@@ -104,7 +104,7 @@ class Metrics
|
|
|
104
104
|
return $this;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
public function totalProducts(
|
|
107
|
+
public function totalProducts(callable $callback = null): Metrics
|
|
108
108
|
{
|
|
109
109
|
$query = Product::where('company_uuid', $this->company->uuid);
|
|
110
110
|
|
|
@@ -117,7 +117,7 @@ class Metrics
|
|
|
117
117
|
return $this->set('total_products', $data);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
public function totalStores(
|
|
120
|
+
public function totalStores(callable $callback = null): Metrics
|
|
121
121
|
{
|
|
122
122
|
$query = Store::where('company_uuid', $this->company->uuid);
|
|
123
123
|
|
|
@@ -130,7 +130,7 @@ class Metrics
|
|
|
130
130
|
return $this->set('total_stores', $data);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
public function totalNetworks(
|
|
133
|
+
public function totalNetworks(callable $callback = null): Metrics
|
|
134
134
|
{
|
|
135
135
|
$query = Network::where('company_uuid', $this->company->uuid);
|
|
136
136
|
|
|
@@ -143,7 +143,7 @@ class Metrics
|
|
|
143
143
|
return $this->set('total_networks', $data);
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
public function ordersInProgress(
|
|
146
|
+
public function ordersInProgress(callable $callback = null): Metrics
|
|
147
147
|
{
|
|
148
148
|
$query = Order::where('company_uuid', $this->company->uuid)
|
|
149
149
|
->whereBetween('created_at', [$this->start, $this->end])
|
|
@@ -159,7 +159,7 @@ class Metrics
|
|
|
159
159
|
return $this->set('orders_in_progress', $data);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
public function ordersCompleted(
|
|
162
|
+
public function ordersCompleted(callable $callback = null): Metrics
|
|
163
163
|
{
|
|
164
164
|
$query = Order::where('company_uuid', $this->company->uuid)
|
|
165
165
|
->whereBetween('created_at', [$this->start, $this->end])
|
|
@@ -175,7 +175,7 @@ class Metrics
|
|
|
175
175
|
return $this->set('orders_completed', $data);
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
public function ordersCanceled(
|
|
178
|
+
public function ordersCanceled(callable $callback = null): Metrics
|
|
179
179
|
{
|
|
180
180
|
$query = Order::where('company_uuid', $this->company->uuid)
|
|
181
181
|
->whereBetween('created_at', [$this->start, $this->end])
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\Storefront\Support;
|
|
4
4
|
|
|
5
|
-
class OrderConfig
|
|
5
|
+
class OrderConfig
|
|
6
|
+
{
|
|
6
7
|
/**
|
|
7
8
|
* Provides default order configs for Storefront.
|
|
8
9
|
*/
|
|
@@ -10,4 +11,4 @@ class OrderConfig {
|
|
|
10
11
|
{
|
|
11
12
|
return config('storefront.api.types.order', []);
|
|
12
13
|
}
|
|
13
|
-
}
|
|
14
|
+
}
|