@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.
- package/addon/controllers/products/index/category/new.js +5 -9
- package/addon/models/product-addon-category.js +10 -1
- package/addon/models/product-variant.js +0 -2
- package/addon/models/product.js +35 -2
- package/addon/serializers/product.js +16 -0
- package/addon/templates/products/index/category/new.hbs +2 -2
- package/composer.json +3 -3
- package/extension.json +1 -1
- package/package.json +132 -132
- package/server/src/Auth/Schemas/Storefront.php +31 -39
- package/server/src/Console/Commands/NotifyStorefrontOrderNearby.php +9 -11
- package/server/src/Expansions/ContactFilterExpansion.php +1 -1
- package/server/src/Expansions/EntityExpansion.php +12 -12
- package/server/src/Expansions/OrderFilterExpansion.php +1 -1
- package/server/src/Expansions/VendorFilterExpansion.php +1 -1
- package/server/src/Http/Controllers/ActionController.php +9 -11
- package/server/src/Http/Controllers/AddonCategoryController.php +1 -1
- package/server/src/Http/Controllers/CustomerController.php +1 -1
- package/server/src/Http/Controllers/GatewayController.php +1 -1
- package/server/src/Http/Controllers/MetricsController.php +17 -17
- package/server/src/Http/Controllers/NetworkController.php +16 -26
- package/server/src/Http/Controllers/NotificationChannelController.php +1 -1
- package/server/src/Http/Controllers/OrderController.php +18 -22
- package/server/src/Http/Controllers/ProductAddonCategoryController.php +1 -2
- package/server/src/Http/Controllers/ProductAddonController.php +1 -2
- package/server/src/Http/Controllers/ProductController.php +89 -44
- package/server/src/Http/Controllers/ProductHourController.php +1 -1
- package/server/src/Http/Controllers/ProductVariantController.php +1 -1
- package/server/src/Http/Controllers/ProductVariantOptionController.php +1 -1
- package/server/src/Http/Controllers/ReviewController.php +1 -1
- package/server/src/Http/Controllers/StoreController.php +1 -2
- package/server/src/Http/Controllers/StoreHourController.php +1 -1
- package/server/src/Http/Controllers/StoreLocationController.php +1 -1
- package/server/src/Http/Controllers/StorefrontController.php +0 -2
- package/server/src/Http/Controllers/VoteController.php +1 -1
- package/server/src/Http/Controllers/v1/CartController.php +16 -26
- package/server/src/Http/Controllers/v1/CategoryController.php +3 -4
- package/server/src/Http/Controllers/v1/CheckoutController.php +283 -286
- package/server/src/Http/Controllers/v1/CustomerController.php +54 -67
- package/server/src/Http/Controllers/v1/GatewayControllerController.php +0 -2
- package/server/src/Http/Controllers/v1/NetworkController.php +26 -23
- package/server/src/Http/Controllers/v1/PaymentMethodController.php +0 -2
- package/server/src/Http/Controllers/v1/ProductController.php +1 -4
- package/server/src/Http/Controllers/v1/ReviewController.php +31 -35
- package/server/src/Http/Controllers/v1/ServiceQuoteController.php +57 -53
- package/server/src/Http/Controllers/v1/StoreController.php +8 -16
- package/server/src/Http/Filter/AddonCategoryFilter.php +1 -1
- package/server/src/Http/Filter/OrderFilter.php +2 -2
- package/server/src/Http/Middleware/SetStorefrontSession.php +9 -20
- package/server/src/Http/Requests/AddStoreToNetworkCategory.php +3 -3
- package/server/src/Http/Requests/CreateCustomerRequest.php +5 -7
- package/server/src/Http/Requests/CreateReviewRequest.php +4 -5
- package/server/src/Http/Requests/GetServiceQuoteFromCart.php +2 -2
- package/server/src/Http/Requests/InitializeCheckoutRequest.php +5 -5
- package/server/src/Http/Requests/NetworkActionRequest.php +2 -2
- package/server/src/Http/Requests/VerifyCreateCustomerRequest.php +2 -2
- package/server/src/Http/Resources/Cart.php +19 -18
- package/server/src/Http/Resources/Category.php +12 -11
- package/server/src/Http/Resources/Customer.php +15 -14
- package/server/src/Http/Resources/Gateway.php +12 -11
- package/server/src/Http/Resources/Media.php +9 -8
- package/server/src/Http/Resources/Network.php +32 -31
- package/server/src/Http/Resources/Product.php +88 -85
- package/server/src/Http/Resources/Review.php +14 -13
- package/server/src/Http/Resources/ReviewCustomer.php +12 -11
- package/server/src/Http/Resources/Store.php +38 -36
- package/server/src/Http/Resources/StoreHour.php +9 -8
- package/server/src/Http/Resources/StoreLocation.php +9 -8
- package/server/src/Imports/ProductsImport.php +0 -2
- package/server/src/Jobs/DownloadProductImageUrl.php +7 -4
- package/server/src/Listeners/HandleOrderCompleted.php +2 -1
- package/server/src/Listeners/HandleOrderDispatched.php +2 -1
- package/server/src/Listeners/HandleOrderDriverAssigned.php +2 -1
- package/server/src/Listeners/HandleOrderStarted.php +4 -3
- package/server/src/Mail/StorefrontNetworkInvite.php +7 -6
- package/server/src/Models/AddonCategory.php +2 -4
- package/server/src/Models/Cart.php +117 -124
- package/server/src/Models/Checkout.php +14 -12
- package/server/src/Models/Customer.php +9 -9
- package/server/src/Models/Gateway.php +22 -22
- package/server/src/Models/Network.php +41 -52
- package/server/src/Models/NetworkStore.php +6 -5
- package/server/src/Models/NotificationChannel.php +11 -9
- package/server/src/Models/PaymentMethod.php +9 -7
- package/server/src/Models/Product.php +152 -30
- package/server/src/Models/ProductAddon.php +14 -11
- package/server/src/Models/ProductAddonCategory.php +9 -8
- package/server/src/Models/ProductHour.php +6 -5
- package/server/src/Models/ProductStoreLocation.php +7 -5
- package/server/src/Models/ProductVariant.php +15 -11
- package/server/src/Models/ProductVariantOption.php +12 -9
- package/server/src/Models/Review.php +9 -7
- package/server/src/Models/Store.php +68 -84
- package/server/src/Models/StoreHour.php +6 -5
- package/server/src/Models/StoreLocation.php +12 -8
- package/server/src/Models/StorefrontModel.php +1 -1
- package/server/src/Models/Vote.php +8 -6
- package/server/src/Notifications/StorefrontOrderCanceled.php +15 -19
- package/server/src/Notifications/StorefrontOrderCompleted.php +15 -19
- package/server/src/Notifications/StorefrontOrderCreated.php +31 -36
- package/server/src/Notifications/StorefrontOrderDriverAssigned.php +15 -20
- package/server/src/Notifications/StorefrontOrderEnroute.php +14 -19
- package/server/src/Notifications/StorefrontOrderNearby.php +16 -21
- package/server/src/Notifications/StorefrontOrderPreparing.php +15 -18
- package/server/src/Notifications/StorefrontOrderReadyForPickup.php +15 -18
- package/server/src/Observers/NetworkObserver.php +2 -3
- package/server/src/Observers/ProductObserver.php +17 -33
- package/server/src/Providers/EventServiceProvider.php +15 -4
- package/server/src/Providers/StorefrontServiceProvider.php +8 -10
- package/server/src/Support/Metrics.php +12 -12
- package/server/src/Support/OrderConfig.php +3 -2
- package/server/src/Support/QPay.php +22 -20
- package/server/src/Support/Storefront.php +18 -17
- 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'
|
|
30
|
+
'origin' => $this->isStoreKey() ? ['required', new IsValidLocation()] : [],
|
|
31
31
|
'destination' => ['required', new IsValidLocation()],
|
|
32
|
-
'cart'
|
|
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'
|
|
31
|
-
'customer'
|
|
32
|
-
'cart'
|
|
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'
|
|
35
|
-
'pickup'
|
|
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
|
|
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
|
}
|
|
@@ -10,30 +10,31 @@ class Cart extends FleetbaseResource
|
|
|
10
10
|
/**
|
|
11
11
|
* Transform the resource into an array.
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
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'
|
|
20
|
-
'uuid'
|
|
21
|
-
'public_id'
|
|
22
|
-
'company_uuid'
|
|
23
|
-
'user_uuid'
|
|
24
|
-
'checkout_uuid'
|
|
25
|
-
'checkout_uuid'
|
|
26
|
-
'customer_id'
|
|
27
|
-
'currency'
|
|
28
|
-
'subtotal'
|
|
29
|
-
'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'
|
|
32
|
-
'events'
|
|
33
|
-
'discount_code'
|
|
34
|
-
'expires_at'
|
|
35
|
-
'created_at'
|
|
36
|
-
'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
|
|
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'
|
|
20
|
-
'uuid'
|
|
21
|
-
'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'
|
|
24
|
-
'parent'
|
|
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'
|
|
31
|
-
'translations'
|
|
32
|
-
'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'
|
|
43
|
-
'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
|
|
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'
|
|
21
|
-
'uuid'
|
|
22
|
-
'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'
|
|
25
|
-
'photo_url'
|
|
26
|
-
'email'
|
|
27
|
-
'phone'
|
|
28
|
-
'address'
|
|
29
|
-
'addresses'
|
|
30
|
-
'token'
|
|
31
|
-
'slug'
|
|
32
|
-
'created_at'
|
|
33
|
-
'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
|
|
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'
|
|
20
|
-
'uuid'
|
|
21
|
-
'public_id'
|
|
22
|
-
'name'
|
|
23
|
-
'description'
|
|
24
|
-
'logo_url'
|
|
25
|
-
'code'
|
|
26
|
-
'type'
|
|
27
|
-
'sandbox'
|
|
28
|
-
'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
|
|
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'
|
|
20
|
-
'uuid'
|
|
21
|
-
'filename'
|
|
22
|
-
'type'
|
|
23
|
-
'caption'
|
|
24
|
-
'url'
|
|
25
|
-
'created_at' => $this->when(Http::isInternalRequest(),
|
|
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
|
|
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'
|
|
20
|
-
'uuid'
|
|
21
|
-
'public_id'
|
|
22
|
-
'key'
|
|
23
|
-
'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'
|
|
26
|
-
'backdrop_uuid'
|
|
27
|
-
'name'
|
|
28
|
-
'description'
|
|
29
|
-
'translations'
|
|
30
|
-
'website'
|
|
31
|
-
'facebook'
|
|
32
|
-
'instagram'
|
|
33
|
-
'twitter'
|
|
34
|
-
'email'
|
|
35
|
-
'phone'
|
|
36
|
-
'tags'
|
|
37
|
-
'currency'
|
|
38
|
-
'options'
|
|
39
|
-
'logo_url'
|
|
40
|
-
'backdrop_url'
|
|
41
|
-
'rating'
|
|
42
|
-
'online'
|
|
43
|
-
'stores'
|
|
44
|
-
'categories'
|
|
45
|
-
'is_network'
|
|
46
|
-
'is_store'
|
|
47
|
-
'slug'
|
|
48
|
-
'created_at'
|
|
49
|
-
'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
|
|
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'
|
|
22
|
-
'uuid'
|
|
23
|
-
'public_id'
|
|
24
|
-
'company_uuid'
|
|
25
|
-
'store_uuid'
|
|
26
|
-
'category_uuid'
|
|
27
|
-
'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'
|
|
30
|
-
'description'
|
|
31
|
-
'sku'
|
|
32
|
-
'primary_image_url'
|
|
33
|
-
'price'
|
|
34
|
-
'sale_price'
|
|
35
|
-
'currency'
|
|
36
|
-
'is_on_sale'
|
|
37
|
-
'is_recommended'
|
|
38
|
-
'is_service'
|
|
39
|
-
'is_bookable'
|
|
40
|
-
'is_available'
|
|
41
|
-
'tags'
|
|
42
|
-
'status'
|
|
43
|
-
'slug'
|
|
44
|
-
'translations'
|
|
45
|
-
'addon_categories'
|
|
46
|
-
'variants'
|
|
47
|
-
'files'
|
|
48
|
-
'images'
|
|
49
|
-
'videos'
|
|
50
|
-
'hours'
|
|
51
|
-
'youtube_urls'
|
|
52
|
-
'created_at'
|
|
53
|
-
'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(
|
|
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']
|
|
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'
|
|
73
|
+
'day' => data_get($hour, 'day_of_week'),
|
|
73
74
|
'start' => data_get($hour, 'start'),
|
|
74
|
-
'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(
|
|
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(
|
|
93
|
+
public function mapAddonCategories(\Illuminate\Database\Eloquent\Collection $addonCategories = null)
|
|
93
94
|
{
|
|
94
95
|
return collect($addonCategories)->map(function ($addonCategory) {
|
|
95
|
-
$
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
$
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
'
|
|
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
|
|
119
|
+
return [];
|
|
117
120
|
});
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
public function mapProductAddons(
|
|
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'
|
|
129
|
-
'name'
|
|
131
|
+
'id' => $addon->public_id,
|
|
132
|
+
'name' => $addon->name,
|
|
130
133
|
'description' => $addon->description,
|
|
131
|
-
'price'
|
|
132
|
-
'sale_price'
|
|
133
|
-
'is_on_sale'
|
|
134
|
-
'slug'
|
|
135
|
-
'created_at'
|
|
136
|
-
'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'
|
|
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(
|
|
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'
|
|
162
|
-
'name'
|
|
163
|
-
'description'
|
|
164
|
+
'id' => $variant->public_id,
|
|
165
|
+
'name' => $variant->name,
|
|
166
|
+
'description' => $variant->description,
|
|
164
167
|
'is_multiselect' => $variant->is_multiselect,
|
|
165
|
-
'is_required'
|
|
166
|
-
'slug'
|
|
167
|
-
'options'
|
|
168
|
+
'is_required' => $variant->is_required,
|
|
169
|
+
'slug' => $variant->slug,
|
|
170
|
+
'options' => collect($variant->options)->map(function ($variantOpt) {
|
|
168
171
|
$variantOptArr = [
|
|
169
|
-
'id'
|
|
170
|
-
'name'
|
|
171
|
-
'description'
|
|
172
|
+
'id' => $variantOpt->public_id,
|
|
173
|
+
'name' => $variantOpt->name,
|
|
174
|
+
'description' => $variantOpt->description,
|
|
172
175
|
'additional_cost' => $variantOpt->additional_cost,
|
|
173
|
-
'created_at'
|
|
174
|
-
'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'
|
|
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'
|
|
205
|
-
'public_id' => $variant->public_id
|
|
207
|
+
'uuid' => $variant->uuid,
|
|
208
|
+
'public_id' => $variant->public_id,
|
|
206
209
|
],
|
|
207
210
|
'id'
|
|
208
211
|
);
|