@fleetbase/storefront-engine 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/README.md +4 -4
  2. package/addon/components/modals/import-products.hbs +1 -1
  3. package/addon/components/schedule-manager.hbs +2 -2
  4. package/addon/components/widget/customers.hbs +1 -1
  5. package/addon/components/widget/customers.js +7 -4
  6. package/addon/components/widget/orders.js +4 -0
  7. package/addon/controllers/base-controller.js +31 -0
  8. package/addon/controllers/networks/index/network.js +2 -2
  9. package/addon/controllers/networks/index.js +3 -2
  10. package/addon/controllers/products/index/category/new.js +14 -11
  11. package/addon/controllers/products/index/category.js +2 -2
  12. package/addon/controllers/products/index/index.js +2 -2
  13. package/addon/controllers/products/index.js +2 -3
  14. package/addon/models/network.js +0 -1
  15. package/addon/models/product-addon-category.js +10 -1
  16. package/addon/models/product-variant.js +0 -2
  17. package/addon/models/product.js +35 -2
  18. package/addon/routes/customers/index.js +11 -1
  19. package/addon/routes/networks/index.js +9 -0
  20. package/addon/routes/orders/index.js +11 -1
  21. package/addon/routes/products/index.js +8 -2
  22. package/addon/serializers/product.js +16 -0
  23. package/addon/services/storefront.js +81 -0
  24. package/addon/templates/networks/index/network/stores.hbs +2 -2
  25. package/addon/templates/networks/index/network.hbs +1 -1
  26. package/addon/templates/products/index/category/new.hbs +3 -3
  27. package/addon/templates/products/index/category.hbs +20 -3
  28. package/app/controllers/base-controller.js +1 -0
  29. package/assets/sounds/storefront_order_alert.mp3 +0 -0
  30. package/composer.json +3 -3
  31. package/config/environment.js +11 -1
  32. package/extension.json +1 -1
  33. package/index.js +15 -0
  34. package/package.json +132 -125
  35. package/server/src/Auth/Schemas/Storefront.php +31 -39
  36. package/server/src/Console/Commands/NotifyStorefrontOrderNearby.php +9 -11
  37. package/server/src/Expansions/ContactFilterExpansion.php +36 -0
  38. package/server/src/Expansions/EntityExpansion.php +12 -12
  39. package/server/src/Expansions/OrderFilterExpansion.php +31 -0
  40. package/server/src/Expansions/VendorFilterExpansion.php +36 -0
  41. package/server/src/Http/Controllers/ActionController.php +9 -11
  42. package/server/src/Http/Controllers/AddonCategoryController.php +1 -1
  43. package/server/src/Http/Controllers/CustomerController.php +1 -1
  44. package/server/src/Http/Controllers/GatewayController.php +1 -1
  45. package/server/src/Http/Controllers/MetricsController.php +17 -17
  46. package/server/src/Http/Controllers/NetworkController.php +16 -26
  47. package/server/src/Http/Controllers/NotificationChannelController.php +1 -1
  48. package/server/src/Http/Controllers/OrderController.php +18 -22
  49. package/server/src/Http/Controllers/ProductAddonCategoryController.php +1 -2
  50. package/server/src/Http/Controllers/ProductAddonController.php +1 -2
  51. package/server/src/Http/Controllers/ProductController.php +89 -44
  52. package/server/src/Http/Controllers/ProductHourController.php +1 -1
  53. package/server/src/Http/Controllers/ProductVariantController.php +1 -1
  54. package/server/src/Http/Controllers/ProductVariantOptionController.php +1 -1
  55. package/server/src/Http/Controllers/ReviewController.php +1 -1
  56. package/server/src/Http/Controllers/StoreController.php +1 -2
  57. package/server/src/Http/Controllers/StoreHourController.php +1 -1
  58. package/server/src/Http/Controllers/StoreLocationController.php +1 -1
  59. package/server/src/Http/Controllers/StorefrontController.php +0 -2
  60. package/server/src/Http/Controllers/VoteController.php +1 -1
  61. package/server/src/Http/Controllers/v1/CartController.php +16 -26
  62. package/server/src/Http/Controllers/v1/CategoryController.php +3 -4
  63. package/server/src/Http/Controllers/v1/CheckoutController.php +283 -286
  64. package/server/src/Http/Controllers/v1/CustomerController.php +54 -67
  65. package/server/src/Http/Controllers/v1/GatewayControllerController.php +0 -2
  66. package/server/src/Http/Controllers/v1/NetworkController.php +26 -23
  67. package/server/src/Http/Controllers/v1/PaymentMethodController.php +0 -2
  68. package/server/src/Http/Controllers/v1/ProductController.php +1 -4
  69. package/server/src/Http/Controllers/v1/ReviewController.php +31 -35
  70. package/server/src/Http/Controllers/v1/ServiceQuoteController.php +57 -53
  71. package/server/src/Http/Controllers/v1/StoreController.php +8 -16
  72. package/server/src/Http/Filter/AddonCategoryFilter.php +1 -1
  73. package/server/src/Http/Filter/OrderFilter.php +2 -2
  74. package/server/src/Http/Middleware/SetStorefrontSession.php +9 -20
  75. package/server/src/Http/Requests/AddStoreToNetworkCategory.php +3 -3
  76. package/server/src/Http/Requests/CreateCustomerRequest.php +5 -7
  77. package/server/src/Http/Requests/CreateReviewRequest.php +4 -5
  78. package/server/src/Http/Requests/GetServiceQuoteFromCart.php +2 -2
  79. package/server/src/Http/Requests/InitializeCheckoutRequest.php +5 -5
  80. package/server/src/Http/Requests/NetworkActionRequest.php +2 -2
  81. package/server/src/Http/Requests/VerifyCreateCustomerRequest.php +2 -2
  82. package/server/src/Http/Resources/Cart.php +20 -11
  83. package/server/src/Http/Resources/Category.php +12 -11
  84. package/server/src/Http/Resources/Customer.php +15 -14
  85. package/server/src/Http/Resources/Gateway.php +12 -11
  86. package/server/src/Http/Resources/Media.php +9 -8
  87. package/server/src/Http/Resources/Network.php +33 -28
  88. package/server/src/Http/Resources/Product.php +89 -81
  89. package/server/src/Http/Resources/Review.php +14 -13
  90. package/server/src/Http/Resources/ReviewCustomer.php +12 -11
  91. package/server/src/Http/Resources/Store.php +39 -33
  92. package/server/src/Http/Resources/StoreHour.php +9 -8
  93. package/server/src/Http/Resources/StoreLocation.php +9 -9
  94. package/server/src/Imports/ProductsImport.php +0 -2
  95. package/server/src/Jobs/DownloadProductImageUrl.php +7 -4
  96. package/server/src/Listeners/HandleOrderCompleted.php +2 -1
  97. package/server/src/Listeners/HandleOrderDispatched.php +2 -1
  98. package/server/src/Listeners/HandleOrderDriverAssigned.php +2 -1
  99. package/server/src/Listeners/HandleOrderStarted.php +4 -3
  100. package/server/src/Mail/StorefrontNetworkInvite.php +7 -6
  101. package/server/src/Models/AddonCategory.php +2 -4
  102. package/server/src/Models/Cart.php +117 -124
  103. package/server/src/Models/Checkout.php +14 -12
  104. package/server/src/Models/Customer.php +9 -9
  105. package/server/src/Models/Gateway.php +22 -22
  106. package/server/src/Models/Network.php +41 -52
  107. package/server/src/Models/NetworkStore.php +6 -5
  108. package/server/src/Models/NotificationChannel.php +11 -9
  109. package/server/src/Models/PaymentMethod.php +9 -7
  110. package/server/src/Models/Product.php +152 -30
  111. package/server/src/Models/ProductAddon.php +14 -11
  112. package/server/src/Models/ProductAddonCategory.php +9 -8
  113. package/server/src/Models/ProductHour.php +6 -5
  114. package/server/src/Models/ProductStoreLocation.php +7 -5
  115. package/server/src/Models/ProductVariant.php +15 -11
  116. package/server/src/Models/ProductVariantOption.php +12 -9
  117. package/server/src/Models/Review.php +9 -7
  118. package/server/src/Models/Store.php +68 -84
  119. package/server/src/Models/StoreHour.php +6 -5
  120. package/server/src/Models/StoreLocation.php +12 -8
  121. package/server/src/Models/StorefrontModel.php +1 -1
  122. package/server/src/Models/Vote.php +8 -6
  123. package/server/src/Notifications/StorefrontOrderCanceled.php +15 -19
  124. package/server/src/Notifications/StorefrontOrderCompleted.php +15 -19
  125. package/server/src/Notifications/StorefrontOrderCreated.php +31 -36
  126. package/server/src/Notifications/StorefrontOrderDriverAssigned.php +15 -20
  127. package/server/src/Notifications/StorefrontOrderEnroute.php +14 -19
  128. package/server/src/Notifications/StorefrontOrderNearby.php +16 -21
  129. package/server/src/Notifications/StorefrontOrderPreparing.php +15 -18
  130. package/server/src/Notifications/StorefrontOrderReadyForPickup.php +15 -18
  131. package/server/src/Observers/NetworkObserver.php +2 -3
  132. package/server/src/Observers/ProductObserver.php +17 -33
  133. package/server/src/Providers/EventServiceProvider.php +15 -4
  134. package/server/src/Providers/StorefrontServiceProvider.php +8 -10
  135. package/server/src/Support/Metrics.php +12 -12
  136. package/server/src/Support/OrderConfig.php +3 -2
  137. package/server/src/Support/QPay.php +22 -20
  138. package/server/src/Support/Storefront.php +18 -17
  139. package/server/src/routes.php +1 -1
  140. package/tsconfig.declarations.json +10 -0
@@ -27,9 +27,9 @@ class GetServiceQuoteFromCart extends FleetbaseRequest
27
27
  {
28
28
  // valid origin is only required if store_ key
29
29
  return [
30
- 'origin' => $this->isStoreKey() ? ['required', new IsValidLocation()] : [],
30
+ 'origin' => $this->isStoreKey() ? ['required', new IsValidLocation()] : [],
31
31
  'destination' => ['required', new IsValidLocation()],
32
- 'cart' => 'required'
32
+ 'cart' => 'required',
33
33
  ];
34
34
  }
35
35
 
@@ -27,12 +27,12 @@ class InitializeCheckoutRequest extends FleetbaseRequest
27
27
  public function rules()
28
28
  {
29
29
  return [
30
- 'gateway' => ['required', new GatewayExists],
31
- 'customer' => ['required', new CustomerExists],
32
- 'cart' => ['required', 'exists:storefront.carts,public_id'],
30
+ 'gateway' => ['required', new GatewayExists()],
31
+ 'customer' => ['required', new CustomerExists()],
32
+ 'cart' => ['required', 'exists:storefront.carts,public_id'],
33
33
  'serviceQuote' => ['required', 'exists:service_quotes,public_id'],
34
- 'cash' => ['sometimes', 'boolean'],
35
- 'pickup' => ['sometimes', 'boolean'],
34
+ 'cash' => ['sometimes', 'boolean'],
35
+ 'pickup' => ['sometimes', 'boolean'],
36
36
  ];
37
37
  }
38
38
  }
@@ -13,7 +13,7 @@ class NetworkActionRequest extends FleetbaseRequest
13
13
  */
14
14
  public function all($keys = null)
15
15
  {
16
- $data = parent::all($keys);
16
+ $data = parent::all($keys);
17
17
  $data['id'] = $this->route('id');
18
18
 
19
19
  return $data;
@@ -37,7 +37,7 @@ class NetworkActionRequest extends FleetbaseRequest
37
37
  public function rules()
38
38
  {
39
39
  return [
40
- 'id' => ['required', 'exists:storefront.networks,uuid']
40
+ 'id' => ['required', 'exists:storefront.networks,uuid'],
41
41
  ];
42
42
  }
43
43
  }
@@ -24,8 +24,8 @@ class VerifyCreateCustomerRequest extends FleetbaseRequest
24
24
  public function rules()
25
25
  {
26
26
  return [
27
- 'mode' => 'required|in:email,sms',
28
- 'identity' => 'required'
27
+ 'mode' => 'required|in:email,sms',
28
+ 'identity' => 'required',
29
29
  ];
30
30
  }
31
31
  }
@@ -3,29 +3,38 @@
3
3
  namespace Fleetbase\Storefront\Http\Resources;
4
4
 
5
5
  use Fleetbase\Http\Resources\FleetbaseResource;
6
+ use Fleetbase\Support\Http;
6
7
 
7
8
  class Cart extends FleetbaseResource
8
9
  {
9
10
  /**
10
11
  * Transform the resource into an array.
11
12
  *
12
- * @param \Illuminate\Http\Request $request
13
+ * @param \Illuminate\Http\Request $request
14
+ *
13
15
  * @return array
14
16
  */
15
17
  public function toArray($request)
16
18
  {
17
19
  return [
18
- 'id' => $this->public_id,
19
- 'currency' => $this->currency,
20
- 'subtotal' => $this->subtotal,
21
- 'total_items' => $this->total_items,
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
+ 'user_uuid' => $this->when(Http::isInternalRequest(), $this->user_uuid),
25
+ 'checkout_uuid' => $this->when(Http::isInternalRequest(), $this->checkout_uuid),
26
+ 'checkout_uuid' => $this->when(Http::isInternalRequest(), $this->checkout_uuid),
27
+ 'customer_id' => $this->customer_id,
28
+ 'currency' => $this->currency,
29
+ 'subtotal' => $this->subtotal,
30
+ 'total_items' => $this->total_items,
22
31
  'total_unique_items' => $this->total_unique_items,
23
- 'items' => $this->items ?? [],
24
- 'events' => $this->events ?? [],
25
- 'discount_code' => $this->discount_code,
26
- 'expires_at' => $this->expires_at,
27
- 'created_at' => $this->created_at,
28
- 'updated_at' => $this->updated_at,
32
+ 'items' => $this->items ?? [],
33
+ 'events' => $this->events ?? [],
34
+ 'discount_code' => $this->discount_code,
35
+ 'expires_at' => $this->expires_at,
36
+ 'created_at' => $this->created_at,
37
+ 'updated_at' => $this->updated_at,
29
38
  ];
30
39
  }
31
40
  }
@@ -10,26 +10,27 @@ class Category extends FleetbaseResource
10
10
  /**
11
11
  * Transform the resource into an array.
12
12
  *
13
- * @param \Illuminate\Http\Request $request
13
+ * @param \Illuminate\Http\Request $request
14
+ *
14
15
  * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
15
16
  */
16
17
  public function toArray($request)
17
18
  {
18
19
  return [
19
- 'id' => $this->public_id,
20
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
21
- 'name' => $this->name,
20
+ 'id' => $this->public_id,
21
+ 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
22
+ 'name' => $this->name,
22
23
  'description' => $this->description,
23
- 'icon_url' => $this->icon_url,
24
- 'parent' => $this->whenLoaded(
24
+ 'icon_url' => $this->icon_url,
25
+ 'parent' => $this->whenLoaded(
25
26
  'parentCategory',
26
27
  function ($parentCategory) {
27
28
  return $parentCategory->public_id;
28
29
  }
29
30
  ),
30
- 'tags' => $this->tags ?? [],
31
- 'translations' => $this->translations ?? [],
32
- 'products' => Product::collection($this->whenLoaded('products')),
31
+ 'tags' => $this->tags ?? [],
32
+ 'translations' => $this->translations ?? [],
33
+ 'products' => Product::collection($this->whenLoaded('products')),
33
34
  'subcategories' => $this->when(
34
35
  $request->has('with_subcategories'),
35
36
  array_map(
@@ -39,8 +40,8 @@ class Category extends FleetbaseResource
39
40
  $this->subCategories->toArray()
40
41
  )
41
42
  ),
42
- 'order' => $this->order,
43
- 'slug' => $this->slug,
43
+ 'order' => $this->order,
44
+ 'slug' => $this->slug,
44
45
  'created_at' => $this->created_at,
45
46
  'updated_at' => $this->updated_at,
46
47
  ];
@@ -11,26 +11,27 @@ class Customer extends FleetbaseResource
11
11
  /**
12
12
  * Transform the resource into an array.
13
13
  *
14
- * @param \Illuminate\Http\Request $request
14
+ * @param \Illuminate\Http\Request $request
15
+ *
15
16
  * @return array
16
17
  */
17
18
  public function toArray($request)
18
19
  {
19
20
  return [
20
- 'id' => $this->when(Http::isInternalRequest(), $this->id, Str::replaceFirst('contact', 'customer', $this->public_id)),
21
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
22
- 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
21
+ 'id' => $this->when(Http::isInternalRequest(), $this->id, Str::replaceFirst('contact', 'customer', $this->public_id)),
22
+ 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
23
+ 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
23
24
  'internal_id' => $this->internal_id,
24
- 'name' => $this->name,
25
- 'photo_url' => $this->photo_url,
26
- 'email' => $this->email,
27
- 'phone' => $this->phone,
28
- 'address' => data_get($this, 'address.address'),
29
- 'addresses' => $this->addresses,
30
- 'token' => $this->when($this->token, $this->token),
31
- 'slug' => $this->slug,
32
- 'created_at' => $this->created_at,
33
- 'updated_at' => $this->updated_at,
25
+ 'name' => $this->name,
26
+ 'photo_url' => $this->photo_url,
27
+ 'email' => $this->email,
28
+ 'phone' => $this->phone,
29
+ 'address' => data_get($this, 'address.address'),
30
+ 'addresses' => $this->addresses,
31
+ 'token' => $this->when($this->token, $this->token),
32
+ 'slug' => $this->slug,
33
+ 'created_at' => $this->created_at,
34
+ 'updated_at' => $this->updated_at,
34
35
  ];
35
36
  }
36
37
  }
@@ -10,22 +10,23 @@ class Gateway extends FleetbaseResource
10
10
  /**
11
11
  * Transform the resource into an array.
12
12
  *
13
- * @param \Illuminate\Http\Request $request
13
+ * @param \Illuminate\Http\Request $request
14
+ *
14
15
  * @return array
15
16
  */
16
17
  public function toArray($request)
17
18
  {
18
19
  return [
19
- 'id' => $this->when(Http::isInternalRequest(), $this->id,$this->public_id),
20
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
21
- 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
22
- 'name' => $this->name,
23
- 'description' => $this->description,
24
- 'logo_url' => $this->logo_url,
25
- 'code' => $this->code,
26
- 'type' => $this->type,
27
- 'sandbox' => $this->sandbox,
28
- 'return_url' => $this->return_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
+ '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,
29
30
  'callback_url' => $this->callback_url,
30
31
  ];
31
32
  }
@@ -10,19 +10,20 @@ class Media extends FleetbaseResource
10
10
  /**
11
11
  * Transform the resource into an array.
12
12
  *
13
- * @param \Illuminate\Http\Request $request
13
+ * @param \Illuminate\Http\Request $request
14
+ *
14
15
  * @return array
15
16
  */
16
17
  public function toArray($request)
17
18
  {
18
19
  return [
19
- 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
20
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
21
- 'filename' => data_get($this, 'original_filename'),
22
- 'type' => data_get($this, 'content_type'),
23
- 'caption' => data_get($this, 'caption'),
24
- 'url' => data_get($this, 'url'),
25
- 'created_at' => $this->when(Http::isInternalRequest(), $this->created_at),
20
+ 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
21
+ 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
22
+ 'filename' => data_get($this, 'original_filename'),
23
+ 'type' => data_get($this, 'content_type'),
24
+ 'caption' => data_get($this, 'caption'),
25
+ 'url' => data_get($this, 'url'),
26
+ 'created_at' => $this->when(Http::isInternalRequest(), $this->created_at),
26
27
  'updated_at' => $this->when(Http::isInternalRequest(), $this->updated_at),
27
28
  ];
28
29
  }
@@ -10,39 +10,44 @@ class Network extends FleetbaseResource
10
10
  /**
11
11
  * Transform the resource into an array.
12
12
  *
13
- * @param \Illuminate\Http\Request $request
13
+ * @param \Illuminate\Http\Request $request
14
+ *
14
15
  * @return array
15
16
  */
16
17
  public function toArray($request)
17
18
  {
18
19
  return [
19
- 'id' => $this->when(Http::isInternalRequest(), $this->id,$this->public_id),
20
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
21
- 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
22
- 'key' => $this->when(Http::isInternalRequest(), $this->key),
23
- 'name' => $this->name,
24
- 'description' => $this->description,
25
- 'translations' => $this->translations ?? [],
26
- 'website' => $this->website,
27
- 'facebook' => $this->facebook,
28
- 'instagram' => $this->instagram,
29
- 'twitter' => $this->twitter,
30
- 'email' => $this->email,
31
- 'phone' => $this->phone,
32
- 'tags' => $this->tags ?? [],
33
- 'currency' => $this->currency ?? 'USD',
34
- 'options' => $this->options ?? [],
35
- 'logo_url' => $this->logo_url,
36
- 'backdrop_url' => $this->backdrop_url,
37
- 'rating' => $this->rating,
38
- 'online' => $this->online,
39
- 'stores' => $this->when($request->boolean('with_stores') || $request->inArray('with', 'stores'), Store::collection($this->stores)),
40
- 'categories' => $this->when($request->boolean('with_categories') || $request->inArray('with', 'categories'), Category::collection($this->categories)),
41
- 'is_network' => true,
42
- 'is_store' => false,
43
- 'slug' => $this->slug,
44
- 'created_at' => $this->created_at,
45
- '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
+ '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
+ 'logo_url' => $this->logo_url,
41
+ 'backdrop_url' => $this->backdrop_url,
42
+ 'rating' => $this->rating,
43
+ 'online' => $this->online,
44
+ 'stores' => $this->when($request->boolean('with_stores') || $request->inArray('with', 'stores'), Store::collection($this->stores)),
45
+ 'categories' => $this->when($request->boolean('with_categories') || $request->inArray('with', 'categories'), Category::collection($this->categories)),
46
+ 'is_network' => true,
47
+ 'is_store' => false,
48
+ 'slug' => $this->slug,
49
+ 'created_at' => $this->created_at,
50
+ 'updated_at' => $this->updated_at,
46
51
  ];
47
52
  }
48
53
  }
@@ -12,44 +12,50 @@ class Product extends FleetbaseResource
12
12
  /**
13
13
  * Transform the resource into an array.
14
14
  *
15
- * @param \Illuminate\Http\Request $request
15
+ * @param \Illuminate\Http\Request $request
16
+ *
16
17
  * @return array
17
18
  */
18
19
  public function toArray($request)
19
20
  {
20
21
  return [
21
- 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
22
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
23
- 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
24
- 'name' => $this->name,
25
- 'description' => $this->description,
26
- 'sku' => $this->sku,
27
- 'primary_image_url' => $this->primary_image_url,
28
- 'price' => $this->price,
29
- 'sale_price' => $this->sale_price,
30
- 'currency' => $this->currency,
31
- 'is_on_sale' => $this->is_on_sale,
32
- 'is_recommended' => $this->is_recommended,
33
- 'is_service' => $this->is_service,
34
- 'is_bookable' => $this->is_bookable,
35
- 'is_available' => $this->is_available,
36
- 'tags' => $this->tags ?? [],
37
- 'status' => $this->status,
38
- 'slug' => $this->slug,
39
- 'translations' => $this->translations ?? [],
40
- 'addon_categories' => $this->mapAddonCategories($this->addonCategories),
41
- 'variants' => $this->mapVariants($this->variants),
42
- 'files' => $this->when(Http::isInternalRequest(), $this->files),
43
- 'images' => $this->when(!Http::isInternalRequest(), $this->mapFiles($this->files)),
44
- 'videos' => $this->when(!Http::isInternalRequest(), $this->mapFiles($this->files, 'video')),
45
- 'hours' => $this->mapHours($this->hours),
46
- 'youtube_urls' => $this->youtube_urls ?? [],
47
- 'created_at' => $this->created_at,
48
- 'updated_at' => $this->updated_at,
22
+ 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
23
+ 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
24
+ 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
25
+ 'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
26
+ 'store_uuid' => $this->when(Http::isInternalRequest(), $this->store_uuid),
27
+ 'category_uuid' => $this->when(Http::isInternalRequest(), $this->category_uuid),
28
+ 'created_by_uuid' => $this->when(Http::isInternalRequest(), $this->created_by_uuid),
29
+ 'primary_image_uuid' => $this->when(Http::isInternalRequest(), $this->primary_image_uuid),
30
+ 'name' => $this->name,
31
+ 'description' => $this->description,
32
+ 'sku' => $this->sku,
33
+ 'primary_image_url' => $this->primary_image_url,
34
+ 'price' => $this->price,
35
+ 'sale_price' => $this->sale_price,
36
+ 'currency' => $this->currency,
37
+ 'is_on_sale' => $this->is_on_sale,
38
+ 'is_recommended' => $this->is_recommended,
39
+ 'is_service' => $this->is_service,
40
+ 'is_bookable' => $this->is_bookable,
41
+ 'is_available' => $this->is_available,
42
+ 'tags' => $this->tags ?? [],
43
+ 'status' => $this->status,
44
+ 'slug' => $this->slug,
45
+ 'translations' => $this->translations ?? [],
46
+ 'addon_categories' => $this->mapAddonCategories($this->addonCategories),
47
+ 'variants' => $this->mapVariants($this->variants),
48
+ 'files' => $this->when(Http::isInternalRequest(), $this->files),
49
+ 'images' => $this->when(!Http::isInternalRequest(), $this->mapFiles($this->files)),
50
+ 'videos' => $this->when(!Http::isInternalRequest(), $this->mapFiles($this->files, 'video')),
51
+ 'hours' => $this->mapHours($this->hours),
52
+ 'youtube_urls' => $this->youtube_urls ?? [],
53
+ 'created_at' => $this->created_at,
54
+ 'updated_at' => $this->updated_at,
49
55
  ];
50
56
  }
51
57
 
52
- public function mapHours(?\Illuminate\Database\Eloquent\Collection $hours = null): array
58
+ public function mapHours(\Illuminate\Database\Eloquent\Collection $hours = null): array
53
59
  {
54
60
  if (empty($hours)) {
55
61
  return [];
@@ -59,21 +65,21 @@ class Product extends FleetbaseResource
59
65
  function ($hour) {
60
66
  // modify for internal requests
61
67
  if (Http::isInternalRequest()) {
62
- $hour['id'] = data_get($hour, 'id');
68
+ $hour['id'] = data_get($hour, 'id');
63
69
  $hour['uuid'] = data_get($hour, 'uuid');
64
70
  }
65
71
 
66
72
  return array_merge($hour, [
67
- 'day' => data_get($hour, 'day_of_week'),
73
+ 'day' => data_get($hour, 'day_of_week'),
68
74
  'start' => data_get($hour, 'start'),
69
- 'end' => data_get($hour, 'end'),
75
+ 'end' => data_get($hour, 'end'),
70
76
  ]);
71
77
  },
72
78
  $hours->toArray()
73
79
  );
74
80
  }
75
81
 
76
- public function mapFiles(?\Illuminate\Database\Eloquent\Collection $files = null, $contentType = 'image')
82
+ public function mapFiles(\Illuminate\Database\Eloquent\Collection $files = null, $contentType = 'image')
77
83
  {
78
84
  return collect($files)->map(function ($file) use ($contentType) {
79
85
  if (!Str::contains($file->content_type, $contentType)) {
@@ -84,35 +90,37 @@ class Product extends FleetbaseResource
84
90
  })->filter()->values();
85
91
  }
86
92
 
87
- public function mapAddonCategories(?\Illuminate\Database\Eloquent\Collection $addonCategories = null)
93
+ public function mapAddonCategories(\Illuminate\Database\Eloquent\Collection $addonCategories = null)
88
94
  {
89
95
  return collect($addonCategories)->map(function ($addonCategory) {
90
- $addonCategoryArr = [
91
- 'id' => $addonCategory->category->public_id ?? null,
92
- 'name' => $addonCategory->name,
93
- 'description' => $addonCategory->category->description ?? null,
94
- 'addons' => $this->mapProductAddons($addonCategory->category->addons ?? [], $addonCategory->excluded_addons)
95
- ];
96
+ $addons = data_get($addonCategory, 'category.addons', []);
96
97
 
97
- // modify for internal requests
98
98
  if (Http::isInternalRequest()) {
99
- $addonCategoryArr['id'] = $addonCategory->category->id;
100
-
101
- $addonCategoryArr = Arr::insertAfterKey(
102
- $addonCategoryArr,
103
- [
104
- 'uuid' => $addonCategory->category->uuid,
105
- 'public_id' => $addonCategory->category->public_id
106
- ],
107
- 'id'
108
- );
99
+ return [
100
+ 'uuid' => $addonCategory->uuid,
101
+ 'public_id' => data_get($addonCategory, 'category.public_id'),
102
+ 'id' => $addonCategory->id,
103
+ 'name' => $addonCategory->name,
104
+ 'excluded_addons' => $addonCategory->excluded_addons,
105
+ 'category' => $addonCategory->category,
106
+ 'created_at' => $addonCategory->created_at,
107
+ 'updated_at' => $addonCategory->updated_at,
108
+ ];
109
+ } else {
110
+ return [
111
+ 'id' => data_get($addonCategory, 'category.public_id'),
112
+ 'name' => data_get($addonCategory, 'name'),
113
+ 'description' => data_get($addonCategory, 'category.description'),
114
+ 'excluded_addons' => $addonCategory->excluded_addons,
115
+ 'addons' => $this->mapProductAddons($addons, $addonCategory->excluded_addons),
116
+ ];
109
117
  }
110
118
 
111
- return $addonCategoryArr;
119
+ return [];
112
120
  });
113
121
  }
114
122
 
115
- public function mapProductAddons(?\Illuminate\Database\Eloquent\Collection $addons = null, $excluded = [])
123
+ public function mapProductAddons(\Illuminate\Database\Eloquent\Collection $addons = null, $excluded = [])
116
124
  {
117
125
  return collect($addons)->map(function ($addon) use ($excluded) {
118
126
  if (is_array($excluded) && in_array($addon->uuid, $excluded)) {
@@ -120,15 +128,15 @@ class Product extends FleetbaseResource
120
128
  }
121
129
 
122
130
  $productAddonArr = [
123
- 'id' => $addon->public_id,
124
- 'name' => $addon->name,
131
+ 'id' => $addon->public_id,
132
+ 'name' => $addon->name,
125
133
  'description' => $addon->description,
126
- 'price' => $addon->price,
127
- 'sale_price' => $addon->sale_price,
128
- 'is_on_sale' => $addon->is_on_sale,
129
- 'slug' => $addon->slug,
130
- 'created_at' => $addon->created_at,
131
- 'updated_at' => $addon->updated_at
134
+ 'price' => $addon->price,
135
+ 'sale_price' => $addon->sale_price,
136
+ 'is_on_sale' => $addon->is_on_sale,
137
+ 'slug' => $addon->slug,
138
+ 'created_at' => $addon->created_at,
139
+ 'updated_at' => $addon->updated_at,
132
140
  ];
133
141
 
134
142
  // modify for internal requests
@@ -138,8 +146,8 @@ class Product extends FleetbaseResource
138
146
  $productAddonArr = Arr::insertAfterKey(
139
147
  $productAddonArr,
140
148
  [
141
- 'uuid' => $addon->uuid,
142
- 'public_id' => $addon->public_id
149
+ 'uuid' => $addon->uuid,
150
+ 'public_id' => $addon->public_id,
143
151
  ],
144
152
  'id'
145
153
  );
@@ -149,24 +157,24 @@ class Product extends FleetbaseResource
149
157
  })->filter()->values();
150
158
  }
151
159
 
152
- public function mapVariants(?\Illuminate\Database\Eloquent\Collection $variants = null)
160
+ public function mapVariants(\Illuminate\Database\Eloquent\Collection $variants = null)
153
161
  {
154
162
  return collect($variants)->map(function ($variant) {
155
163
  $productVariantArr = [
156
- 'id' => $variant->public_id,
157
- 'name' => $variant->name,
158
- 'description' => $variant->description,
164
+ 'id' => $variant->public_id,
165
+ 'name' => $variant->name,
166
+ 'description' => $variant->description,
159
167
  'is_multiselect' => $variant->is_multiselect,
160
- 'is_required' => $variant->is_required,
161
- 'slug' => $variant->slug,
162
- 'options' => collect($variant->options)->map(function ($variantOpt) {
168
+ 'is_required' => $variant->is_required,
169
+ 'slug' => $variant->slug,
170
+ 'options' => collect($variant->options)->map(function ($variantOpt) {
163
171
  $variantOptArr = [
164
- 'id' => $variantOpt->public_id,
165
- 'name' => $variantOpt->name,
166
- 'description' => $variantOpt->description,
172
+ 'id' => $variantOpt->public_id,
173
+ 'name' => $variantOpt->name,
174
+ 'description' => $variantOpt->description,
167
175
  'additional_cost' => $variantOpt->additional_cost,
168
- 'created_at' => $variantOpt->created_at,
169
- 'updated_at' => $variantOpt->updated_at
176
+ 'created_at' => $variantOpt->created_at,
177
+ 'updated_at' => $variantOpt->updated_at,
170
178
  ];
171
179
 
172
180
  // modify for internal requests
@@ -176,8 +184,8 @@ class Product extends FleetbaseResource
176
184
  $variantOptArr = Arr::insertAfterKey(
177
185
  $variantOptArr,
178
186
  [
179
- 'uuid' => $variantOpt->uuid,
180
- 'public_id' => $variantOpt->public_id
187
+ 'uuid' => $variantOpt->uuid,
188
+ 'public_id' => $variantOpt->public_id,
181
189
  ],
182
190
  'id'
183
191
  );
@@ -186,7 +194,7 @@ class Product extends FleetbaseResource
186
194
  return $variantOptArr;
187
195
  }),
188
196
  'created_at' => $variant->created_at,
189
- 'updated_at' => $variant->updated_at
197
+ 'updated_at' => $variant->updated_at,
190
198
  ];
191
199
 
192
200
  // modify for internal requests
@@ -196,8 +204,8 @@ class Product extends FleetbaseResource
196
204
  $productVariantArr = Arr::insertAfterKey(
197
205
  $productVariantArr,
198
206
  [
199
- 'uuid' => $variant->uuid,
200
- 'public_id' => $variant->public_id
207
+ 'uuid' => $variant->uuid,
208
+ 'public_id' => $variant->public_id,
201
209
  ],
202
210
  'id'
203
211
  );