@fleetbase/storefront-engine 0.4.0 → 0.4.1

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 (57) hide show
  1. package/addon/components/customer-panel/orders.hbs +2 -2
  2. package/addon/components/modals/create-gateway.hbs +33 -12
  3. package/addon/components/network-category-picker.js +1 -1
  4. package/addon/components/order-panel.hbs +1 -1
  5. package/addon/components/widget/customers.hbs +5 -2
  6. package/addon/components/widget/customers.js +14 -6
  7. package/addon/components/widget/orders.hbs +30 -9
  8. package/addon/components/widget/orders.js +7 -1
  9. package/addon/components/widget/storefront-key-metrics.js +2 -2
  10. package/addon/components/widget/storefront-metrics.hbs +11 -1
  11. package/addon/components/widget/storefront-metrics.js +103 -1
  12. package/addon/controllers/networks/index/network/index.js +2 -0
  13. package/addon/controllers/networks/index/network/stores.js +0 -1
  14. package/addon/controllers/settings/gateways.js +6 -1
  15. package/addon/controllers/settings/index.js +1 -0
  16. package/addon/controllers/settings/notifications.js +3 -5
  17. package/addon/models/network.js +1 -0
  18. package/addon/models/store.js +1 -0
  19. package/addon/routes/networks/index/network/index.js +5 -0
  20. package/addon/routes/settings/index.js +5 -0
  21. package/addon/services/order-actions.js +31 -0
  22. package/addon/styles/storefront-engine.css +22 -0
  23. package/addon/templates/networks/index/network/index.hbs +13 -0
  24. package/addon/templates/networks/index/network/stores.hbs +8 -1
  25. package/addon/templates/settings/gateways.hbs +15 -4
  26. package/addon/templates/settings/index.hbs +13 -0
  27. package/addon/templates/settings/notifications.hbs +2 -2
  28. package/addon/utils/commerce-date-ranges.js +263 -0
  29. package/app/utils/commerce-date-ranges.js +1 -0
  30. package/composer.json +1 -1
  31. package/extension.json +1 -1
  32. package/package.json +1 -1
  33. package/server/migrations/2025_09_01_041353_add_default_order_config_column.php +110 -0
  34. package/server/src/Console/Commands/MigrateStripeSandboxCustomers.php +150 -0
  35. package/server/src/Expansions/OrderExpansion.php +43 -0
  36. package/server/src/Http/Controllers/NetworkController.php +1 -1
  37. package/server/src/Http/Controllers/OrderController.php +62 -9
  38. package/server/src/Http/Controllers/v1/CheckoutController.php +45 -48
  39. package/server/src/Http/Controllers/v1/ServiceQuoteController.php +19 -3
  40. package/server/src/Http/Middleware/SetStorefrontSession.php +8 -6
  41. package/server/src/Http/Resources/Customer.php +41 -17
  42. package/server/src/Http/Resources/Gateway.php +16 -11
  43. package/server/src/Http/Resources/Network.php +35 -34
  44. package/server/src/Http/Resources/NotificationChannel.php +17 -10
  45. package/server/src/Http/Resources/Store.php +36 -35
  46. package/server/src/Models/Customer.php +18 -2
  47. package/server/src/Models/FoodTruck.php +15 -0
  48. package/server/src/Models/Network.php +63 -1
  49. package/server/src/Models/Store.php +71 -9
  50. package/server/src/Notifications/StorefrontOrderAccepted.php +154 -0
  51. package/server/src/Observers/OrderObserver.php +6 -4
  52. package/server/src/Providers/StorefrontServiceProvider.php +1 -0
  53. package/server/src/Rules/IsValidLocation.php +12 -0
  54. package/server/src/Support/PushNotification.php +13 -4
  55. package/server/src/Support/Storefront.php +199 -37
  56. package/server/src/routes.php +1 -0
  57. package/translations/en-us.yaml +5 -0
@@ -0,0 +1,43 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\Storefront\Expansions;
4
+
5
+ use Fleetbase\Build\Expansion;
6
+ use Fleetbase\FleetOps\Models\Order;
7
+ use Fleetbase\Storefront\Models\Network;
8
+ use Fleetbase\Storefront\Models\Store;
9
+
10
+ class OrderExpansion implements Expansion
11
+ {
12
+ /**
13
+ * Get the target class to expand.
14
+ *
15
+ * @return string|Class
16
+ */
17
+ public static function target()
18
+ {
19
+ return Order::class;
20
+ }
21
+
22
+ /**
23
+ * Get the current storefront for the order created.
24
+ */
25
+ public static function getStorefrontAttribute(): \Closure
26
+ {
27
+ return function (): Store|Network|null {
28
+ /** @var Order $this */
29
+ $storefrontId = $this->getMeta('storefront_id');
30
+ $storefrontNetworkId = $this->getMeta('storefront_network_id');
31
+
32
+ if ($storefrontId) {
33
+ return Store::where('public_id', $storefrontId)->first();
34
+ }
35
+
36
+ if ($storefrontNetworkId) {
37
+ return Network::where('public_id', $storefrontNetworkId)->first();
38
+ }
39
+
40
+ return null;
41
+ };
42
+ }
43
+ }
@@ -121,7 +121,7 @@ class NetworkController extends StorefrontController
121
121
  }
122
122
 
123
123
  /**
124
- * Add a store to a network category
124
+ * Add a store to a network category.
125
125
  *
126
126
  * @return \Illuminate\Http\Response
127
127
  */
@@ -4,9 +4,10 @@ namespace Fleetbase\Storefront\Http\Controllers;
4
4
 
5
5
  use Fleetbase\FleetOps\Http\Controllers\Internal\v1\OrderController as FleetbaseOrderController;
6
6
  use Fleetbase\FleetOps\Models\Order;
7
- use Fleetbase\Storefront\Notifications\StorefrontOrderPreparing;
7
+ use Fleetbase\Storefront\Notifications\StorefrontOrderAccepted;
8
8
  use Fleetbase\Storefront\Support\Storefront;
9
9
  use Illuminate\Http\Request;
10
+ use Illuminate\Support\Facades\Log;
10
11
 
11
12
  class OrderController extends FleetbaseOrderController
12
13
  {
@@ -40,11 +41,29 @@ class OrderController extends FleetbaseOrderController
40
41
  }
41
42
 
42
43
  // Patch order config
43
- Storefront::patchOrderConfig($order);
44
+ $orderConfig = Storefront::patchOrderConfig($order);
45
+ $activity = Storefront::createAcceptedActivity($orderConfig);
44
46
 
45
- // update activity to prepating
46
- $order->updateStatus('preparing');
47
- $order->customer->notify(new StorefrontOrderPreparing($order));
47
+ // Dispatch already if order is a pickup
48
+ if ($order->isMeta('is_pickup')) {
49
+ $order->firstDispatchWithActivity();
50
+ }
51
+
52
+ // Set order as accepted
53
+ try {
54
+ $order->setStatus($activity->code);
55
+ $order->insertActivity($activity, $order->getLastLocation());
56
+ } catch (\Exception $e) {
57
+ Log::debug('[Storefront] was unable to accept an order.', ['order' => $order, 'activity' => $activity]);
58
+
59
+ return response()->error('Unable to accept order.');
60
+ }
61
+
62
+ // Notify customer order was accepted
63
+ try {
64
+ $order->customer->notify(new StorefrontOrderAccepted($order));
65
+ } catch (\Exception $e) {
66
+ }
48
67
 
49
68
  return response()->json([
50
69
  'status' => 'ok',
@@ -66,9 +85,7 @@ class OrderController extends FleetbaseOrderController
66
85
  $order = Order::where('uuid', $request->order)->whereNull('deleted_at')->with(['customer'])->first();
67
86
 
68
87
  if (!$order) {
69
- return response()->json([
70
- 'error' => 'No order to update!',
71
- ], 400);
88
+ return response()->error('No order to update!');
72
89
  }
73
90
 
74
91
  // Patch order config
@@ -95,7 +112,7 @@ class OrderController extends FleetbaseOrderController
95
112
  }
96
113
 
97
114
  // update activity to dispatched
98
- $order->updateStatus('dispatched');
115
+ $order->dispatchWithActivity();
99
116
 
100
117
  return response()->json([
101
118
  'status' => 'ok',
@@ -109,6 +126,42 @@ class OrderController extends FleetbaseOrderController
109
126
  *
110
127
  * @return \Illuminate\Http\Response
111
128
  */
129
+ public function markOrderAsPreparing(Request $request)
130
+ {
131
+ /** @var Order $order */
132
+ $order = Order::where('uuid', $request->order)->whereNull('deleted_at')->with(['customer'])->first();
133
+
134
+ if (!$order) {
135
+ return response()->error('No order to update!');
136
+ }
137
+
138
+ // Patch order config
139
+ $orderConfig = Storefront::patchOrderConfig($order);
140
+
141
+ // Get preparing activity
142
+ $activity = $orderConfig->getActivityByCode('preparing');
143
+
144
+ try {
145
+ $order->setStatus($activity->code);
146
+ $order->insertActivity($activity, $order->getLastLocation());
147
+ } catch (\Exception $e) {
148
+ Log::debug('[Storefront] was unable to trigger order preparing.', ['order' => $order, 'activity' => $activity]);
149
+
150
+ return response()->error('Unable to trigger order preparing.');
151
+ }
152
+
153
+ return response()->json([
154
+ 'status' => 'ok',
155
+ 'order' => $order->public_id,
156
+ 'status' => $order->status,
157
+ ]);
158
+ }
159
+
160
+ /**
161
+ * Accept an order by incrementing status to completed.
162
+ *
163
+ * @return \Illuminate\Http\Response
164
+ */
112
165
  public function markOrderAsCompleted(Request $request)
113
166
  {
114
167
  /** @var Order */
@@ -24,7 +24,6 @@ use Fleetbase\Storefront\Models\Gateway;
24
24
  use Fleetbase\Storefront\Models\Product;
25
25
  use Fleetbase\Storefront\Models\Store;
26
26
  use Fleetbase\Storefront\Models\StoreLocation;
27
- use Fleetbase\Storefront\Notifications\StorefrontOrderPreparing;
28
27
  use Fleetbase\Storefront\Support\QPay;
29
28
  use Fleetbase\Storefront\Support\Storefront;
30
29
  use Fleetbase\Storefront\Support\StripeUtils;
@@ -686,9 +685,7 @@ class CheckoutController extends Controller
686
685
 
687
686
  // if cart is null then cart has either been deleted or expired
688
687
  if (!$cart) {
689
- return response()->json([
690
- 'error' => 'Cart expired',
691
- ], 400);
688
+ return response()->apiError('Cart expired');
692
689
  }
693
690
 
694
691
  // $amount = $checkout->amount ?? ($checkout->is_pickup ? $cart->subtotal : $cart->subtotal + $serviceQuote->amount);
@@ -815,10 +812,15 @@ class CheckoutController extends Controller
815
812
  ->unique()
816
813
  ->filter()
817
814
  ->map(function ($foodTruckId) {
818
- return FoodTruck::where('public_id', $foodTruckId)->first();
815
+ return FoodTruck::where('public_id', $foodTruckId)->with(['zone', 'serviceArea'])->first();
819
816
  })
820
817
  ->first();
821
818
 
819
+ // Set food truck vehicle location as origin
820
+ if ($foodTruck && $foodTruck->vehicle) {
821
+ $origin = ['name' => $foodTruck->name, 'street1' => data_get($foodTruck, 'zone.name'), 'city' => data_get($foodTruck, 'serviceArea.name'), 'country' => data_get($foodTruck, 'serviceArea.country'), 'location' => $foodTruck->vehicle->location];
822
+ }
823
+
822
824
  // if there is no origin attempt to get from cart
823
825
  if (!$origin) {
824
826
  $storeLocation = collect($cart->items)->map(function ($cartItem) {
@@ -888,7 +890,7 @@ class CheckoutController extends Controller
888
890
  $orderMeta = array_merge($orderMeta, [
889
891
  'checkout_id' => $checkout->public_id,
890
892
  'subtotal' => Utils::numbersOnly($cart->subtotal),
891
- 'delivery_fee' => $checkout->is_pickip ? 0 : Utils::numbersOnly($serviceQuote->amount),
893
+ 'delivery_fee' => $checkout->is_pickup ? 0 : Utils::numbersOnly($serviceQuote->amount),
892
894
  'tip' => $checkout->getOption('tip'),
893
895
  'delivery_tip' => $checkout->getOption('delivery_tip'),
894
896
  'total' => Utils::numbersOnly($amount),
@@ -906,16 +908,17 @@ class CheckoutController extends Controller
906
908
 
907
909
  // initialize order creation input
908
910
  $orderInput = [
909
- 'company_uuid' => $store->company_uuid ?? session('company'),
910
- 'payload_uuid' => $payload->uuid,
911
- 'customer_uuid' => $customer->uuid,
912
- 'customer_type' => Utils::getMutationType('fleet-ops:contact'),
913
- 'transaction_uuid' => $transaction->uuid,
914
- 'adhoc' => $about->isOption('auto_dispatch'),
915
- 'type' => 'storefront',
916
- 'status' => 'created',
917
- 'meta' => $orderMeta,
918
- 'notes' => $notes,
911
+ 'company_uuid' => $store->company_uuid ?? session('company'),
912
+ 'payload_uuid' => $payload->uuid,
913
+ 'customer_uuid' => $customer->uuid,
914
+ 'customer_type' => Utils::getMutationType('fleet-ops:contact'),
915
+ 'transaction_uuid' => $transaction->uuid,
916
+ 'order_config_uuid' => $about->getOrderConfigId(),
917
+ 'adhoc' => $about->isOption('auto_dispatch'),
918
+ 'type' => 'storefront',
919
+ 'status' => 'created',
920
+ 'meta' => $orderMeta,
921
+ 'notes' => $notes,
919
922
  ];
920
923
 
921
924
  // if it's integrated vendor order apply to meta
@@ -939,15 +942,11 @@ class CheckoutController extends Controller
939
942
  }
940
943
 
941
944
  // if order is auto accepted update status
942
- if ($about->isOption('auto_accept_orders')) {
943
- if ($about->isOption('auto_dispatch')) {
944
- $order->updateStatus(['preparing', 'dispatched']);
945
- } else {
946
- $order->updateStatus('preparing');
945
+ if ($store->isOption('auto_accept_orders')) {
946
+ Storefront::autoAcceptOrder($order);
947
+ if ($store->isOption('auto_dispatch')) {
948
+ Storefront::autoDispatchOrder($order);
947
949
  }
948
-
949
- // notify customer order is preparing
950
- $customer->notify(new StorefrontOrderPreparing($order));
951
950
  }
952
951
 
953
952
  // update the cart with the checkout
@@ -1136,15 +1135,16 @@ class CheckoutController extends Controller
1136
1135
 
1137
1136
  // prepare order input
1138
1137
  $orderInput = [
1139
- 'company_uuid' => $store->company_uuid,
1140
- 'payload_uuid' => $payload->uuid,
1141
- 'customer_uuid' => $customer->uuid,
1142
- 'customer_type' => Utils::getMutationType('fleet-ops:contact'),
1143
- 'transaction_uuid' => $transaction->uuid,
1144
- 'adhoc' => $about->isOption('auto_dispatch'),
1145
- 'type' => 'storefront',
1146
- 'status' => 'created',
1147
- 'notes' => $notes,
1138
+ 'company_uuid' => $store->company_uuid,
1139
+ 'payload_uuid' => $payload->uuid,
1140
+ 'customer_uuid' => $customer->uuid,
1141
+ 'customer_type' => Utils::getMutationType('fleet-ops:contact'),
1142
+ 'transaction_uuid' => $transaction->uuid,
1143
+ 'order_config_uuid' => $store->getOrderConfigId(),
1144
+ 'adhoc' => $about->isOption('auto_dispatch'),
1145
+ 'type' => 'storefront',
1146
+ 'status' => 'created',
1147
+ 'notes' => $notes,
1148
1148
  ];
1149
1149
 
1150
1150
  // if it's integrated vendor order apply to meta
@@ -1173,14 +1173,10 @@ class CheckoutController extends Controller
1173
1173
 
1174
1174
  // if order is auto accepted update status
1175
1175
  if ($store->isOption('auto_accept_orders')) {
1176
+ Storefront::autoAcceptOrder($order);
1176
1177
  if ($store->isOption('auto_dispatch')) {
1177
- $order->updateStatus(['preparing', 'dispatched']);
1178
- } else {
1179
- $order->updateStatus('preparing');
1178
+ Storefront::autoDispatchOrder($order);
1180
1179
  }
1181
-
1182
- // notify customer order is preparing
1183
- $customer->notify(new StorefrontOrderPreparing($order));
1184
1180
  }
1185
1181
  }
1186
1182
 
@@ -1212,7 +1208,7 @@ class CheckoutController extends Controller
1212
1208
  'storefront_network_id' => $about->public_id,
1213
1209
  'checkout_id' => $checkout->public_id,
1214
1210
  'subtotal' => Utils::numbersOnly($cart->subtotal),
1215
- 'delivery_fee' => $checkout->is_pickip ? 0 : Utils::numbersOnly($serviceQuote->amount),
1211
+ 'delivery_fee' => $checkout->is_pickup ? 0 : Utils::numbersOnly($serviceQuote->amount),
1216
1212
  'tip' => $checkout->getOption('tip'),
1217
1213
  'delivery_tip' => $checkout->getOption('delivery_tip'),
1218
1214
  'total' => Utils::numbersOnly($amount),
@@ -1225,14 +1221,15 @@ class CheckoutController extends Controller
1225
1221
 
1226
1222
  // prepare master order input
1227
1223
  $masterOrderInput = [
1228
- 'company_uuid' => session('company'),
1229
- 'payload_uuid' => $payload->uuid,
1230
- 'customer_uuid' => $customer->uuid,
1231
- 'customer_type' => Utils::getMutationType('fleet-ops:contact'),
1232
- 'transaction_uuid' => $transaction->uuid,
1233
- 'adhoc' => $about->isOption('auto_dispatch'),
1234
- 'type' => 'storefront',
1235
- 'status' => 'created',
1224
+ 'company_uuid' => session('company'),
1225
+ 'payload_uuid' => $payload->uuid,
1226
+ 'customer_uuid' => $customer->uuid,
1227
+ 'customer_type' => Utils::getMutationType('fleet-ops:contact'),
1228
+ 'transaction_uuid' => $transaction->uuid,
1229
+ 'order_config_uuid' => $about->getOrderConfigId(),
1230
+ 'adhoc' => $about->isOption('auto_dispatch'),
1231
+ 'type' => 'storefront',
1232
+ 'status' => 'created',
1236
1233
  ];
1237
1234
 
1238
1235
  // if it's integrated vendor order apply to meta
@@ -10,10 +10,12 @@ use Fleetbase\FleetOps\Models\Place;
10
10
  use Fleetbase\FleetOps\Models\ServiceQuote;
11
11
  use Fleetbase\FleetOps\Models\ServiceQuoteItem;
12
12
  use Fleetbase\FleetOps\Models\ServiceRate;
13
+ use Fleetbase\FleetOps\Models\Vehicle;
13
14
  use Fleetbase\FleetOps\Support\Utils;
14
15
  use Fleetbase\Http\Controllers\Controller;
15
16
  use Fleetbase\Storefront\Http\Requests\GetServiceQuoteFromCart;
16
17
  use Fleetbase\Storefront\Models\Cart;
18
+ use Fleetbase\Storefront\Models\FoodTruck;
17
19
  use Fleetbase\Storefront\Models\Product;
18
20
  use Fleetbase\Storefront\Models\Store;
19
21
  use Fleetbase\Storefront\Models\StoreLocation;
@@ -121,8 +123,8 @@ class ServiceQuoteController extends Controller
121
123
 
122
124
  // set origin and destination in service quote meta
123
125
  $serviceQuote->updateMeta([
124
- 'origin' => $origin->public_id,
125
- 'destination' => $destination->public_id,
126
+ 'origin' => $origin->public_id ?? $request->input('origin'),
127
+ 'destination' => $destination->public_id ?? $request->input('destination'),
126
128
  ]);
127
129
 
128
130
  return new ServiceQuoteResource($serviceQuote);
@@ -392,8 +394,22 @@ class ServiceQuoteController extends Controller
392
394
  return Place::where(['public_id' => $id, 'company_uuid' => session('company')])->first();
393
395
  }
394
396
 
397
+ // If vehicle
398
+ if (Str::startsWith($id, 'vehicle_')) {
399
+ $vehicle = Vehicle::where('public_id', $id)->first();
400
+
401
+ return Place::createFromCoordinates($vehicle->location);
402
+ }
403
+
404
+ // If food truck
405
+ if (Str::startsWith($id, 'food_truck_')) {
406
+ $foodTruck = FoodTruck::where('public_id', $id)->with('vehicle')->first();
407
+
408
+ return $foodTruck->vehicle ? Place::createFromCoordinates($foodTruck->vehicle->location) : null;
409
+ }
410
+
395
411
  // handle coordinates tooo!
396
- if (!Str::startsWith($id, ['place_', 'store_location']) && Utils::isCoordinates($id)) {
412
+ if (Utils::isCoordinates($id)) {
397
413
  $point = Utils::getPointFromCoordinates($id);
398
414
  $place = Place::createFromCoordinates($point, ['company_uuid' => session('company')], true);
399
415
 
@@ -59,17 +59,19 @@ class SetStorefrontSession
59
59
  $store = Store::select(['uuid', 'company_uuid', 'currency'])->where('key', $key)->first();
60
60
 
61
61
  if ($store) {
62
- $session['storefront_store'] = $store->uuid;
63
- $session['storefront_currency'] = $store->currency;
64
- $session['company'] = $store->company_uuid;
62
+ $session['storefront_store'] = $store->uuid;
63
+ $session['storefront_store_public_id'] = $store->public_id;
64
+ $session['storefront_currency'] = $store->currency;
65
+ $session['company'] = $store->company_uuid;
65
66
  }
66
67
  } elseif (Str::startsWith($key, 'network')) {
67
68
  $network = Network::select(['uuid', 'company_uuid', 'currency'])->where('key', $key)->first();
68
69
 
69
70
  if ($network) {
70
- $session['storefront_network'] = $network->uuid;
71
- $session['storefront_currency'] = $network->currency;
72
- $session['company'] = $network->company_uuid;
71
+ $session['storefront_network'] = $network->uuid;
72
+ $session['storefront_network_public_id'] = $network->public_id;
73
+ $session['storefront_currency'] = $network->currency;
74
+ $session['company'] = $network->company_uuid;
73
75
  }
74
76
  }
75
77
 
@@ -3,9 +3,11 @@
3
3
  namespace Fleetbase\Storefront\Http\Resources;
4
4
 
5
5
  use Fleetbase\FleetOps\Http\Resources\v1\Place;
6
+ use Fleetbase\FleetOps\Models\Order;
6
7
  use Fleetbase\Http\Resources\FleetbaseResource;
7
8
  use Fleetbase\Support\Http;
8
9
  use Fleetbase\Support\Utils;
10
+ use Illuminate\Http\Request;
9
11
  use Illuminate\Support\Str;
10
12
 
11
13
  class Customer extends FleetbaseResource
@@ -13,7 +15,7 @@ class Customer extends FleetbaseResource
13
15
  /**
14
16
  * Transform the resource into an array.
15
17
  *
16
- * @param \Illuminate\Http\Request $request
18
+ * @param Request $request
17
19
  *
18
20
  * @return array
19
21
  */
@@ -22,22 +24,44 @@ class Customer extends FleetbaseResource
22
24
  $this->loadMissing(['place', 'places']);
23
25
 
24
26
  return [
25
- 'id' => $this->when(Http::isInternalRequest(), $this->id, Str::replaceFirst('contact', 'customer', $this->public_id)),
26
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
27
- 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
28
- 'address_id' => $this->place ? $this->place->public_id : null,
29
- 'internal_id' => $this->internal_id,
30
- 'name' => $this->name,
31
- 'photo_url' => $this->photo_url,
32
- 'email' => $this->email,
33
- 'phone' => $this->phone,
34
- 'address' => data_get($this, 'place.address'),
35
- 'addresses' => $this->whenLoaded('places', Place::collection($this->places)),
36
- 'token' => $this->when($this->token, $this->token),
37
- 'meta' => data_get($this, 'meta', Utils::createObject()),
38
- 'slug' => $this->slug,
39
- 'created_at' => $this->created_at,
40
- 'updated_at' => $this->updated_at,
27
+ 'id' => $this->when(Http::isInternalRequest(), $this->id, Str::replaceFirst('contact', 'customer', $this->public_id)),
28
+ 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
29
+ 'user_uuid' => $this->when(Http::isInternalRequest(), $this->user_uuid),
30
+ 'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
31
+ 'place_uuid' => $this->when(Http::isInternalRequest(), $this->place_uuid),
32
+ 'photo_uuid' => $this->when(Http::isInternalRequest(), $this->photo_uuid),
33
+ 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
34
+ 'address_id' => $this->place ? $this->place->public_id : null,
35
+ 'internal_id' => $this->internal_id,
36
+ 'name' => $this->name,
37
+ 'title' => $this->title,
38
+ 'photo_url' => $this->photo_url,
39
+ 'email' => $this->email,
40
+ 'phone' => $this->phone,
41
+ 'address' => data_get($this, 'place.address'),
42
+ 'addresses' => $this->whenLoaded('places', Place::collection($this->places)),
43
+ 'token' => $this->when($this->token, $this->token),
44
+ 'orders' => $this->getCustomerOrderCount($request),
45
+ 'meta' => data_get($this, 'meta', Utils::createObject()),
46
+ 'slug' => $this->slug,
47
+ 'created_at' => $this->created_at,
48
+ 'updated_at' => $this->updated_at,
41
49
  ];
42
50
  }
51
+
52
+ private function getCustomerOrderCount(Request $request): int
53
+ {
54
+ $storeId = $request->input('storefront') ?? $request->session()->get('storefront_id');
55
+ $networkId = $request->input('network') ?? $request->session()->get('network_id');
56
+
57
+ if ($storeId) {
58
+ return Order::where(['customer_uuid' => $this->uuid, 'meta->storefront_id' => $storeId])->count();
59
+ }
60
+
61
+ if ($networkId) {
62
+ return Order::where(['customer_uuid' => $this->uuid, 'meta->storefront_network_id' => $networkId])->count();
63
+ }
64
+
65
+ return 0;
66
+ }
43
67
  }
@@ -17,17 +17,22 @@ class Gateway extends FleetbaseResource
17
17
  public function toArray($request)
18
18
  {
19
19
  return [
20
- 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
21
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
22
- 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
23
- 'name' => $this->name,
24
- 'description' => $this->description,
25
- 'logo_url' => $this->logo_url,
26
- 'code' => $this->code,
27
- 'type' => $this->type,
28
- 'sandbox' => $this->sandbox,
29
- 'return_url' => $this->return_url,
30
- 'callback_url' => $this->callback_url,
20
+ 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
21
+ 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
22
+ 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
23
+ 'owner_uuid' => $this->when(Http::isInternalRequest(), $this->owner_uuid),
24
+ 'name' => $this->name,
25
+ 'description' => $this->description,
26
+ 'logo_url' => $this->logo_url,
27
+ 'code' => $this->code,
28
+ 'type' => $this->type,
29
+ 'sandbox' => $this->sandbox,
30
+ 'return_url' => $this->return_url,
31
+ 'callback_url' => $this->callback_url,
32
+ 'meta' => $this->meta,
33
+ 'config' => $this->when(Http::isInternalRequest(), $this->config),
34
+ 'updated_at' => $this->updated_at,
35
+ 'created_at' => $this->created_at,
31
36
  ];
32
37
  }
33
38
  }
@@ -17,40 +17,41 @@ class Network extends FleetbaseResource
17
17
  public function toArray($request)
18
18
  {
19
19
  return [
20
- 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
21
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
22
- 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
23
- 'key' => $this->when(Http::isInternalRequest(), $this->key),
24
- 'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
25
- 'created_by_uuid' => $this->when(Http::isInternalRequest(), $this->created_by_uuid),
26
- 'logo_uuid' => $this->when(Http::isInternalRequest(), $this->logo_uuid),
27
- 'backdrop_uuid' => $this->when(Http::isInternalRequest(), $this->backdrop_uuid),
28
- 'name' => $this->name,
29
- 'description' => $this->description,
30
- 'translations' => $this->translations ?? [],
31
- 'website' => $this->website,
32
- 'facebook' => $this->facebook,
33
- 'instagram' => $this->instagram,
34
- 'twitter' => $this->twitter,
35
- 'email' => $this->email,
36
- 'phone' => $this->phone,
37
- 'tags' => $this->tags ?? [],
38
- 'currency' => $this->currency ?? 'USD',
39
- 'options' => $this->options ?? [],
40
- 'alertable' => $this->alertable,
41
- 'logo_url' => $this->logo_url,
42
- 'backdrop_url' => $this->backdrop_url,
43
- 'rating' => $this->rating,
44
- 'online' => $this->online,
45
- 'stores' => $this->when($request->boolean('with_stores') || $request->inArray('with', 'stores'), Store::collection($this->stores)),
46
- 'categories' => $this->when($request->boolean('with_categories') || $request->inArray('with', 'categories'), Category::collection($this->categories)),
47
- 'gateways' => $this->when($request->boolean('with_gateways') || $request->inArray('with', 'gateways'), Gateway::collection($this->gateways)),
48
- 'notification_channels' => $this->when($request->boolean('with_notification_channels') || $request->inArray('with', 'notification_channels'), NotificationChannel::collection($this->notificationChannels)),
49
- 'is_network' => true,
50
- 'is_store' => false,
51
- 'slug' => $this->slug,
52
- 'created_at' => $this->created_at,
53
- 'updated_at' => $this->updated_at,
20
+ 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
21
+ 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
22
+ 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
23
+ 'key' => $this->when(Http::isInternalRequest(), $this->key),
24
+ 'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
25
+ 'created_by_uuid' => $this->when(Http::isInternalRequest(), $this->created_by_uuid),
26
+ 'logo_uuid' => $this->when(Http::isInternalRequest(), $this->logo_uuid),
27
+ 'backdrop_uuid' => $this->when(Http::isInternalRequest(), $this->backdrop_uuid),
28
+ 'order_config_uuid' => $this->when(Http::isInternalRequest(), $this->order_config_uuid),
29
+ 'name' => $this->name,
30
+ 'description' => $this->description,
31
+ 'translations' => $this->translations ?? [],
32
+ 'website' => $this->website,
33
+ 'facebook' => $this->facebook,
34
+ 'instagram' => $this->instagram,
35
+ 'twitter' => $this->twitter,
36
+ 'email' => $this->email,
37
+ 'phone' => $this->phone,
38
+ 'tags' => $this->tags ?? [],
39
+ 'currency' => $this->currency ?? 'USD',
40
+ 'options' => $this->options ?? [],
41
+ 'alertable' => $this->alertable,
42
+ 'logo_url' => $this->logo_url,
43
+ 'backdrop_url' => $this->backdrop_url,
44
+ 'rating' => $this->rating,
45
+ 'online' => $this->online,
46
+ 'stores' => $this->when($request->boolean('with_stores') || $request->inArray('with', 'stores'), Store::collection($this->stores)),
47
+ 'categories' => $this->when($request->boolean('with_categories') || $request->inArray('with', 'categories'), Category::collection($this->categories)),
48
+ 'gateways' => $this->when($request->boolean('with_gateways') || $request->inArray('with', 'gateways'), Gateway::collection($this->gateways)),
49
+ 'notification_channels' => $this->when($request->boolean('with_notification_channels') || $request->inArray('with', 'notification_channels'), NotificationChannel::collection($this->notificationChannels)),
50
+ 'is_network' => true,
51
+ 'is_store' => false,
52
+ 'slug' => $this->slug,
53
+ 'created_at' => $this->created_at,
54
+ 'updated_at' => $this->updated_at,
54
55
  ];
55
56
  }
56
57
  }