@fleetbase/storefront-engine 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon/components/customer-panel/orders.hbs +2 -2
- package/addon/components/modals/create-gateway.hbs +33 -12
- package/addon/components/network-category-picker.js +1 -1
- package/addon/components/order-panel.hbs +1 -1
- package/addon/components/widget/customers.hbs +5 -2
- package/addon/components/widget/customers.js +14 -6
- package/addon/components/widget/orders.hbs +31 -10
- package/addon/components/widget/orders.js +7 -1
- package/addon/components/widget/storefront-key-metrics.js +2 -2
- package/addon/components/widget/storefront-metrics.hbs +11 -1
- package/addon/components/widget/storefront-metrics.js +103 -1
- package/addon/controllers/networks/index/network/index.js +2 -0
- package/addon/controllers/networks/index/network/stores.js +0 -1
- package/addon/controllers/products/index/category/new.js +13 -2
- package/addon/controllers/settings/gateways.js +6 -1
- package/addon/controllers/settings/index.js +1 -0
- package/addon/controllers/settings/notifications.js +4 -5
- package/addon/models/network.js +1 -0
- package/addon/models/store.js +1 -0
- package/addon/routes/networks/index/network/index.js +5 -0
- package/addon/routes/settings/index.js +5 -0
- package/addon/services/order-actions.js +31 -0
- package/addon/styles/storefront-engine.css +22 -0
- package/addon/templates/home.hbs +2 -2
- package/addon/templates/networks/index/network/index.hbs +21 -8
- package/addon/templates/networks/index/network/stores.hbs +8 -1
- package/addon/templates/products/index/category/new.hbs +149 -134
- package/addon/templates/settings/gateways.hbs +15 -4
- package/addon/templates/settings/index.hbs +13 -0
- package/addon/templates/settings/notifications.hbs +2 -2
- package/addon/utils/commerce-date-ranges.js +263 -0
- package/app/utils/commerce-date-ranges.js +1 -0
- package/composer.json +1 -1
- package/extension.json +1 -1
- package/package.json +4 -4
- package/server/migrations/2025_09_01_041353_add_default_order_config_column.php +110 -0
- package/server/src/Console/Commands/MigrateStripeSandboxCustomers.php +165 -0
- package/server/src/Expansions/OrderExpansion.php +43 -0
- package/server/src/Http/Controllers/NetworkController.php +1 -1
- package/server/src/Http/Controllers/OrderController.php +62 -9
- package/server/src/Http/Controllers/v1/CheckoutController.php +57 -48
- package/server/src/Http/Controllers/v1/ServiceQuoteController.php +19 -3
- package/server/src/Http/Middleware/SetStorefrontSession.php +8 -6
- package/server/src/Http/Resources/Customer.php +41 -17
- package/server/src/Http/Resources/Gateway.php +16 -11
- package/server/src/Http/Resources/Network.php +35 -34
- package/server/src/Http/Resources/NotificationChannel.php +17 -10
- package/server/src/Http/Resources/Product.php +1 -0
- package/server/src/Http/Resources/Store.php +36 -35
- package/server/src/Models/Customer.php +18 -2
- package/server/src/Models/FoodTruck.php +29 -2
- package/server/src/Models/Network.php +63 -1
- package/server/src/Models/Store.php +71 -9
- package/server/src/Notifications/StorefrontOrderAccepted.php +164 -0
- package/server/src/Notifications/StorefrontOrderCanceled.php +11 -1
- package/server/src/Notifications/StorefrontOrderCompleted.php +11 -1
- package/server/src/Notifications/StorefrontOrderDriverAssigned.php +12 -4
- package/server/src/Notifications/StorefrontOrderEnroute.php +12 -4
- package/server/src/Notifications/StorefrontOrderNearby.php +12 -4
- package/server/src/Notifications/StorefrontOrderPreparing.php +12 -4
- package/server/src/Notifications/StorefrontOrderReadyForPickup.php +12 -4
- package/server/src/Observers/OrderObserver.php +6 -4
- package/server/src/Providers/StorefrontServiceProvider.php +1 -0
- package/server/src/Rules/IsValidLocation.php +12 -0
- package/server/src/Support/PushNotification.php +20 -4
- package/server/src/Support/Storefront.php +283 -37
- package/server/src/routes.php +1 -0
- package/translations/{ar-ae.yml → ar-ae.yaml} +313 -253
- package/translations/bg-bg.yaml +734 -0
- package/translations/en-us.yaml +5 -0
- package/translations/es-es.yaml +732 -0
- package/translations/fr-fr.yaml +748 -0
- package/translations/mn-mn.yaml +725 -0
- package/translations/pt-br.yaml +732 -0
- package/translations/ru-ru.yaml +726 -0
- package/translations/vi-vn.yaml +412 -338
- package/translations/zh-cn.yaml +659 -0
|
@@ -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\
|
|
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
|
-
//
|
|
46
|
-
$order->
|
|
47
|
-
|
|
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()->
|
|
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->
|
|
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()->
|
|
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->
|
|
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),
|
|
@@ -899,23 +901,33 @@ class CheckoutController extends Controller
|
|
|
899
901
|
...$transactionDetails,
|
|
900
902
|
]);
|
|
901
903
|
|
|
904
|
+
// Create order input here
|
|
905
|
+
$orderInput = [];
|
|
906
|
+
|
|
902
907
|
// if there is a food truck include it in the order meta
|
|
903
908
|
if ($foodTruck) {
|
|
904
909
|
$orderMeta['food_truck_id'] = $foodTruck->public_id;
|
|
910
|
+
// assign the driver to the food truck driver
|
|
911
|
+
$driverAssigned = $foodTruck->getDriverAssigned();
|
|
912
|
+
if ($driverAssigned) {
|
|
913
|
+
$orderInput['driver_assigned_uuid'] = $driverAssigned->uuid;
|
|
914
|
+
}
|
|
905
915
|
}
|
|
906
916
|
|
|
907
917
|
// initialize order creation input
|
|
908
918
|
$orderInput = [
|
|
909
|
-
|
|
910
|
-
'
|
|
911
|
-
'
|
|
912
|
-
'
|
|
913
|
-
'
|
|
914
|
-
'
|
|
915
|
-
'
|
|
916
|
-
'
|
|
917
|
-
'
|
|
918
|
-
'
|
|
919
|
+
...$orderInput,
|
|
920
|
+
'company_uuid' => $store->company_uuid ?? session('company'),
|
|
921
|
+
'payload_uuid' => $payload->uuid,
|
|
922
|
+
'customer_uuid' => $customer->uuid,
|
|
923
|
+
'customer_type' => Utils::getMutationType('fleet-ops:contact'),
|
|
924
|
+
'transaction_uuid' => $transaction->uuid,
|
|
925
|
+
'order_config_uuid' => $about->getOrderConfigId(),
|
|
926
|
+
'adhoc' => $about->isOption('auto_dispatch'),
|
|
927
|
+
'type' => 'storefront',
|
|
928
|
+
'status' => 'created',
|
|
929
|
+
'meta' => $orderMeta,
|
|
930
|
+
'notes' => $notes,
|
|
919
931
|
];
|
|
920
932
|
|
|
921
933
|
// if it's integrated vendor order apply to meta
|
|
@@ -930,6 +942,9 @@ class CheckoutController extends Controller
|
|
|
930
942
|
// create order
|
|
931
943
|
$order = Order::create($orderInput);
|
|
932
944
|
|
|
945
|
+
// notify driver if assigned
|
|
946
|
+
$order->notifyDriverAssigned();
|
|
947
|
+
|
|
933
948
|
// notify order creation
|
|
934
949
|
Storefront::alertNewOrder($order);
|
|
935
950
|
|
|
@@ -939,15 +954,11 @@ class CheckoutController extends Controller
|
|
|
939
954
|
}
|
|
940
955
|
|
|
941
956
|
// if order is auto accepted update status
|
|
942
|
-
if ($
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
$order->updateStatus('preparing');
|
|
957
|
+
if ($store->isOption('auto_accept_orders')) {
|
|
958
|
+
Storefront::autoAcceptOrder($order);
|
|
959
|
+
if ($store->isOption('auto_dispatch')) {
|
|
960
|
+
Storefront::autoDispatchOrder($order);
|
|
947
961
|
}
|
|
948
|
-
|
|
949
|
-
// notify customer order is preparing
|
|
950
|
-
$customer->notify(new StorefrontOrderPreparing($order));
|
|
951
962
|
}
|
|
952
963
|
|
|
953
964
|
// update the cart with the checkout
|
|
@@ -1136,15 +1147,16 @@ class CheckoutController extends Controller
|
|
|
1136
1147
|
|
|
1137
1148
|
// prepare order input
|
|
1138
1149
|
$orderInput = [
|
|
1139
|
-
'company_uuid'
|
|
1140
|
-
'payload_uuid'
|
|
1141
|
-
'customer_uuid'
|
|
1142
|
-
'customer_type'
|
|
1143
|
-
'transaction_uuid'
|
|
1144
|
-
'
|
|
1145
|
-
'
|
|
1146
|
-
'
|
|
1147
|
-
'
|
|
1150
|
+
'company_uuid' => $store->company_uuid,
|
|
1151
|
+
'payload_uuid' => $payload->uuid,
|
|
1152
|
+
'customer_uuid' => $customer->uuid,
|
|
1153
|
+
'customer_type' => Utils::getMutationType('fleet-ops:contact'),
|
|
1154
|
+
'transaction_uuid' => $transaction->uuid,
|
|
1155
|
+
'order_config_uuid' => $store->getOrderConfigId(),
|
|
1156
|
+
'adhoc' => $about->isOption('auto_dispatch'),
|
|
1157
|
+
'type' => 'storefront',
|
|
1158
|
+
'status' => 'created',
|
|
1159
|
+
'notes' => $notes,
|
|
1148
1160
|
];
|
|
1149
1161
|
|
|
1150
1162
|
// if it's integrated vendor order apply to meta
|
|
@@ -1173,14 +1185,10 @@ class CheckoutController extends Controller
|
|
|
1173
1185
|
|
|
1174
1186
|
// if order is auto accepted update status
|
|
1175
1187
|
if ($store->isOption('auto_accept_orders')) {
|
|
1188
|
+
Storefront::autoAcceptOrder($order);
|
|
1176
1189
|
if ($store->isOption('auto_dispatch')) {
|
|
1177
|
-
$order
|
|
1178
|
-
} else {
|
|
1179
|
-
$order->updateStatus('preparing');
|
|
1190
|
+
Storefront::autoDispatchOrder($order);
|
|
1180
1191
|
}
|
|
1181
|
-
|
|
1182
|
-
// notify customer order is preparing
|
|
1183
|
-
$customer->notify(new StorefrontOrderPreparing($order));
|
|
1184
1192
|
}
|
|
1185
1193
|
}
|
|
1186
1194
|
|
|
@@ -1212,7 +1220,7 @@ class CheckoutController extends Controller
|
|
|
1212
1220
|
'storefront_network_id' => $about->public_id,
|
|
1213
1221
|
'checkout_id' => $checkout->public_id,
|
|
1214
1222
|
'subtotal' => Utils::numbersOnly($cart->subtotal),
|
|
1215
|
-
'delivery_fee' => $checkout->
|
|
1223
|
+
'delivery_fee' => $checkout->is_pickup ? 0 : Utils::numbersOnly($serviceQuote->amount),
|
|
1216
1224
|
'tip' => $checkout->getOption('tip'),
|
|
1217
1225
|
'delivery_tip' => $checkout->getOption('delivery_tip'),
|
|
1218
1226
|
'total' => Utils::numbersOnly($amount),
|
|
@@ -1225,14 +1233,15 @@ class CheckoutController extends Controller
|
|
|
1225
1233
|
|
|
1226
1234
|
// prepare master order input
|
|
1227
1235
|
$masterOrderInput = [
|
|
1228
|
-
'company_uuid'
|
|
1229
|
-
'payload_uuid'
|
|
1230
|
-
'customer_uuid'
|
|
1231
|
-
'customer_type'
|
|
1232
|
-
'transaction_uuid'
|
|
1233
|
-
'
|
|
1234
|
-
'
|
|
1235
|
-
'
|
|
1236
|
+
'company_uuid' => session('company'),
|
|
1237
|
+
'payload_uuid' => $payload->uuid,
|
|
1238
|
+
'customer_uuid' => $customer->uuid,
|
|
1239
|
+
'customer_type' => Utils::getMutationType('fleet-ops:contact'),
|
|
1240
|
+
'transaction_uuid' => $transaction->uuid,
|
|
1241
|
+
'order_config_uuid' => $about->getOrderConfigId(),
|
|
1242
|
+
'adhoc' => $about->isOption('auto_dispatch'),
|
|
1243
|
+
'type' => 'storefront',
|
|
1244
|
+
'status' => 'created',
|
|
1236
1245
|
];
|
|
1237
1246
|
|
|
1238
1247
|
// 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 (
|
|
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']
|
|
63
|
-
$session['
|
|
64
|
-
$session['
|
|
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']
|
|
71
|
-
$session['
|
|
72
|
-
$session['
|
|
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
|
|
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'
|
|
26
|
-
'uuid'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'
|
|
40
|
-
'
|
|
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'
|
|
21
|
-
'uuid'
|
|
22
|
-
'public_id'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
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'
|
|
21
|
-
'uuid'
|
|
22
|
-
'public_id'
|
|
23
|
-
'key'
|
|
24
|
-
'company_uuid'
|
|
25
|
-
'created_by_uuid'
|
|
26
|
-
'logo_uuid'
|
|
27
|
-
'backdrop_uuid'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'
|
|
40
|
-
'
|
|
41
|
-
'
|
|
42
|
-
'
|
|
43
|
-
'
|
|
44
|
-
'
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'
|
|
53
|
-
'
|
|
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
|
}
|
|
@@ -17,16 +17,23 @@ class NotificationChannel extends FleetbaseResource
|
|
|
17
17
|
public function toArray($request)
|
|
18
18
|
{
|
|
19
19
|
return [
|
|
20
|
-
'id'
|
|
21
|
-
'uuid'
|
|
22
|
-
'public_id'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
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
|
+
'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
|
|
24
|
+
'created_by_uuid' => $this->when(Http::isInternalRequest(), $this->created_by_uuid),
|
|
25
|
+
'certificate_uuid' => $this->when(Http::isInternalRequest(), $this->certificate_uuid),
|
|
26
|
+
'owner_uuid' => $this->when(Http::isInternalRequest(), $this->owner_uuid),
|
|
27
|
+
'owner_type' => $this->when(Http::isInternalRequest(), $this->owner_type),
|
|
28
|
+
'name' => $this->name,
|
|
29
|
+
'scheme' => $this->scheme,
|
|
30
|
+
'options' => $this->options,
|
|
31
|
+
'config' => $this->config,
|
|
32
|
+
'app_key' => $this->app_key,
|
|
33
|
+
'is_apn_gateway' => $this->is_apn_gateway,
|
|
34
|
+
'is_fcm_gateway' => $this->is_fcm_gateway,
|
|
35
|
+
'created_at' => $this->created_at,
|
|
36
|
+
'updated_at' => $this->updated_at,
|
|
30
37
|
];
|
|
31
38
|
}
|
|
32
39
|
}
|
|
@@ -31,6 +31,7 @@ class Product extends FleetbaseResource
|
|
|
31
31
|
'primary_image_uuid' => $this->when(Http::isInternalRequest(), $this->primary_image_uuid),
|
|
32
32
|
'name' => $this->name,
|
|
33
33
|
'description' => $this->description,
|
|
34
|
+
'category' => $this->when(Http::isInternalRequest(), $this->category),
|
|
34
35
|
'sku' => $this->sku,
|
|
35
36
|
'primary_image_url' => $this->primary_image_url,
|
|
36
37
|
'price' => $this->price,
|