@fleetbase/storefront-engine 0.2.5 → 0.2.7

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 (114) hide show
  1. package/addon/controllers/products/index/category/new.js +5 -9
  2. package/addon/models/product-addon-category.js +10 -1
  3. package/addon/models/product-variant.js +0 -2
  4. package/addon/models/product.js +35 -2
  5. package/addon/serializers/product.js +16 -0
  6. package/addon/templates/products/index/category/new.hbs +2 -2
  7. package/composer.json +3 -3
  8. package/extension.json +1 -1
  9. package/package.json +132 -132
  10. package/server/src/Auth/Schemas/Storefront.php +31 -39
  11. package/server/src/Console/Commands/NotifyStorefrontOrderNearby.php +9 -11
  12. package/server/src/Expansions/ContactFilterExpansion.php +1 -1
  13. package/server/src/Expansions/EntityExpansion.php +12 -12
  14. package/server/src/Expansions/OrderFilterExpansion.php +1 -1
  15. package/server/src/Expansions/VendorFilterExpansion.php +1 -1
  16. package/server/src/Http/Controllers/ActionController.php +9 -11
  17. package/server/src/Http/Controllers/AddonCategoryController.php +1 -1
  18. package/server/src/Http/Controllers/CustomerController.php +1 -1
  19. package/server/src/Http/Controllers/GatewayController.php +1 -1
  20. package/server/src/Http/Controllers/MetricsController.php +17 -17
  21. package/server/src/Http/Controllers/NetworkController.php +16 -26
  22. package/server/src/Http/Controllers/NotificationChannelController.php +1 -1
  23. package/server/src/Http/Controllers/OrderController.php +18 -22
  24. package/server/src/Http/Controllers/ProductAddonCategoryController.php +1 -2
  25. package/server/src/Http/Controllers/ProductAddonController.php +1 -2
  26. package/server/src/Http/Controllers/ProductController.php +89 -44
  27. package/server/src/Http/Controllers/ProductHourController.php +1 -1
  28. package/server/src/Http/Controllers/ProductVariantController.php +1 -1
  29. package/server/src/Http/Controllers/ProductVariantOptionController.php +1 -1
  30. package/server/src/Http/Controllers/ReviewController.php +1 -1
  31. package/server/src/Http/Controllers/StoreController.php +1 -2
  32. package/server/src/Http/Controllers/StoreHourController.php +1 -1
  33. package/server/src/Http/Controllers/StoreLocationController.php +1 -1
  34. package/server/src/Http/Controllers/StorefrontController.php +0 -2
  35. package/server/src/Http/Controllers/VoteController.php +1 -1
  36. package/server/src/Http/Controllers/v1/CartController.php +16 -26
  37. package/server/src/Http/Controllers/v1/CategoryController.php +3 -4
  38. package/server/src/Http/Controllers/v1/CheckoutController.php +283 -286
  39. package/server/src/Http/Controllers/v1/CustomerController.php +54 -67
  40. package/server/src/Http/Controllers/v1/GatewayControllerController.php +0 -2
  41. package/server/src/Http/Controllers/v1/NetworkController.php +26 -23
  42. package/server/src/Http/Controllers/v1/PaymentMethodController.php +0 -2
  43. package/server/src/Http/Controllers/v1/ProductController.php +1 -4
  44. package/server/src/Http/Controllers/v1/ReviewController.php +31 -35
  45. package/server/src/Http/Controllers/v1/ServiceQuoteController.php +57 -53
  46. package/server/src/Http/Controllers/v1/StoreController.php +8 -16
  47. package/server/src/Http/Filter/AddonCategoryFilter.php +1 -1
  48. package/server/src/Http/Filter/OrderFilter.php +2 -2
  49. package/server/src/Http/Middleware/SetStorefrontSession.php +9 -20
  50. package/server/src/Http/Requests/AddStoreToNetworkCategory.php +3 -3
  51. package/server/src/Http/Requests/CreateCustomerRequest.php +5 -7
  52. package/server/src/Http/Requests/CreateReviewRequest.php +4 -5
  53. package/server/src/Http/Requests/GetServiceQuoteFromCart.php +2 -2
  54. package/server/src/Http/Requests/InitializeCheckoutRequest.php +5 -5
  55. package/server/src/Http/Requests/NetworkActionRequest.php +2 -2
  56. package/server/src/Http/Requests/VerifyCreateCustomerRequest.php +2 -2
  57. package/server/src/Http/Resources/Cart.php +19 -18
  58. package/server/src/Http/Resources/Category.php +12 -11
  59. package/server/src/Http/Resources/Customer.php +15 -14
  60. package/server/src/Http/Resources/Gateway.php +12 -11
  61. package/server/src/Http/Resources/Media.php +9 -8
  62. package/server/src/Http/Resources/Network.php +32 -31
  63. package/server/src/Http/Resources/Product.php +88 -85
  64. package/server/src/Http/Resources/Review.php +14 -13
  65. package/server/src/Http/Resources/ReviewCustomer.php +12 -11
  66. package/server/src/Http/Resources/Store.php +38 -36
  67. package/server/src/Http/Resources/StoreHour.php +9 -8
  68. package/server/src/Http/Resources/StoreLocation.php +9 -8
  69. package/server/src/Imports/ProductsImport.php +0 -2
  70. package/server/src/Jobs/DownloadProductImageUrl.php +7 -4
  71. package/server/src/Listeners/HandleOrderCompleted.php +2 -1
  72. package/server/src/Listeners/HandleOrderDispatched.php +2 -1
  73. package/server/src/Listeners/HandleOrderDriverAssigned.php +2 -1
  74. package/server/src/Listeners/HandleOrderStarted.php +4 -3
  75. package/server/src/Mail/StorefrontNetworkInvite.php +7 -6
  76. package/server/src/Models/AddonCategory.php +2 -4
  77. package/server/src/Models/Cart.php +117 -124
  78. package/server/src/Models/Checkout.php +14 -12
  79. package/server/src/Models/Customer.php +9 -9
  80. package/server/src/Models/Gateway.php +22 -22
  81. package/server/src/Models/Network.php +41 -52
  82. package/server/src/Models/NetworkStore.php +6 -5
  83. package/server/src/Models/NotificationChannel.php +11 -9
  84. package/server/src/Models/PaymentMethod.php +9 -7
  85. package/server/src/Models/Product.php +152 -30
  86. package/server/src/Models/ProductAddon.php +14 -11
  87. package/server/src/Models/ProductAddonCategory.php +9 -8
  88. package/server/src/Models/ProductHour.php +6 -5
  89. package/server/src/Models/ProductStoreLocation.php +7 -5
  90. package/server/src/Models/ProductVariant.php +15 -11
  91. package/server/src/Models/ProductVariantOption.php +12 -9
  92. package/server/src/Models/Review.php +9 -7
  93. package/server/src/Models/Store.php +68 -84
  94. package/server/src/Models/StoreHour.php +6 -5
  95. package/server/src/Models/StoreLocation.php +12 -8
  96. package/server/src/Models/StorefrontModel.php +1 -1
  97. package/server/src/Models/Vote.php +8 -6
  98. package/server/src/Notifications/StorefrontOrderCanceled.php +15 -19
  99. package/server/src/Notifications/StorefrontOrderCompleted.php +15 -19
  100. package/server/src/Notifications/StorefrontOrderCreated.php +31 -36
  101. package/server/src/Notifications/StorefrontOrderDriverAssigned.php +15 -20
  102. package/server/src/Notifications/StorefrontOrderEnroute.php +14 -19
  103. package/server/src/Notifications/StorefrontOrderNearby.php +16 -21
  104. package/server/src/Notifications/StorefrontOrderPreparing.php +15 -18
  105. package/server/src/Notifications/StorefrontOrderReadyForPickup.php +15 -18
  106. package/server/src/Observers/NetworkObserver.php +2 -3
  107. package/server/src/Observers/ProductObserver.php +17 -33
  108. package/server/src/Providers/EventServiceProvider.php +15 -4
  109. package/server/src/Providers/StorefrontServiceProvider.php +8 -10
  110. package/server/src/Support/Metrics.php +12 -12
  111. package/server/src/Support/OrderConfig.php +3 -2
  112. package/server/src/Support/QPay.php +22 -20
  113. package/server/src/Support/Storefront.php +18 -17
  114. package/server/src/routes.php +1 -1
@@ -2,26 +2,26 @@
2
2
 
3
3
  namespace Fleetbase\Storefront\Models;
4
4
 
5
- use Exception;
6
- use Fleetbase\Casts\Json;
7
- use Fleetbase\Models\Company;
8
5
  use Fleetbase\FleetOps\Models\Contact;
9
6
  use Fleetbase\FleetOps\Support\Utils;
7
+ use Fleetbase\Models\Company;
10
8
  use Fleetbase\Traits\Expirable;
11
- use Fleetbase\Traits\HasUuid;
12
- Use Fleetbase\Traits\HasApiModelBehavior;
9
+ use Fleetbase\Traits\HasApiModelBehavior;
13
10
  use Fleetbase\Traits\HasPublicId;
11
+ use Fleetbase\Traits\HasUuid;
14
12
  use Illuminate\Support\Arr;
15
13
  use Illuminate\Support\Carbon;
16
14
  use Illuminate\Support\Str;
17
- use stdClass;
18
15
 
19
16
  class Cart extends StorefrontModel
20
17
  {
21
- use HasUuid, HasPublicId, HasApiModelBehavior, Expirable;
18
+ use HasUuid;
19
+ use HasPublicId;
20
+ use HasApiModelBehavior;
21
+ use Expirable;
22
22
 
23
23
  /**
24
- * The type of public Id to generate
24
+ * The type of public Id to generate.
25
25
  *
26
26
  * @var string
27
27
  */
@@ -35,7 +35,7 @@ class Cart extends StorefrontModel
35
35
  protected $table = 'carts';
36
36
 
37
37
  /**
38
- * These attributes that can be queried
38
+ * These attributes that can be queried.
39
39
  *
40
40
  * @var array
41
41
  */
@@ -54,11 +54,11 @@ class Cart extends StorefrontModel
54
54
  * @var array
55
55
  */
56
56
  protected $casts = [
57
- 'expires_at' => 'datetime'
57
+ 'expires_at' => 'datetime',
58
58
  ];
59
59
 
60
60
  /**
61
- * Dynamic attributes that are appended to object
61
+ * Dynamic attributes that are appended to object.
62
62
  *
63
63
  * @var array
64
64
  */
@@ -73,7 +73,6 @@ class Cart extends StorefrontModel
73
73
  }
74
74
 
75
75
  /**
76
- *
77
76
  * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
78
77
  */
79
78
  public function user()
@@ -99,7 +98,7 @@ class Cart extends StorefrontModel
99
98
 
100
99
  /**
101
100
  * Set cart items.
102
- *
101
+ *
103
102
  * @return void
104
103
  */
105
104
  public function setItemsAttribute($items)
@@ -109,7 +108,7 @@ class Cart extends StorefrontModel
109
108
 
110
109
  /**
111
110
  * Set cart events.
112
- *
111
+ *
113
112
  * @return void
114
113
  */
115
114
  public function setEventsAttribute($events)
@@ -119,7 +118,7 @@ class Cart extends StorefrontModel
119
118
 
120
119
  /**
121
120
  * Get cart items.
122
- *
121
+ *
123
122
  * @return array
124
123
  */
125
124
  public function getItemsAttribute($items)
@@ -133,7 +132,7 @@ class Cart extends StorefrontModel
133
132
 
134
133
  /**
135
134
  * Get cart events.
136
- *
135
+ *
137
136
  * @return array
138
137
  */
139
138
  public function getEventsAttribute($events)
@@ -152,7 +151,7 @@ class Cart extends StorefrontModel
152
151
  */
153
152
  public function getSubtotalAttribute()
154
153
  {
155
- $items = $this->getAttribute('items') ?? [];
154
+ $items = $this->getAttribute('items') ?? [];
156
155
  $subtotal = 0;
157
156
 
158
157
  foreach ($items as $item) {
@@ -191,8 +190,8 @@ class Cart extends StorefrontModel
191
190
 
192
191
  /**
193
192
  * The last cart event.
194
- *
195
- * @return stdClass|null
193
+ *
194
+ * @return \stdClass|null
196
195
  */
197
196
  public function getLastEventAttribute()
198
197
  {
@@ -202,9 +201,9 @@ class Cart extends StorefrontModel
202
201
  }
203
202
 
204
203
  /**
205
- * If the cart is a multi cart
206
- *
207
- * @return boolean
204
+ * If the cart is a multi cart.
205
+ *
206
+ * @return bool
208
207
  */
209
208
  public function getIsMultiCartAttribute()
210
209
  {
@@ -212,8 +211,8 @@ class Cart extends StorefrontModel
212
211
  }
213
212
 
214
213
  /**
215
- * Returns the checkout store id
216
- *
214
+ * Returns the checkout store id.
215
+ *
217
216
  * @return string
218
217
  */
219
218
  public function getCheckoutStoreIdAttribute()
@@ -222,8 +221,8 @@ class Cart extends StorefrontModel
222
221
  }
223
222
 
224
223
  /**
225
- * Returns the checkout store ids for all stores being checked out from
226
- *
224
+ * Returns the checkout store ids for all stores being checked out from.
225
+ *
227
226
  * @return array
228
227
  */
229
228
  public function getCheckoutStoreIdsAttribute()
@@ -232,8 +231,8 @@ class Cart extends StorefrontModel
232
231
  }
233
232
 
234
233
  /**
235
- * Returns cart items for a specific store only
236
- *
234
+ * Returns cart items for a specific store only.
235
+ *
237
236
  * @return array
238
237
  */
239
238
  public function getItemsForStore($id)
@@ -254,7 +253,7 @@ class Cart extends StorefrontModel
254
253
  */
255
254
  public function getSubtotalForStore($id)
256
255
  {
257
- $items = $this->getItemsForStore($id);
256
+ $items = $this->getItemsForStore($id);
258
257
  $subtotal = 0;
259
258
 
260
259
  foreach ($items as $item) {
@@ -268,12 +267,14 @@ class Cart extends StorefrontModel
268
267
  * Adds item to cart.
269
268
  *
270
269
  * @param Product|string $product
271
- * @param integer $quantity
272
- * @param array $variants
273
- * @param array $addons
274
- * @param string|null $createdAt
275
- * @return stdClass
276
- * @throws Exception
270
+ * @param int $quantity
271
+ * @param array $variants
272
+ * @param array $addons
273
+ * @param string|null $createdAt
274
+ *
275
+ * @return \stdClass
276
+ *
277
+ * @throws \Exception
277
278
  */
278
279
  public function add($product, $quantity = 1, $variants = [], $addons = [], $storeLocationId = null, $scheduledAt = null, $createdAt = null)
279
280
  {
@@ -287,22 +288,22 @@ class Cart extends StorefrontModel
287
288
  return $this->add($product, $quantity, $variants, $addons, $storeLocationId, $scheduledAt, $createdAt);
288
289
  }
289
290
 
290
- throw new Exception('Invalid product provided to cart!');
291
+ throw new \Exception('Invalid product provided to cart!');
291
292
  }
292
293
 
293
294
  /**
294
295
  * Adds an item to cart.
295
- *
296
+ *
296
297
  * @param \Fleetbase\Models\Storefront\Product $product
297
- * @param integer $quantity
298
- * @param array $variants
299
- * @param array $addons
300
- * @param string $createdAt
298
+ * @param int $quantity
299
+ * @param array $variants
300
+ * @param array $addons
301
+ * @param string $createdAt
301
302
  */
302
303
  public function addItem(Product $product, $quantity = 1, $variants = [], $addons = [], $storeLocationId = null, $scheduledAt = null, $createdAt = null)
303
304
  {
304
- $id = Utils::generatePublicId('cart_item');
305
- $cartItem = new stdClass();
305
+ $id = Utils::generatePublicId('cart_item');
306
+ $cartItem = new \stdClass();
306
307
 
307
308
  // set base price
308
309
  $price = Utils::numbersOnly($product->is_on_sale ? $product->sale_price : $product->price);
@@ -310,27 +311,27 @@ class Cart extends StorefrontModel
310
311
  // calculate subtotal
311
312
  $subtotal = static::calculateProductSubtotal($product, $quantity, $variants, $addons);
312
313
 
313
- // if no store location id, default to first store location
314
+ // if no store location id, default to first store location
314
315
  if (empty($storeLocationId)) {
315
316
  $storeLocationId = Utils::get($product, 'store.locations.0.public_id');
316
317
  }
317
318
 
318
319
  $properties = [
319
- 'id' => $id,
320
- 'store_id' => $product->store_id,
320
+ 'id' => $id,
321
+ 'store_id' => $product->store_id,
321
322
  'store_location_id' => $storeLocationId,
322
- 'product_id' => $product->public_id,
323
+ 'product_id' => $product->public_id,
323
324
  'product_image_url' => $product->primary_image_url,
324
- 'name' => $product->name,
325
- 'description' => $product->description,
326
- 'scheduled_at' => $scheduledAt,
327
- 'created_at' => $createdAt ?? time(),
328
- 'updated_at' => time(),
329
- 'quantity' => $quantity,
330
- 'price' => $price,
331
- 'subtotal' => $subtotal,
332
- 'variants' => $variants,
333
- 'addons' => $addons
325
+ 'name' => $product->name,
326
+ 'description' => $product->description,
327
+ 'scheduled_at' => $scheduledAt,
328
+ 'created_at' => $createdAt ?? time(),
329
+ 'updated_at' => time(),
330
+ 'quantity' => $quantity,
331
+ 'price' => $price,
332
+ 'subtotal' => $subtotal,
333
+ 'variants' => $variants,
334
+ 'addons' => $addons,
334
335
  ];
335
336
 
336
337
  foreach ($properties as $prop => $value) {
@@ -351,17 +352,18 @@ class Cart extends StorefrontModel
351
352
  /**
352
353
  * Adds item to cart.
353
354
  *
354
- * @param stdClass|string $cartItem
355
- * @param integer $quantity
356
- * @param array $variants
357
- * @param array $addons
358
- * @param string|null $createdAt
359
- * @return stdClass
360
- * @throws Exception
355
+ * @param \stdClass|string $cartItem
356
+ * @param int $quantity
357
+ * @param array $variants
358
+ * @param array $addons
359
+ *
360
+ * @return \stdClass
361
+ *
362
+ * @throws \Exception
361
363
  */
362
364
  public function updateItem($cartItem, $quantity = 1, $variants = [], $addons = [], $scheduledAt = null)
363
365
  {
364
- if ($cartItem instanceof stdClass) {
366
+ if ($cartItem instanceof \stdClass) {
365
367
  return $this->updateCartItem($cartItem, $quantity, $variants, $addons, $scheduledAt);
366
368
  }
367
369
 
@@ -371,23 +373,24 @@ class Cart extends StorefrontModel
371
373
  return $this->updateItem($cartItem, $quantity, $variants, $addons, $scheduledAt);
372
374
  }
373
375
 
374
- throw new Exception('Invalid cart item provided to cart!');
376
+ throw new \Exception('Invalid cart item provided to cart!');
375
377
  }
376
378
 
377
379
  /**
378
380
  * Updates an item in cart.
379
381
  *
380
382
  * @param [type] $cartItem
381
- * @param integer $quantity
383
+ * @param int $quantity
382
384
  * @param array $variants
383
385
  * @param array $addons
384
- * @return stdClass
386
+ *
387
+ * @return \stdClass
385
388
  */
386
- public function updateCartItem($cartItem, $quantity = 1, $variants = [], $addons = [], $scheduledAt = null)
389
+ public function updateCartItem($cartItem, $quantity = 1, $variants = [], $addons = [], $scheduledAt = null)
387
390
  {
388
391
  // get the line item product
389
392
  $productId = $cartItem->product_id;
390
- $product = static::findProduct($productId);
393
+ $product = static::findProduct($productId);
391
394
 
392
395
  // set base price
393
396
  $price = Utils::numbersOnly($product->is_on_sale ? $product->sale_price : $product->price);
@@ -401,23 +404,23 @@ class Cart extends StorefrontModel
401
404
  // find the item from cart
402
405
  $index = $this->findCartItemIndex($cartItem->id);
403
406
 
404
- $existingCartItem = $items[$index] ?? new stdClass();
407
+ $existingCartItem = $items[$index] ?? new \stdClass();
405
408
 
406
409
  $properties = [
407
- 'id' => $cartItem->id,
408
- 'store_id' => $product->store_id,
409
- 'product_id' => $product->public_id,
410
+ 'id' => $cartItem->id,
411
+ 'store_id' => $product->store_id,
412
+ 'product_id' => $product->public_id,
410
413
  'product_image_url' => $product->primary_image_url,
411
- 'name' => $product->name,
412
- 'description' => $product->description,
413
- 'scheduled_at' => $scheduledAt,
414
- 'created_at' => $cartItem->created_at,
415
- 'updated_at' => time(),
416
- 'quantity' => $quantity ?? $cartItem->quantity,
417
- 'price' => $price,
418
- 'subtotal' => $subtotal,
419
- 'variants' => $variants ?? $cartItem->variants,
420
- 'addons' => $addons ?? $cartItem->addons
414
+ 'name' => $product->name,
415
+ 'description' => $product->description,
416
+ 'scheduled_at' => $scheduledAt,
417
+ 'created_at' => $cartItem->created_at,
418
+ 'updated_at' => time(),
419
+ 'quantity' => $quantity ?? $cartItem->quantity,
420
+ 'price' => $price,
421
+ 'subtotal' => $subtotal,
422
+ 'variants' => $variants ?? $cartItem->variants,
423
+ 'addons' => $addons ?? $cartItem->addons,
421
424
  ];
422
425
 
423
426
  foreach ($properties as $prop => $value) {
@@ -436,11 +439,11 @@ class Cart extends StorefrontModel
436
439
  /**
437
440
  * Updates a cart item by id.
438
441
  *
439
- * @param string $id
440
- * @param integer $quantity
442
+ * @param int $quantity
441
443
  * @param array $variants
442
444
  * @param array $addons
443
- * @return stdClass
445
+ *
446
+ * @return \stdClass
444
447
  */
445
448
  public function updateCartItemById(string $id, $quantity = 1, $variants = [], $addons = [], $scheduledAt = null)
446
449
  {
@@ -452,13 +455,15 @@ class Cart extends StorefrontModel
452
455
  /**
453
456
  * Remove item from cart.
454
457
  *
455
- * @param stdClass|string $cartItem
456
- * @return stdClass
457
- * @throws Exception
458
+ * @param \stdClass|string $cartItem
459
+ *
460
+ * @return \stdClass
461
+ *
462
+ * @throws \Exception
458
463
  */
459
464
  public function remove($cartItem)
460
465
  {
461
- if ($cartItem instanceof stdClass) {
466
+ if ($cartItem instanceof \stdClass) {
462
467
  return $this->removeItem($cartItem);
463
468
  }
464
469
 
@@ -468,13 +473,14 @@ class Cart extends StorefrontModel
468
473
  return $this->remove($cartItem);
469
474
  }
470
475
 
471
- throw new Exception('Invalid cart item provided to cart!');
476
+ throw new \Exception('Invalid cart item provided to cart!');
472
477
  }
473
478
 
474
479
  /**
475
480
  * Removes an item from cart.
476
481
  *
477
- * @param stdClass $cartItem
482
+ * @param \stdClass $cartItem
483
+ *
478
484
  * @return \Fleetbase\Models\Storefront\Cart
479
485
  */
480
486
  public function removeItem($cartItem)
@@ -494,7 +500,6 @@ class Cart extends StorefrontModel
494
500
  /**
495
501
  * Removes a cart item by id.
496
502
  *
497
- * @param string $id
498
503
  * @return \Fleetbase\Models\Storefront\Cart
499
504
  */
500
505
  public function removeItemById(string $id)
@@ -521,11 +526,8 @@ class Cart extends StorefrontModel
521
526
 
522
527
  /**
523
528
  * Finds an item in cart by id.
524
- *
525
- * @param string $id
526
- * @return stdClass|null
527
529
  */
528
- public function findCartItem(string $id): ?stdClass
530
+ public function findCartItem(string $id): ?\stdClass
529
531
  {
530
532
  $items = $this->getAttribute('items');
531
533
 
@@ -538,9 +540,6 @@ class Cart extends StorefrontModel
538
540
 
539
541
  /**
540
542
  * Finds index of a cart item.
541
- *
542
- * @param string $id
543
- * @return integer|null
544
543
  */
545
544
  public function findCartItemIndex(string $id): ?int
546
545
  {
@@ -558,8 +557,8 @@ class Cart extends StorefrontModel
558
557
  /**
559
558
  * Create a new cart event.
560
559
  *
561
- * @param string $eventName
562
560
  * @param string|null $cartItemId
561
+ *
563
562
  * @return \Fleetbase\Models\Storefront\Cart
564
563
  */
565
564
  public function createEvent(string $eventName, $cartItemId = null, $save = true)
@@ -567,9 +566,9 @@ class Cart extends StorefrontModel
567
566
  $events = $this->getAttribute('events') ?? [];
568
567
 
569
568
  $events[] = Utils::createObject([
570
- 'event' => $eventName,
569
+ 'event' => $eventName,
571
570
  'cart_item_id' => $cartItemId,
572
- 'time' => time()
571
+ 'time' => time(),
573
572
  ]);
574
573
 
575
574
  $this->attributes['events'] = $events;
@@ -584,11 +583,11 @@ class Cart extends StorefrontModel
584
583
  /**
585
584
  * Update the cart session currency code.
586
585
  *
587
- * @param string $currencyCode
588
- * @param boolean $save
586
+ * @param bool $save
587
+ *
589
588
  * @return \Fleetbase\Models\Storefront\Cart
590
589
  */
591
- public function updateCurrency(?string $currencyCode = null, $save = false)
590
+ public function updateCurrency(string $currencyCode = null, $save = false)
592
591
  {
593
592
  $this->attributes['currency'] = $currencyCode ?? session('storefront_currency');
594
593
 
@@ -613,26 +612,24 @@ class Cart extends StorefrontModel
613
612
  * Creates a new cart.
614
613
  *
615
614
  * @param string|null $uniqueId
615
+ *
616
616
  * @return \Fleetbase\Models\Storefront\Cart
617
617
  */
618
618
  public static function newCart($uniqueId = null): Cart
619
619
  {
620
620
  return Cart::create([
621
621
  'unique_identifier' => $uniqueId,
622
- 'company_uuid' => session('company'),
623
- 'expires_at' => Carbon::now()->addDays(7),
624
- 'currency' => session('storefront_currency'),
625
- 'customer_id' => session('customer_id'),
626
- 'items' => [],
627
- 'events' => []
622
+ 'company_uuid' => session('company'),
623
+ 'expires_at' => Carbon::now()->addDays(7),
624
+ 'currency' => session('storefront_currency'),
625
+ 'customer_id' => session('customer_id'),
626
+ 'items' => [],
627
+ 'events' => [],
628
628
  ]);
629
629
  }
630
630
 
631
631
  /**
632
632
  * Retrieve a cart by id or unique id.
633
- *
634
- * @param string $id
635
- * @return Cart
636
633
  */
637
634
  public static function retrieve(string $id, bool $excludeCheckedout = true): Cart
638
635
  {
@@ -644,7 +641,7 @@ class Cart extends StorefrontModel
644
641
  if ($excludeCheckedout) {
645
642
  $query->whereNull('checkout_uuid');
646
643
  }
647
-
644
+
648
645
  $cart = $query->first();
649
646
 
650
647
  if (!$cart) {
@@ -658,10 +655,9 @@ class Cart extends StorefrontModel
658
655
  * Calculates the subtotal for a product using quantity vairants and addons.
659
656
  *
660
657
  * @param \Fleetbase\Models\Storefront\Product $product
661
- * @param integer $quantity
662
- * @param array $variants
663
- * @param array $addons
664
- * @return integer
658
+ * @param int $quantity
659
+ * @param array $variants
660
+ * @param array $addons
665
661
  */
666
662
  public static function calculateProductSubtotal(Product $product, $quantity = 1, $variants = [], $addons = []): int
667
663
  {
@@ -680,9 +676,6 @@ class Cart extends StorefrontModel
680
676
 
681
677
  /**
682
678
  * Finds a product via id.
683
- *
684
- * @param string $id
685
- * @return Product|null
686
679
  */
687
680
  public static function findProduct(string $id): ?Product
688
681
  {
@@ -3,20 +3,22 @@
3
3
  namespace Fleetbase\Storefront\Models;
4
4
 
5
5
  use Fleetbase\Casts\Json;
6
+ use Fleetbase\FleetOps\Support\Utils;
6
7
  use Fleetbase\Models\Company;
7
8
  use Fleetbase\Models\ServiceQuote;
8
- use Fleetbase\FleetOps\Support\Utils;
9
9
  use Fleetbase\Traits\HasOptionsAttributes;
10
- use Fleetbase\Traits\HasUuid;
11
10
  use Fleetbase\Traits\HasPublicid;
11
+ use Fleetbase\Traits\HasUuid;
12
12
  use Illuminate\Support\Str;
13
13
 
14
14
  class Checkout extends StorefrontModel
15
15
  {
16
- use HasUuid, HasPublicid, HasOptionsAttributes;
16
+ use HasUuid;
17
+ use HasPublicid;
18
+ use HasOptionsAttributes;
17
19
 
18
20
  /**
19
- * The type of public Id to generate
21
+ * The type of public Id to generate.
20
22
  *
21
23
  * @var string
22
24
  */
@@ -30,7 +32,7 @@ class Checkout extends StorefrontModel
30
32
  protected $table = 'checkouts';
31
33
 
32
34
  /**
33
- * These attributes that can be queried
35
+ * These attributes that can be queried.
34
36
  *
35
37
  * @var array
36
38
  */
@@ -50,14 +52,14 @@ class Checkout extends StorefrontModel
50
52
  */
51
53
  protected $casts = [
52
54
  'cart_state' => Json::class,
53
- 'options' => Json::class,
54
- 'captured' => 'boolean',
55
- 'is_cod' => 'boolean',
56
- 'is_pickup' => 'boolean'
55
+ 'options' => Json::class,
56
+ 'captured' => 'boolean',
57
+ 'is_cod' => 'boolean',
58
+ 'is_pickup' => 'boolean',
57
59
  ];
58
60
 
59
61
  /**
60
- * Dynamic attributes that are appended to object
62
+ * Dynamic attributes that are appended to object.
61
63
  *
62
64
  * @var array
63
65
  */
@@ -137,8 +139,8 @@ class Checkout extends StorefrontModel
137
139
  }
138
140
 
139
141
  /**
140
- * Sets the owner type
141
- *
142
+ * Sets the owner type.
143
+ *
142
144
  * @return void
143
145
  */
144
146
  public function setOwnerTypeAttribute($type)
@@ -8,9 +8,7 @@ use Illuminate\Support\Str;
8
8
  class Customer extends Contact
9
9
  {
10
10
  /**
11
- * The key to use in the payload responses
12
- *
13
- * @var string
11
+ * The key to use in the payload responses.
14
12
  */
15
13
  protected string $payloadKey = 'customer';
16
14
 
@@ -47,7 +45,7 @@ class Customer extends Contact
47
45
  }
48
46
 
49
47
  /**
50
- * @return integer
48
+ * @return int
51
49
  */
52
50
  public function getReviewsCountAttribute()
53
51
  {
@@ -55,26 +53,28 @@ class Customer extends Contact
55
53
  }
56
54
 
57
55
  /**
58
- * Count the number of orders for the storefront with the given ID
56
+ * Count the number of orders for the storefront with the given ID.
59
57
  *
60
58
  * @param int $id The ID of the storefront to count orders for
59
+ *
61
60
  * @return int The number of storefront orders for the customer with this UUID
62
61
  */
63
62
  public function countStorefrontOrdersFrom($id)
64
63
  {
65
64
  return \Fleetbase\FleetOps\Models\Order::where(
66
65
  [
67
- 'customer_uuid' => $this->uuid,
68
- 'type' => 'storefront',
69
- 'meta->storefront_id' => $id
66
+ 'customer_uuid' => $this->uuid,
67
+ 'type' => 'storefront',
68
+ 'meta->storefront_id' => $id,
70
69
  ]
71
70
  )->count();
72
71
  }
73
72
 
74
73
  /**
75
- * Find a customer with the given public ID
74
+ * Find a customer with the given public ID.
76
75
  *
77
76
  * @param string $publicId The public ID of the customer to find
77
+ *
78
78
  * @return static|null The customer with the given public ID, or null if none was found
79
79
  */
80
80
  public static function findFromCustomerId($publicId)