@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.
Files changed (140) hide show
  1. package/README.md +4 -4
  2. package/addon/components/modals/import-products.hbs +1 -1
  3. package/addon/components/schedule-manager.hbs +2 -2
  4. package/addon/components/widget/customers.hbs +1 -1
  5. package/addon/components/widget/customers.js +7 -4
  6. package/addon/components/widget/orders.js +4 -0
  7. package/addon/controllers/base-controller.js +31 -0
  8. package/addon/controllers/networks/index/network.js +2 -2
  9. package/addon/controllers/networks/index.js +3 -2
  10. package/addon/controllers/products/index/category/new.js +14 -11
  11. package/addon/controllers/products/index/category.js +2 -2
  12. package/addon/controllers/products/index/index.js +2 -2
  13. package/addon/controllers/products/index.js +2 -3
  14. package/addon/models/network.js +0 -1
  15. package/addon/models/product-addon-category.js +10 -1
  16. package/addon/models/product-variant.js +0 -2
  17. package/addon/models/product.js +35 -2
  18. package/addon/routes/customers/index.js +11 -1
  19. package/addon/routes/networks/index.js +9 -0
  20. package/addon/routes/orders/index.js +11 -1
  21. package/addon/routes/products/index.js +8 -2
  22. package/addon/serializers/product.js +16 -0
  23. package/addon/services/storefront.js +81 -0
  24. package/addon/templates/networks/index/network/stores.hbs +2 -2
  25. package/addon/templates/networks/index/network.hbs +1 -1
  26. package/addon/templates/products/index/category/new.hbs +3 -3
  27. package/addon/templates/products/index/category.hbs +20 -3
  28. package/app/controllers/base-controller.js +1 -0
  29. package/assets/sounds/storefront_order_alert.mp3 +0 -0
  30. package/composer.json +3 -3
  31. package/config/environment.js +11 -1
  32. package/extension.json +1 -1
  33. package/index.js +15 -0
  34. package/package.json +132 -125
  35. package/server/src/Auth/Schemas/Storefront.php +31 -39
  36. package/server/src/Console/Commands/NotifyStorefrontOrderNearby.php +9 -11
  37. package/server/src/Expansions/ContactFilterExpansion.php +36 -0
  38. package/server/src/Expansions/EntityExpansion.php +12 -12
  39. package/server/src/Expansions/OrderFilterExpansion.php +31 -0
  40. package/server/src/Expansions/VendorFilterExpansion.php +36 -0
  41. package/server/src/Http/Controllers/ActionController.php +9 -11
  42. package/server/src/Http/Controllers/AddonCategoryController.php +1 -1
  43. package/server/src/Http/Controllers/CustomerController.php +1 -1
  44. package/server/src/Http/Controllers/GatewayController.php +1 -1
  45. package/server/src/Http/Controllers/MetricsController.php +17 -17
  46. package/server/src/Http/Controllers/NetworkController.php +16 -26
  47. package/server/src/Http/Controllers/NotificationChannelController.php +1 -1
  48. package/server/src/Http/Controllers/OrderController.php +18 -22
  49. package/server/src/Http/Controllers/ProductAddonCategoryController.php +1 -2
  50. package/server/src/Http/Controllers/ProductAddonController.php +1 -2
  51. package/server/src/Http/Controllers/ProductController.php +89 -44
  52. package/server/src/Http/Controllers/ProductHourController.php +1 -1
  53. package/server/src/Http/Controllers/ProductVariantController.php +1 -1
  54. package/server/src/Http/Controllers/ProductVariantOptionController.php +1 -1
  55. package/server/src/Http/Controllers/ReviewController.php +1 -1
  56. package/server/src/Http/Controllers/StoreController.php +1 -2
  57. package/server/src/Http/Controllers/StoreHourController.php +1 -1
  58. package/server/src/Http/Controllers/StoreLocationController.php +1 -1
  59. package/server/src/Http/Controllers/StorefrontController.php +0 -2
  60. package/server/src/Http/Controllers/VoteController.php +1 -1
  61. package/server/src/Http/Controllers/v1/CartController.php +16 -26
  62. package/server/src/Http/Controllers/v1/CategoryController.php +3 -4
  63. package/server/src/Http/Controllers/v1/CheckoutController.php +283 -286
  64. package/server/src/Http/Controllers/v1/CustomerController.php +54 -67
  65. package/server/src/Http/Controllers/v1/GatewayControllerController.php +0 -2
  66. package/server/src/Http/Controllers/v1/NetworkController.php +26 -23
  67. package/server/src/Http/Controllers/v1/PaymentMethodController.php +0 -2
  68. package/server/src/Http/Controllers/v1/ProductController.php +1 -4
  69. package/server/src/Http/Controllers/v1/ReviewController.php +31 -35
  70. package/server/src/Http/Controllers/v1/ServiceQuoteController.php +57 -53
  71. package/server/src/Http/Controllers/v1/StoreController.php +8 -16
  72. package/server/src/Http/Filter/AddonCategoryFilter.php +1 -1
  73. package/server/src/Http/Filter/OrderFilter.php +2 -2
  74. package/server/src/Http/Middleware/SetStorefrontSession.php +9 -20
  75. package/server/src/Http/Requests/AddStoreToNetworkCategory.php +3 -3
  76. package/server/src/Http/Requests/CreateCustomerRequest.php +5 -7
  77. package/server/src/Http/Requests/CreateReviewRequest.php +4 -5
  78. package/server/src/Http/Requests/GetServiceQuoteFromCart.php +2 -2
  79. package/server/src/Http/Requests/InitializeCheckoutRequest.php +5 -5
  80. package/server/src/Http/Requests/NetworkActionRequest.php +2 -2
  81. package/server/src/Http/Requests/VerifyCreateCustomerRequest.php +2 -2
  82. package/server/src/Http/Resources/Cart.php +20 -11
  83. package/server/src/Http/Resources/Category.php +12 -11
  84. package/server/src/Http/Resources/Customer.php +15 -14
  85. package/server/src/Http/Resources/Gateway.php +12 -11
  86. package/server/src/Http/Resources/Media.php +9 -8
  87. package/server/src/Http/Resources/Network.php +33 -28
  88. package/server/src/Http/Resources/Product.php +89 -81
  89. package/server/src/Http/Resources/Review.php +14 -13
  90. package/server/src/Http/Resources/ReviewCustomer.php +12 -11
  91. package/server/src/Http/Resources/Store.php +39 -33
  92. package/server/src/Http/Resources/StoreHour.php +9 -8
  93. package/server/src/Http/Resources/StoreLocation.php +9 -9
  94. package/server/src/Imports/ProductsImport.php +0 -2
  95. package/server/src/Jobs/DownloadProductImageUrl.php +7 -4
  96. package/server/src/Listeners/HandleOrderCompleted.php +2 -1
  97. package/server/src/Listeners/HandleOrderDispatched.php +2 -1
  98. package/server/src/Listeners/HandleOrderDriverAssigned.php +2 -1
  99. package/server/src/Listeners/HandleOrderStarted.php +4 -3
  100. package/server/src/Mail/StorefrontNetworkInvite.php +7 -6
  101. package/server/src/Models/AddonCategory.php +2 -4
  102. package/server/src/Models/Cart.php +117 -124
  103. package/server/src/Models/Checkout.php +14 -12
  104. package/server/src/Models/Customer.php +9 -9
  105. package/server/src/Models/Gateway.php +22 -22
  106. package/server/src/Models/Network.php +41 -52
  107. package/server/src/Models/NetworkStore.php +6 -5
  108. package/server/src/Models/NotificationChannel.php +11 -9
  109. package/server/src/Models/PaymentMethod.php +9 -7
  110. package/server/src/Models/Product.php +152 -30
  111. package/server/src/Models/ProductAddon.php +14 -11
  112. package/server/src/Models/ProductAddonCategory.php +9 -8
  113. package/server/src/Models/ProductHour.php +6 -5
  114. package/server/src/Models/ProductStoreLocation.php +7 -5
  115. package/server/src/Models/ProductVariant.php +15 -11
  116. package/server/src/Models/ProductVariantOption.php +12 -9
  117. package/server/src/Models/Review.php +9 -7
  118. package/server/src/Models/Store.php +68 -84
  119. package/server/src/Models/StoreHour.php +6 -5
  120. package/server/src/Models/StoreLocation.php +12 -8
  121. package/server/src/Models/StorefrontModel.php +1 -1
  122. package/server/src/Models/Vote.php +8 -6
  123. package/server/src/Notifications/StorefrontOrderCanceled.php +15 -19
  124. package/server/src/Notifications/StorefrontOrderCompleted.php +15 -19
  125. package/server/src/Notifications/StorefrontOrderCreated.php +31 -36
  126. package/server/src/Notifications/StorefrontOrderDriverAssigned.php +15 -20
  127. package/server/src/Notifications/StorefrontOrderEnroute.php +14 -19
  128. package/server/src/Notifications/StorefrontOrderNearby.php +16 -21
  129. package/server/src/Notifications/StorefrontOrderPreparing.php +15 -18
  130. package/server/src/Notifications/StorefrontOrderReadyForPickup.php +15 -18
  131. package/server/src/Observers/NetworkObserver.php +2 -3
  132. package/server/src/Observers/ProductObserver.php +17 -33
  133. package/server/src/Providers/EventServiceProvider.php +15 -4
  134. package/server/src/Providers/StorefrontServiceProvider.php +8 -10
  135. package/server/src/Support/Metrics.php +12 -12
  136. package/server/src/Support/OrderConfig.php +3 -2
  137. package/server/src/Support/QPay.php +22 -20
  138. package/server/src/Support/Storefront.php +18 -17
  139. package/server/src/routes.php +1 -1
  140. 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 = $order->setRelations([]);
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' => $this->order->getMeta('storefront_notification_channel'),
122
- 'scheme' => 'fcm'
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' => 'fcm'
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 = (array) $notificationChannel->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' => $this->order->getMeta('storefront_notification_channel'),
170
- 'scheme' => 'apn'
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' => 'apn'
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 = $order->setRelations([]);
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' => $this->order->getMeta('storefront_notification_channel'),
122
- 'scheme' => 'fcm'
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' => 'fcm'
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 = (array) $notificationChannel->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' => $this->order->getMeta('storefront_notification_channel'),
170
- 'scheme' => 'apn'
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' => 'apn'
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 \Fleetbase\Storefront\Models\Network $network The Network that is updating.
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 \Fleetbase\Storefront\Models\Product $product The Product that was created.
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 = Request::input('product.variants');
26
- $files = Request::input('product.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
- foreach ($addonCategories as $addonCategory) {
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
- foreach ($variants as $variant) {
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 \Fleetbase\Storefront\Models\Product $product The Product that was created.
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
- $productAddonCategories = Request::input('product.addon_categories');
65
- $variants = Request::input('product.variants');
48
+ $addonCategories = Request::input('product.addon_categories', []);
49
+ $variants = Request::input('product.variants', []);
66
50
 
67
51
  // update addon categories
68
- foreach ($productAddonCategories as $productAddonCategory) {
69
- if (!empty($productAddonCategory['uuid'])) {
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 (!empty($variant['uuid'])) {
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'] = Request::session()->get('company');
108
- $variant['product_uuid'] = $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 => [\Fleetbase\Storefront\Listeners\HandleOrderStarted::class],
19
- \Fleetbase\FleetOps\Events\OrderDispatched::class => [\Fleetbase\Storefront\Listeners\HandleOrderDispatched::class],
20
- \Fleetbase\FleetOps\Events\OrderCompleted::class => [\Fleetbase\Storefront\Listeners\HandleOrderCompleted::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:60,1',
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 If the `fleetbase/core-api` package is not installed.
85
- * @throws \Exception If the `fleetbase/fleetops-api` package is not installed.
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\FleetOps\Models\Order;
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, ?\DateTime $start = null, ?\DateTime $end = null): Metrics
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 = $end === null ? Carbon::tomorrow()->toDateTime() : $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, ?\DateTime $start = null, ?\DateTime $end = null): Metrics
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(?callable $callback = null): Metrics
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(?callable $callback = null): Metrics
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(?callable $callback = null): Metrics
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(?callable $callback = null): Metrics
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(?callable $callback = null): Metrics
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(?callable $callback = null): Metrics
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
+ }