@fleetbase/storefront-engine 0.3.3 → 0.3.4

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 (69) hide show
  1. package/.php-cs-fixer.php +2 -0
  2. package/addon/components/modals/create-first-store.hbs +1 -1
  3. package/addon/components/modals/create-network.hbs +1 -1
  4. package/addon/components/modals/create-store.hbs +1 -1
  5. package/addon/components/modals/manage-addons.hbs +1 -1
  6. package/addon/components/modals/store-form.hbs +2 -2
  7. package/addon/components/storefront-order-summary.hbs +73 -0
  8. package/addon/components/storefront-order-summary.js +3 -0
  9. package/addon/components/widget/orders.js +1 -1
  10. package/addon/controllers/networks/index/network/index.js +5 -1
  11. package/addon/controllers/products/index/category/edit.js +1 -1
  12. package/addon/controllers/products/index/category/new.js +4 -5
  13. package/addon/controllers/settings/index.js +5 -1
  14. package/addon/engine.js +4 -0
  15. package/addon/templates/networks/index/network/index.hbs +1 -1
  16. package/addon/templates/products/index/category/new.hbs +10 -5
  17. package/addon/templates/settings/index.hbs +14 -4
  18. package/app/components/storefront-order-summary.js +1 -0
  19. package/composer.json +6 -4
  20. package/extension.json +1 -1
  21. package/package.json +3 -3
  22. package/server/migrations/2023_05_03_025307_create_carts_table.php +1 -2
  23. package/server/migrations/2023_05_03_025307_create_checkouts_table.php +1 -2
  24. package/server/migrations/2023_05_03_025307_create_gateways_table.php +1 -2
  25. package/server/migrations/2023_05_03_025307_create_network_stores_table.php +1 -2
  26. package/server/migrations/2023_05_03_025307_create_networks_table.php +1 -2
  27. package/server/migrations/2023_05_03_025307_create_notification_channels_table.php +1 -2
  28. package/server/migrations/2023_05_03_025307_create_payment_methods_table.php +1 -2
  29. package/server/migrations/2023_05_03_025307_create_product_addon_categories_table.php +1 -2
  30. package/server/migrations/2023_05_03_025307_create_product_addons_table.php +1 -2
  31. package/server/migrations/2023_05_03_025307_create_product_hours_table.php +1 -2
  32. package/server/migrations/2023_05_03_025307_create_product_store_locations_table.php +1 -2
  33. package/server/migrations/2023_05_03_025307_create_product_variant_options_table.php +1 -2
  34. package/server/migrations/2023_05_03_025307_create_product_variants_table.php +1 -2
  35. package/server/migrations/2023_05_03_025307_create_products_table.php +1 -2
  36. package/server/migrations/2023_05_03_025307_create_reviews_table.php +1 -2
  37. package/server/migrations/2023_05_03_025307_create_store_hours_table.php +1 -2
  38. package/server/migrations/2023_05_03_025307_create_store_locations_table.php +1 -2
  39. package/server/migrations/2023_05_03_025307_create_stores_table.php +1 -2
  40. package/server/migrations/2023_05_03_025307_create_votes_table.php +1 -2
  41. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_carts_table.php +3 -4
  42. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_checkouts_table.php +3 -4
  43. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_gateways_table.php +3 -4
  44. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_network_stores_table.php +3 -4
  45. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_networks_table.php +3 -4
  46. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_notification_channels_table.php +3 -4
  47. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_payment_methods_table.php +3 -4
  48. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_addon_categories_table.php +3 -4
  49. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_addons_table.php +3 -4
  50. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_hours_table.php +1 -2
  51. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_store_locations_table.php +1 -2
  52. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_variant_options_table.php +1 -2
  53. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_variants_table.php +1 -2
  54. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_products_table.php +3 -4
  55. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_reviews_table.php +3 -4
  56. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_store_hours_table.php +1 -2
  57. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_store_locations_table.php +3 -4
  58. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_stores_table.php +3 -4
  59. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_votes_table.php +3 -4
  60. package/server/seeders/OrderConfigSeeder.php +270 -0
  61. package/server/src/Expansions/EntityExpansion.php +2 -1
  62. package/server/src/Http/Controllers/v1/CartController.php +0 -12
  63. package/server/src/Http/Controllers/v1/CheckoutController.php +37 -38
  64. package/server/src/Http/Resources/Network.php +1 -0
  65. package/server/src/Http/Resources/Store.php +1 -0
  66. package/server/src/Models/Cart.php +3 -11
  67. package/server/src/Models/Product.php +2 -5
  68. package/server/src/Observers/NetworkObserver.php +1 -1
  69. package/translations/en-us.yaml +2 -0
@@ -264,6 +264,40 @@ class CheckoutController extends Controller
264
264
  ]);
265
265
  }
266
266
 
267
+ /**
268
+ * Process a cart item and create/save an entity.
269
+ *
270
+ * @param mixed $cartItem the cart item to process
271
+ * @param mixed $payload the payload
272
+ * @param mixed $customer the customer
273
+ *
274
+ * @return void
275
+ */
276
+ private function processCartItem($cartItem, $payload, $customer)
277
+ {
278
+ $product = Product::where('public_id', $cartItem->product_id)->first();
279
+
280
+ // Generate metas array
281
+ $metas = [
282
+ 'variants' => $cartItem->variants ?? [],
283
+ 'addons' => $cartItem->addons ?? [],
284
+ 'subtotal' => $cartItem->subtotal,
285
+ 'quantity' => $cartItem->quantity,
286
+ 'scheduled_at' => $cartItem->scheduled_at ?? null,
287
+ ];
288
+
289
+ // Create and fill entity
290
+ $entity = Entity::fromStorefrontProduct($product, $metas)->fill([
291
+ 'company_uuid' => session('company'),
292
+ 'payload_uuid' => $payload->uuid,
293
+ 'customer_uuid' => $customer->uuid,
294
+ 'customer_type' => Utils::getMutationType('fleet-ops:contact'),
295
+ ]);
296
+
297
+ // Save entity
298
+ $entity->save();
299
+ }
300
+
267
301
  public function captureOrder(CaptureOrderRequest $request)
268
302
  {
269
303
  $token = $request->input('token');
@@ -458,10 +492,7 @@ class CheckoutController extends Controller
458
492
 
459
493
  // create entities
460
494
  foreach ($cart->items as $cartItem) {
461
- $product = Product::where('public_id', $cartItem->product_id)->first();
462
- $entity = Entity::fromStorefrontProduct($product);
463
-
464
- $entity->save();
495
+ $this->processCartItem($cartItem, $payload, $customer);
465
496
  }
466
497
 
467
498
  // create order meta
@@ -515,8 +546,6 @@ class CheckoutController extends Controller
515
546
  // create order
516
547
  $order = Order::create($orderInput);
517
548
 
518
- info('Order created', $order->toArray());
519
-
520
549
  // notify order creation
521
550
  Storefront::alertNewOrder($order);
522
551
 
@@ -692,22 +721,7 @@ class CheckoutController extends Controller
692
721
 
693
722
  // create entities
694
723
  foreach ($cartItems as $cartItem) {
695
- $product = Product::where('public_id', $cartItem->product_id)->first();
696
-
697
- $entity = Entity::fromStorefrontProduct($product)->fill([
698
- 'company_uuid' => $store->company_uuid,
699
- 'payload_uuid' => $payload->uuid,
700
- 'customer_uuid' => $customer->uuid,
701
- 'customer_type' => Utils::getMutationType('fleet-ops:contact'),
702
- ])->setMetas([
703
- 'variants' => $cartItem->variants,
704
- 'addons' => $cartItem->addons,
705
- 'subtotal' => $cartItem->subtotal,
706
- 'quantity' => $cartItem->quantity,
707
- 'scheduled_at' => $cartItem->scheduled_at ?? null,
708
- ]);
709
-
710
- $entity->save();
724
+ $this->processCartItem($cartItem, $payload, $customer);
711
725
  }
712
726
 
713
727
  // get order subtotal
@@ -797,22 +811,7 @@ class CheckoutController extends Controller
797
811
 
798
812
  // create entities
799
813
  foreach ($cart->items as $cartItem) {
800
- $product = Product::where('public_id', $cartItem->product_id)->first();
801
-
802
- $entity = Entity::fromStorefrontProduct($product)->fill([
803
- 'company_uuid' => session('company'),
804
- 'payload_uuid' => $payload->uuid,
805
- 'customer_uuid' => $customer->uuid,
806
- 'customer_type' => Utils::getMutationType('fleet-ops:contact'),
807
- ])->setMetas([
808
- 'variants' => $cartItem->variants,
809
- 'addons' => $cartItem->addons,
810
- 'subtotal' => $cartItem->subtotal,
811
- 'quantity' => $cartItem->quantity,
812
- 'scheduled_at' => $cartItem->scheduled_at ?? null,
813
- ]);
814
-
815
- $entity->save();
814
+ $this->processCartItem($cartItem, $payload, $customer);
816
815
  }
817
816
 
818
817
  // prepare master order meta
@@ -37,6 +37,7 @@ class Network extends FleetbaseResource
37
37
  'tags' => $this->tags ?? [],
38
38
  'currency' => $this->currency ?? 'USD',
39
39
  'options' => $this->options ?? [],
40
+ 'alertable' => $this->alertable,
40
41
  'logo_url' => $this->logo_url,
41
42
  'backdrop_url' => $this->backdrop_url,
42
43
  'rating' => $this->rating,
@@ -41,6 +41,7 @@ class Store extends FleetbaseResource
41
41
  'backdrop_url' => $this->backdrop_url,
42
42
  'rating' => $this->rating,
43
43
  'online' => $this->online,
44
+ 'alertable' => $this->alertable,
44
45
  'is_network' => false,
45
46
  'is_store' => true,
46
47
  'category' => $this->when($request->filled('network') && ($request->has('with_category') || $request->inArray('with', 'category')), new Category($this->getNetworkCategoryUsingId($request->input('network')))),
@@ -334,6 +334,8 @@ class Cart extends StorefrontModel
334
334
  'addons' => $addons,
335
335
  ];
336
336
 
337
+ $this->updateCurrency($product->currency, false);
338
+
337
339
  foreach ($properties as $prop => $value) {
338
340
  $cartItem->{$prop} = $value;
339
341
  }
@@ -598,16 +600,6 @@ class Cart extends StorefrontModel
598
600
  return $this;
599
601
  }
600
602
 
601
- /**
602
- * Reset the cart currency code to the current session.
603
- *
604
- * @return \Fleetbase\Models\Storefront\Cart
605
- */
606
- public function resetCurrency()
607
- {
608
- return $this->updateCurrency(null, true);
609
- }
610
-
611
603
  /**
612
604
  * Creates a new cart.
613
605
  *
@@ -679,6 +671,6 @@ class Cart extends StorefrontModel
679
671
  */
680
672
  public static function findProduct(string $id): ?Product
681
673
  {
682
- return Product::select(['uuid', 'store_uuid', 'public_id', 'name', 'description', 'price', 'sale_price', 'is_on_sale'])->where(['public_id' => $id])->with([])->first();
674
+ return Product::select(['uuid', 'store_uuid', 'public_id', 'name', 'description', 'price', 'currency', 'sale_price', 'is_on_sale'])->where(['public_id' => $id])->with([])->first();
683
675
  }
684
676
  }
@@ -322,9 +322,6 @@ class Product extends StorefrontModel
322
322
  'max_selectable' => data_get($addonCategory, 'max_selectable'),
323
323
  'is_required' => data_get($addonCategory, 'is_required'),
324
324
  ]);
325
-
326
- // insert to hasmany relation
327
- $this->addonCategories->push($productAddonCategory);
328
325
  }
329
326
 
330
327
  return $this;
@@ -357,8 +354,8 @@ class Product extends StorefrontModel
357
354
  'meta' => data_get($variant, 'meta', []),
358
355
  'is_multiselect' => data_get($variant, 'is_multiselect'),
359
356
  'is_required' => data_get($variant, 'is_required'),
360
- 'min' => data_get($variant, 'min'),
361
- 'max' => data_get($variant, 'max'),
357
+ 'min' => data_get($variant, 'min') ?? 0,
358
+ 'max' => data_get($variant, 'max') ?? 100,
362
359
  ]);
363
360
 
364
361
  // Update product variant options if applicable
@@ -27,7 +27,7 @@ class NetworkObserver
27
27
  return [
28
28
  $key => collect($alertables)->map(
29
29
  function ($user) {
30
- return data_get($user, 'public_id');
30
+ return $user;
31
31
  }
32
32
  )
33
33
  ->values()
@@ -77,6 +77,8 @@ storefront:
77
77
  settings: Settings
78
78
  launch-app: Launch App
79
79
  component:
80
+ storefront-order-summary:
81
+ order-summary-title: Storefront Order Summary
80
82
  modals:
81
83
  add-store-hours:
82
84
  start-time: Start time