@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
@@ -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
  }
@@ -10,30 +10,31 @@ class Cart 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
- 'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
23
- 'user_uuid' => $this->when(Http::isInternalRequest(), $this->user_uuid),
24
- 'checkout_uuid' => $this->when(Http::isInternalRequest(), $this->checkout_uuid),
25
- 'checkout_uuid' => $this->when(Http::isInternalRequest(), $this->checkout_uuid),
26
- 'customer_id' => $this->customer_id,
27
- 'currency' => $this->currency,
28
- 'subtotal' => $this->subtotal,
29
- '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,
30
31
  'total_unique_items' => $this->total_unique_items,
31
- 'items' => $this->items ?? [],
32
- 'events' => $this->events ?? [],
33
- 'discount_code' => $this->discount_code,
34
- 'expires_at' => $this->expires_at,
35
- 'created_at' => $this->created_at,
36
- '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,
37
38
  ];
38
39
  }
39
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,43 +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
- 'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
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),
24
25
  'created_by_uuid' => $this->when(Http::isInternalRequest(), $this->created_by_uuid),
25
- 'logo_uuid' => $this->when(Http::isInternalRequest(), $this->logo_uuid),
26
- 'backdrop_uuid' => $this->when(Http::isInternalRequest(), $this->backdrop_uuid),
27
- 'name' => $this->name,
28
- 'description' => $this->description,
29
- 'translations' => $this->translations ?? [],
30
- 'website' => $this->website,
31
- 'facebook' => $this->facebook,
32
- 'instagram' => $this->instagram,
33
- 'twitter' => $this->twitter,
34
- 'email' => $this->email,
35
- 'phone' => $this->phone,
36
- 'tags' => $this->tags ?? [],
37
- 'currency' => $this->currency ?? 'USD',
38
- 'options' => $this->options ?? [],
39
- 'logo_url' => $this->logo_url,
40
- 'backdrop_url' => $this->backdrop_url,
41
- 'rating' => $this->rating,
42
- 'online' => $this->online,
43
- 'stores' => $this->when($request->boolean('with_stores') || $request->inArray('with', 'stores'), Store::collection($this->stores)),
44
- 'categories' => $this->when($request->boolean('with_categories') || $request->inArray('with', 'categories'), Category::collection($this->categories)),
45
- 'is_network' => true,
46
- 'is_store' => false,
47
- 'slug' => $this->slug,
48
- 'created_at' => $this->created_at,
49
- 'updated_at' => $this->updated_at,
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,
50
51
  ];
51
52
  }
52
53
  }
@@ -12,49 +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
- 'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
25
- 'store_uuid' => $this->when(Http::isInternalRequest(), $this->store_uuid),
26
- 'category_uuid' => $this->when(Http::isInternalRequest(), $this->category_uuid),
27
- 'created_by_uuid' => $this->when(Http::isInternalRequest(), $this->created_by_uuid),
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),
28
29
  'primary_image_uuid' => $this->when(Http::isInternalRequest(), $this->primary_image_uuid),
29
- 'name' => $this->name,
30
- 'description' => $this->description,
31
- 'sku' => $this->sku,
32
- 'primary_image_url' => $this->primary_image_url,
33
- 'price' => $this->price,
34
- 'sale_price' => $this->sale_price,
35
- 'currency' => $this->currency,
36
- 'is_on_sale' => $this->is_on_sale,
37
- 'is_recommended' => $this->is_recommended,
38
- 'is_service' => $this->is_service,
39
- 'is_bookable' => $this->is_bookable,
40
- 'is_available' => $this->is_available,
41
- 'tags' => $this->tags ?? [],
42
- 'status' => $this->status,
43
- 'slug' => $this->slug,
44
- 'translations' => $this->translations ?? [],
45
- 'addon_categories' => $this->mapAddonCategories($this->addonCategories),
46
- 'variants' => $this->mapVariants($this->variants),
47
- 'files' => $this->when(Http::isInternalRequest(), $this->files),
48
- 'images' => $this->when(!Http::isInternalRequest(), $this->mapFiles($this->files)),
49
- 'videos' => $this->when(!Http::isInternalRequest(), $this->mapFiles($this->files, 'video')),
50
- 'hours' => $this->mapHours($this->hours),
51
- 'youtube_urls' => $this->youtube_urls ?? [],
52
- 'created_at' => $this->created_at,
53
- 'updated_at' => $this->updated_at,
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,
54
55
  ];
55
56
  }
56
57
 
57
- public function mapHours(?\Illuminate\Database\Eloquent\Collection $hours = null): array
58
+ public function mapHours(\Illuminate\Database\Eloquent\Collection $hours = null): array
58
59
  {
59
60
  if (empty($hours)) {
60
61
  return [];
@@ -64,21 +65,21 @@ class Product extends FleetbaseResource
64
65
  function ($hour) {
65
66
  // modify for internal requests
66
67
  if (Http::isInternalRequest()) {
67
- $hour['id'] = data_get($hour, 'id');
68
+ $hour['id'] = data_get($hour, 'id');
68
69
  $hour['uuid'] = data_get($hour, 'uuid');
69
70
  }
70
71
 
71
72
  return array_merge($hour, [
72
- 'day' => data_get($hour, 'day_of_week'),
73
+ 'day' => data_get($hour, 'day_of_week'),
73
74
  'start' => data_get($hour, 'start'),
74
- 'end' => data_get($hour, 'end'),
75
+ 'end' => data_get($hour, 'end'),
75
76
  ]);
76
77
  },
77
78
  $hours->toArray()
78
79
  );
79
80
  }
80
81
 
81
- public function mapFiles(?\Illuminate\Database\Eloquent\Collection $files = null, $contentType = 'image')
82
+ public function mapFiles(\Illuminate\Database\Eloquent\Collection $files = null, $contentType = 'image')
82
83
  {
83
84
  return collect($files)->map(function ($file) use ($contentType) {
84
85
  if (!Str::contains($file->content_type, $contentType)) {
@@ -89,35 +90,37 @@ class Product extends FleetbaseResource
89
90
  })->filter()->values();
90
91
  }
91
92
 
92
- public function mapAddonCategories(?\Illuminate\Database\Eloquent\Collection $addonCategories = null)
93
+ public function mapAddonCategories(\Illuminate\Database\Eloquent\Collection $addonCategories = null)
93
94
  {
94
95
  return collect($addonCategories)->map(function ($addonCategory) {
95
- $addonCategoryArr = [
96
- 'id' => $addonCategory->category->public_id ?? null,
97
- 'name' => $addonCategory->name,
98
- 'description' => $addonCategory->category->description ?? null,
99
- 'addons' => $this->mapProductAddons($addonCategory->category->addons ?? [], $addonCategory->excluded_addons)
100
- ];
96
+ $addons = data_get($addonCategory, 'category.addons', []);
101
97
 
102
- // modify for internal requests
103
98
  if (Http::isInternalRequest()) {
104
- $addonCategoryArr['id'] = $addonCategory->category->id;
105
-
106
- $addonCategoryArr = Arr::insertAfterKey(
107
- $addonCategoryArr,
108
- [
109
- 'uuid' => $addonCategory->category->uuid,
110
- 'public_id' => $addonCategory->category->public_id
111
- ],
112
- 'id'
113
- );
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
+ ];
114
117
  }
115
118
 
116
- return $addonCategoryArr;
119
+ return [];
117
120
  });
118
121
  }
119
122
 
120
- public function mapProductAddons(?\Illuminate\Database\Eloquent\Collection $addons = null, $excluded = [])
123
+ public function mapProductAddons(\Illuminate\Database\Eloquent\Collection $addons = null, $excluded = [])
121
124
  {
122
125
  return collect($addons)->map(function ($addon) use ($excluded) {
123
126
  if (is_array($excluded) && in_array($addon->uuid, $excluded)) {
@@ -125,15 +128,15 @@ class Product extends FleetbaseResource
125
128
  }
126
129
 
127
130
  $productAddonArr = [
128
- 'id' => $addon->public_id,
129
- 'name' => $addon->name,
131
+ 'id' => $addon->public_id,
132
+ 'name' => $addon->name,
130
133
  'description' => $addon->description,
131
- 'price' => $addon->price,
132
- 'sale_price' => $addon->sale_price,
133
- 'is_on_sale' => $addon->is_on_sale,
134
- 'slug' => $addon->slug,
135
- 'created_at' => $addon->created_at,
136
- '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,
137
140
  ];
138
141
 
139
142
  // modify for internal requests
@@ -143,8 +146,8 @@ class Product extends FleetbaseResource
143
146
  $productAddonArr = Arr::insertAfterKey(
144
147
  $productAddonArr,
145
148
  [
146
- 'uuid' => $addon->uuid,
147
- 'public_id' => $addon->public_id
149
+ 'uuid' => $addon->uuid,
150
+ 'public_id' => $addon->public_id,
148
151
  ],
149
152
  'id'
150
153
  );
@@ -154,24 +157,24 @@ class Product extends FleetbaseResource
154
157
  })->filter()->values();
155
158
  }
156
159
 
157
- public function mapVariants(?\Illuminate\Database\Eloquent\Collection $variants = null)
160
+ public function mapVariants(\Illuminate\Database\Eloquent\Collection $variants = null)
158
161
  {
159
162
  return collect($variants)->map(function ($variant) {
160
163
  $productVariantArr = [
161
- 'id' => $variant->public_id,
162
- 'name' => $variant->name,
163
- 'description' => $variant->description,
164
+ 'id' => $variant->public_id,
165
+ 'name' => $variant->name,
166
+ 'description' => $variant->description,
164
167
  'is_multiselect' => $variant->is_multiselect,
165
- 'is_required' => $variant->is_required,
166
- 'slug' => $variant->slug,
167
- '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) {
168
171
  $variantOptArr = [
169
- 'id' => $variantOpt->public_id,
170
- 'name' => $variantOpt->name,
171
- 'description' => $variantOpt->description,
172
+ 'id' => $variantOpt->public_id,
173
+ 'name' => $variantOpt->name,
174
+ 'description' => $variantOpt->description,
172
175
  'additional_cost' => $variantOpt->additional_cost,
173
- 'created_at' => $variantOpt->created_at,
174
- 'updated_at' => $variantOpt->updated_at
176
+ 'created_at' => $variantOpt->created_at,
177
+ 'updated_at' => $variantOpt->updated_at,
175
178
  ];
176
179
 
177
180
  // modify for internal requests
@@ -181,8 +184,8 @@ class Product extends FleetbaseResource
181
184
  $variantOptArr = Arr::insertAfterKey(
182
185
  $variantOptArr,
183
186
  [
184
- 'uuid' => $variantOpt->uuid,
185
- 'public_id' => $variantOpt->public_id
187
+ 'uuid' => $variantOpt->uuid,
188
+ 'public_id' => $variantOpt->public_id,
186
189
  ],
187
190
  'id'
188
191
  );
@@ -191,7 +194,7 @@ class Product extends FleetbaseResource
191
194
  return $variantOptArr;
192
195
  }),
193
196
  'created_at' => $variant->created_at,
194
- 'updated_at' => $variant->updated_at
197
+ 'updated_at' => $variant->updated_at,
195
198
  ];
196
199
 
197
200
  // modify for internal requests
@@ -201,8 +204,8 @@ class Product extends FleetbaseResource
201
204
  $productVariantArr = Arr::insertAfterKey(
202
205
  $productVariantArr,
203
206
  [
204
- 'uuid' => $variant->uuid,
205
- 'public_id' => $variant->public_id
207
+ 'uuid' => $variant->uuid,
208
+ 'public_id' => $variant->public_id,
206
209
  ],
207
210
  'id'
208
211
  );