@fleetbase/storefront-engine 0.1.7 → 0.1.9
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/.php-cs-fixer.php +29 -0
- package/LICENSE.md +16 -4
- package/README.md +106 -13
- package/composer.json +88 -0
- package/extension.json +10 -0
- package/package.json +6 -6
- package/phpstan.neon.dist +8 -0
- package/phpunit.xml.dist +16 -0
- package/server/.gitattributes +14 -0
- package/server/README.md +40 -0
- package/server/config/api.php +101 -0
- package/server/config/database.connections.php +57 -0
- package/server/config/storefront.php +19 -0
- package/server/config/twilio-notification-channel.php +36 -0
- package/server/migrations/2023_05_03_025307_create_carts_table.php +44 -0
- package/server/migrations/2023_05_03_025307_create_checkouts_table.php +51 -0
- package/server/migrations/2023_05_03_025307_create_gateways_table.php +48 -0
- package/server/migrations/2023_05_03_025307_create_network_stores_table.php +36 -0
- package/server/migrations/2023_05_03_025307_create_networks_table.php +56 -0
- package/server/migrations/2023_05_03_025307_create_notification_channels_table.php +43 -0
- package/server/migrations/2023_05_03_025307_create_payment_methods_table.php +44 -0
- package/server/migrations/2023_05_03_025307_create_product_addon_categories_table.php +38 -0
- package/server/migrations/2023_05_03_025307_create_product_addons_table.php +43 -0
- package/server/migrations/2023_05_03_025307_create_product_hours_table.php +37 -0
- package/server/migrations/2023_05_03_025307_create_product_store_locations_table.php +34 -0
- package/server/migrations/2023_05_03_025307_create_product_variant_options_table.php +40 -0
- package/server/migrations/2023_05_03_025307_create_product_variants_table.php +44 -0
- package/server/migrations/2023_05_03_025307_create_products_table.php +59 -0
- package/server/migrations/2023_05_03_025307_create_reviews_table.php +41 -0
- package/server/migrations/2023_05_03_025307_create_store_hours_table.php +37 -0
- package/server/migrations/2023_05_03_025307_create_store_locations_table.php +38 -0
- package/server/migrations/2023_05_03_025307_create_stores_table.php +57 -0
- package/server/migrations/2023_05_03_025307_create_votes_table.php +39 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_carts_table.php +40 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_checkouts_table.php +48 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_gateways_table.php +40 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_network_stores_table.php +40 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_networks_table.php +42 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_notification_channels_table.php +40 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_payment_methods_table.php +40 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_addon_categories_table.php +38 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_addons_table.php +38 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_hours_table.php +32 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_store_locations_table.php +34 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_variant_options_table.php +32 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_variants_table.php +32 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_products_table.php +44 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_reviews_table.php +38 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_store_hours_table.php +32 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_store_locations_table.php +40 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_stores_table.php +42 -0
- package/server/migrations/2023_05_03_025310_add_foreign_keys_to_votes_table.php +38 -0
- package/server/src/Auth/Schemas/Storefront.php +95 -0
- package/server/src/Console/Commands/NotifyStorefrontOrderNearby.php +86 -0
- package/server/src/Expansions/EntityExpansion.php +44 -0
- package/server/src/Http/Controllers/ActionController.php +119 -0
- package/server/src/Http/Controllers/AddonCategoryController.php +13 -0
- package/server/src/Http/Controllers/CustomerController.php +13 -0
- package/server/src/Http/Controllers/GatewayController.php +13 -0
- package/server/src/Http/Controllers/MetricsController.php +71 -0
- package/server/src/Http/Controllers/NetworkController.php +170 -0
- package/server/src/Http/Controllers/NotificationChannelController.php +13 -0
- package/server/src/Http/Controllers/OrderController.php +154 -0
- package/server/src/Http/Controllers/ProductAddonCategoryController.php +14 -0
- package/server/src/Http/Controllers/ProductAddonController.php +14 -0
- package/server/src/Http/Controllers/ProductController.php +123 -0
- package/server/src/Http/Controllers/ProductHourController.php +13 -0
- package/server/src/Http/Controllers/ProductVariantController.php +13 -0
- package/server/src/Http/Controllers/ProductVariantOptionController.php +13 -0
- package/server/src/Http/Controllers/ReviewController.php +13 -0
- package/server/src/Http/Controllers/StoreController.php +26 -0
- package/server/src/Http/Controllers/StoreHourController.php +13 -0
- package/server/src/Http/Controllers/StoreLocationController.php +13 -0
- package/server/src/Http/Controllers/StorefrontController.php +15 -0
- package/server/src/Http/Controllers/VoteController.php +13 -0
- package/server/src/Http/Controllers/v1/CartController.php +161 -0
- package/server/src/Http/Controllers/v1/CategoryController.php +138 -0
- package/server/src/Http/Controllers/v1/CheckoutController.php +957 -0
- package/server/src/Http/Controllers/v1/CustomerController.php +482 -0
- package/server/src/Http/Controllers/v1/GatewayControllerController.php +11 -0
- package/server/src/Http/Controllers/v1/NetworkController.php +281 -0
- package/server/src/Http/Controllers/v1/PaymentMethodController.php +11 -0
- package/server/src/Http/Controllers/v1/ProductController.php +94 -0
- package/server/src/Http/Controllers/v1/ReviewController.php +270 -0
- package/server/src/Http/Controllers/v1/ServiceQuoteController.php +402 -0
- package/server/src/Http/Controllers/v1/StoreController.php +176 -0
- package/server/src/Http/Filter/AddonCategoryFilter.php +19 -0
- package/server/src/Http/Filter/CustomerFilter.php +18 -0
- package/server/src/Http/Filter/GatewayFilter.php +13 -0
- package/server/src/Http/Filter/NetworkFilter.php +18 -0
- package/server/src/Http/Filter/NotificationChannelFilter.php +13 -0
- package/server/src/Http/Filter/OrderFilter.php +46 -0
- package/server/src/Http/Filter/ProductFilter.php +28 -0
- package/server/src/Http/Filter/StoreFilter.php +42 -0
- package/server/src/Http/Filter/StoreLocationFilter.php +23 -0
- package/server/src/Http/Middleware/SetStorefrontSession.php +130 -0
- package/server/src/Http/Requests/AddStoreToNetworkCategory.php +45 -0
- package/server/src/Http/Requests/CaptureOrderRequest.php +30 -0
- package/server/src/Http/Requests/CreateCustomerRequest.php +44 -0
- package/server/src/Http/Requests/CreateReviewRequest.php +34 -0
- package/server/src/Http/Requests/GetServiceQuoteFromCart.php +40 -0
- package/server/src/Http/Requests/InitializeCheckoutRequest.php +38 -0
- package/server/src/Http/Requests/NetworkActionRequest.php +43 -0
- package/server/src/Http/Requests/VerifyCreateCustomerRequest.php +31 -0
- package/server/src/Http/Resources/Cart.php +31 -0
- package/server/src/Http/Resources/Category.php +48 -0
- package/server/src/Http/Resources/Customer.php +36 -0
- package/server/src/Http/Resources/Gateway.php +32 -0
- package/server/src/Http/Resources/Media.php +29 -0
- package/server/src/Http/Resources/Network.php +48 -0
- package/server/src/Http/Resources/Product.php +209 -0
- package/server/src/Http/Resources/Review.php +45 -0
- package/server/src/Http/Resources/ReviewCustomer.php +60 -0
- package/server/src/Http/Resources/Store.php +76 -0
- package/server/src/Http/Resources/StoreHour.php +29 -0
- package/server/src/Http/Resources/StoreLocation.php +33 -0
- package/server/src/Imports/ProductsImport.php +20 -0
- package/server/src/Jobs/DownloadProductImageUrl.php +60 -0
- package/server/src/Listeners/HandleOrderCompleted.php +31 -0
- package/server/src/Listeners/HandleOrderDispatched.php +34 -0
- package/server/src/Listeners/HandleOrderDriverAssigned.php +37 -0
- package/server/src/Listeners/HandleOrderStarted.php +27 -0
- package/server/src/Mail/StorefrontNetworkInvite.php +48 -0
- package/server/src/Models/AddonCategory.php +30 -0
- package/server/src/Models/Cart.php +691 -0
- package/server/src/Models/Checkout.php +166 -0
- package/server/src/Models/Customer.php +88 -0
- package/server/src/Models/Gateway.php +165 -0
- package/server/src/Models/Network.php +300 -0
- package/server/src/Models/NetworkStore.php +86 -0
- package/server/src/Models/NotificationChannel.php +147 -0
- package/server/src/Models/PaymentMethod.php +99 -0
- package/server/src/Models/Product.php +315 -0
- package/server/src/Models/ProductAddon.php +128 -0
- package/server/src/Models/ProductAddonCategory.php +90 -0
- package/server/src/Models/ProductHour.php +59 -0
- package/server/src/Models/ProductStoreLocation.php +77 -0
- package/server/src/Models/ProductVariant.php +125 -0
- package/server/src/Models/ProductVariantOption.php +86 -0
- package/server/src/Models/Review.php +127 -0
- package/server/src/Models/Store.php +478 -0
- package/server/src/Models/StoreHour.php +59 -0
- package/server/src/Models/StoreLocation.php +126 -0
- package/server/src/Models/StorefrontModel.php +22 -0
- package/server/src/Models/Vote.php +84 -0
- package/server/src/Notifications/StorefrontOrderCanceled.php +196 -0
- package/server/src/Notifications/StorefrontOrderCompleted.php +201 -0
- package/server/src/Notifications/StorefrontOrderCreated.php +157 -0
- package/server/src/Notifications/StorefrontOrderDriverAssigned.php +200 -0
- package/server/src/Notifications/StorefrontOrderEnroute.php +199 -0
- package/server/src/Notifications/StorefrontOrderNearby.php +201 -0
- package/server/src/Notifications/StorefrontOrderPreparing.php +202 -0
- package/server/src/Notifications/StorefrontOrderReadyForPickup.php +202 -0
- package/server/src/Observers/NetworkObserver.php +40 -0
- package/server/src/Observers/ProductObserver.php +118 -0
- package/server/src/Providers/EventServiceProvider.php +23 -0
- package/server/src/Providers/StorefrontServiceProvider.php +103 -0
- package/server/src/Support/Metrics.php +193 -0
- package/server/src/Support/OrderConfig.php +13 -0
- package/server/src/Support/QPay.php +208 -0
- package/server/src/Support/Storefront.php +201 -0
- package/server/src/routes.php +180 -0
- package/server/tests/Feature.php +5 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Models;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Casts\Json;
|
|
6
|
+
use Fleetbase\Models\Category;
|
|
7
|
+
use Fleetbase\Models\User;
|
|
8
|
+
use Fleetbase\Models\Company;
|
|
9
|
+
use Fleetbase\Models\File;
|
|
10
|
+
use Fleetbase\Models\Invite;
|
|
11
|
+
use Fleetbase\FleetOps\Support\Utils;
|
|
12
|
+
use Fleetbase\Traits\HasOptionsAttributes;
|
|
13
|
+
use Fleetbase\Traits\HasUuid;
|
|
14
|
+
use Fleetbase\Traits\HasApiModelBehavior;
|
|
15
|
+
use Fleetbase\Traits\HasPublicid;
|
|
16
|
+
use Fleetbase\Traits\Searchable;
|
|
17
|
+
use Illuminate\Support\Str;
|
|
18
|
+
use Spatie\Sluggable\HasSlug;
|
|
19
|
+
use Spatie\Sluggable\SlugOptions;
|
|
20
|
+
|
|
21
|
+
class Network extends StorefrontModel
|
|
22
|
+
{
|
|
23
|
+
use HasUuid, HasPublicId, HasApiModelBehavior, HasOptionsAttributes, HasSlug, Searchable;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The type of public Id to generate
|
|
27
|
+
*
|
|
28
|
+
* @var string
|
|
29
|
+
*/
|
|
30
|
+
protected $publicIdType = 'network';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The database table used by the model.
|
|
34
|
+
*
|
|
35
|
+
* @var string
|
|
36
|
+
*/
|
|
37
|
+
protected $table = 'networks';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* These attributes that can be queried
|
|
41
|
+
*
|
|
42
|
+
* @var array
|
|
43
|
+
*/
|
|
44
|
+
protected $searchableColumns = ['name', 'description'];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The attributes that are mass assignable.
|
|
48
|
+
*
|
|
49
|
+
* @var array
|
|
50
|
+
*/
|
|
51
|
+
protected $fillable = ['created_by_uuid', 'company_uuid', 'logo_uuid', 'backdrop_uuid', 'key', 'online', 'name', 'description', 'website', 'facebook', 'instagram', 'twitter', 'email', 'phone', 'translations', 'tags', 'currency', 'timezone', 'pod_method', 'options', 'alertable', 'slug'];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The attributes that should be cast to native types.
|
|
55
|
+
*
|
|
56
|
+
* @var array
|
|
57
|
+
*/
|
|
58
|
+
protected $casts = [
|
|
59
|
+
'options' => Json::class,
|
|
60
|
+
'translations' => Json::class,
|
|
61
|
+
'alertable' => Json::class,
|
|
62
|
+
'tags' => 'array',
|
|
63
|
+
'online' => 'boolean'
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Dynamic attributes that are appended to object
|
|
68
|
+
*
|
|
69
|
+
* @var array
|
|
70
|
+
*/
|
|
71
|
+
protected $appends = ['logo_url', 'backdrop_url', 'stores_count'];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The attributes excluded from the model's JSON form.
|
|
75
|
+
*
|
|
76
|
+
* @var array
|
|
77
|
+
*/
|
|
78
|
+
protected $hidden = ['logo', 'backdrop', 'files', 'media'];
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @var \Spatie\Sluggable\SlugOptions
|
|
82
|
+
*/
|
|
83
|
+
public function getSlugOptions(): SlugOptions
|
|
84
|
+
{
|
|
85
|
+
return SlugOptions::create()
|
|
86
|
+
->generateSlugsFrom('name')
|
|
87
|
+
->saveSlugsTo('slug');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** on boot generate key */
|
|
91
|
+
public static function boot()
|
|
92
|
+
{
|
|
93
|
+
parent::boot();
|
|
94
|
+
static::creating(function ($model) {
|
|
95
|
+
$model->key = 'network_' . md5(Str::random(14) . time());
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
101
|
+
*/
|
|
102
|
+
public function createdBy()
|
|
103
|
+
{
|
|
104
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(User::class);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
109
|
+
*/
|
|
110
|
+
public function company()
|
|
111
|
+
{
|
|
112
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Company::class);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
117
|
+
*/
|
|
118
|
+
public function logo()
|
|
119
|
+
{
|
|
120
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(File::class);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
125
|
+
*/
|
|
126
|
+
public function backdrop()
|
|
127
|
+
{
|
|
128
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(File::class);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
133
|
+
*/
|
|
134
|
+
public function files()
|
|
135
|
+
{
|
|
136
|
+
return $this->setConnection(config('fleetbase.connection.db'))->hasMany(File::class, 'subject_uuid');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
141
|
+
*/
|
|
142
|
+
public function media()
|
|
143
|
+
{
|
|
144
|
+
return $this->files()->where('type', 'storefront_network_media');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
|
149
|
+
*/
|
|
150
|
+
public function stores()
|
|
151
|
+
{
|
|
152
|
+
return $this->belongsToMany(Store::class, 'network_stores', 'network_uuid', 'store_uuid')
|
|
153
|
+
->using(NetworkStore::class)
|
|
154
|
+
->withPivot('category_uuid');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
159
|
+
*/
|
|
160
|
+
public function notificationChannels()
|
|
161
|
+
{
|
|
162
|
+
return $this->hasMany(NotificationChannel::class, 'owner_uuid');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
167
|
+
*/
|
|
168
|
+
public function gateways()
|
|
169
|
+
{
|
|
170
|
+
return $this->hasMany(Gateway::class, 'owner_uuid');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
175
|
+
*/
|
|
176
|
+
public function invitations()
|
|
177
|
+
{
|
|
178
|
+
return $this->setConnection(config('fleetbase.connection.db'))->hasMany(Invite::class, 'subject_uuid');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
183
|
+
*/
|
|
184
|
+
public function categories()
|
|
185
|
+
{
|
|
186
|
+
return $this->setConnection(config('fleetbase.connection.db'))->hasMany(Category::class, 'owner_uuid')->where(['for' => 'network_category']);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @var string
|
|
191
|
+
*/
|
|
192
|
+
public function getLogoUrlAttribute()
|
|
193
|
+
{
|
|
194
|
+
// return static::attributeFromCache($this, 'logo.url', 'https://flb-assets.s3.ap-southeast-1.amazonaws.com/static/image-file-icon.png');
|
|
195
|
+
return $this->logo->url ?? 'https://flb-assets.s3.ap-southeast-1.amazonaws.com/static/image-file-icon.png';
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* @var string
|
|
200
|
+
*/
|
|
201
|
+
public function getBackdropUrlAttribute()
|
|
202
|
+
{
|
|
203
|
+
// return static::attributeFromCache($this, 'backdrop.url', 'https://flb-assets.s3.ap-southeast-1.amazonaws.com/static/default-storefront-backdrop.png');
|
|
204
|
+
return $this->backdrop->url ?? 'https://flb-assets.s3.ap-southeast-1.amazonaws.com/static/default-storefront-backdrop.png';
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @var integer
|
|
209
|
+
*/
|
|
210
|
+
public function getStoresCountAttribute()
|
|
211
|
+
{
|
|
212
|
+
return $this->stores()->count();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Adds a new store to the network
|
|
217
|
+
*
|
|
218
|
+
* @param Store $store
|
|
219
|
+
* @param Category|null $category
|
|
220
|
+
* @return NetworkStore
|
|
221
|
+
*/
|
|
222
|
+
public function addStore(Store $store, ?Category $category = null): NetworkStore
|
|
223
|
+
{
|
|
224
|
+
return NetworkStore::updateOrCreate(
|
|
225
|
+
[
|
|
226
|
+
'network_uuid' => $this->uuid,
|
|
227
|
+
'store_uuid' => $store->uuid
|
|
228
|
+
],
|
|
229
|
+
[
|
|
230
|
+
'network_uuid' => $this->uuid,
|
|
231
|
+
'store_uuid' => $store->uuid,
|
|
232
|
+
'category_uuid' => $category instanceof Category ? $category->uuid : null
|
|
233
|
+
]
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
*'Create a new network store category for this store record
|
|
239
|
+
*
|
|
240
|
+
* @param string $name
|
|
241
|
+
* @param string $description
|
|
242
|
+
* @param array|null $meta
|
|
243
|
+
* @param array|null $translations
|
|
244
|
+
* @param Category|null $parent
|
|
245
|
+
* @param File|string|null $icon
|
|
246
|
+
* @param string $iconColor
|
|
247
|
+
* @return Category
|
|
248
|
+
*/
|
|
249
|
+
public function createCategory(string $name, string $description = '', ?array $meta = [], ?array $translations = [], ?Category $parent = null, $icon = null, $iconColor = '#000000'): Category
|
|
250
|
+
{
|
|
251
|
+
$iconFile = null;
|
|
252
|
+
$iconName = null;
|
|
253
|
+
|
|
254
|
+
if ($icon instanceof File) {
|
|
255
|
+
$iconFile = $icon;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (is_string($icon)) {
|
|
259
|
+
$iconName = $icon;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return Category::create([
|
|
263
|
+
'company_uuid' => $this->company_uuid,
|
|
264
|
+
'owner_uuid' => $this->uuid,
|
|
265
|
+
'owner_type' => Utils::getMutationType('network:storefront'),
|
|
266
|
+
'parent_uuid' => $parent instanceof Category ? $parent->uuid : null,
|
|
267
|
+
'icon_file_uuid' => $iconFile->uuid,
|
|
268
|
+
'for' => 'storefront_network',
|
|
269
|
+
'name' => $name,
|
|
270
|
+
'description' => $description,
|
|
271
|
+
'translations' => $translations,
|
|
272
|
+
'meta' => $meta,
|
|
273
|
+
'icon' => $iconName,
|
|
274
|
+
'icon_color' => $iconColor
|
|
275
|
+
]);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Create a new network store category if it doesn't already exists for this store record
|
|
280
|
+
*
|
|
281
|
+
* @param string $name
|
|
282
|
+
* @param string $description
|
|
283
|
+
* @param array|null $meta
|
|
284
|
+
* @param array|null $translations
|
|
285
|
+
* @param Category|null $parent
|
|
286
|
+
* @param File|string|null $icon
|
|
287
|
+
* @param string $iconColor
|
|
288
|
+
* @return Category
|
|
289
|
+
*/
|
|
290
|
+
public function createCategoryStrict(string $name, string $description = '', ?array $meta = [], ?array $translations = [], ?Category $parent = null, $icon = null, $iconColor = '#000000'): Category
|
|
291
|
+
{
|
|
292
|
+
$existingCategory = Category::where(['company_uuid' => $this->company_uuid, 'owner_uuid' => $this->uuid, 'name' => $name])->first();
|
|
293
|
+
|
|
294
|
+
if ($existingCategory) {
|
|
295
|
+
return $existingCategory;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return $this->createCategory($name, $description, $meta, $translations, $parent, $icon, $iconColor);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Models;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Models\Category;
|
|
6
|
+
use Fleetbase\Traits\HasUuid;
|
|
7
|
+
use Fleetbase\Traits\HasApiModelBehavior;
|
|
8
|
+
use Illuminate\Database\Eloquent\Relations\Pivot;
|
|
9
|
+
|
|
10
|
+
class NetworkStore extends Pivot
|
|
11
|
+
{
|
|
12
|
+
use HasUuid, HasApiModelBehavior;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The database table used by the model.
|
|
16
|
+
*
|
|
17
|
+
* @var string
|
|
18
|
+
*/
|
|
19
|
+
protected $table = 'network_stores';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* These attributes that can be queried
|
|
23
|
+
*
|
|
24
|
+
* @var array
|
|
25
|
+
*/
|
|
26
|
+
protected $searchableColumns = [];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The attributes that are mass assignable.
|
|
30
|
+
*
|
|
31
|
+
* @var array
|
|
32
|
+
*/
|
|
33
|
+
protected $fillable = ['network_uuid', 'store_uuid', 'category_uuid'];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The attributes that should be cast to native types.
|
|
37
|
+
*
|
|
38
|
+
* @var array
|
|
39
|
+
*/
|
|
40
|
+
protected $casts = [];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Dynamic attributes that are appended to object
|
|
44
|
+
*
|
|
45
|
+
* @var array
|
|
46
|
+
*/
|
|
47
|
+
protected $appends = [];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Create a new instance of the model.
|
|
51
|
+
*
|
|
52
|
+
* @param array $attributes The attributes to set on the model.
|
|
53
|
+
*
|
|
54
|
+
* @return void
|
|
55
|
+
*/
|
|
56
|
+
public function __construct(array $attributes = [])
|
|
57
|
+
{
|
|
58
|
+
parent::__construct($attributes);
|
|
59
|
+
|
|
60
|
+
$this->connection = config('storefront.connection.db');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
65
|
+
*/
|
|
66
|
+
public function network()
|
|
67
|
+
{
|
|
68
|
+
return $this->belongsTo(Network::class);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
73
|
+
*/
|
|
74
|
+
public function store()
|
|
75
|
+
{
|
|
76
|
+
return $this->belongsTo(Store::class);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
81
|
+
*/
|
|
82
|
+
public function category()
|
|
83
|
+
{
|
|
84
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Category::class);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Models;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Casts\Json;
|
|
6
|
+
use Fleetbase\Casts\PolymorphicType;
|
|
7
|
+
use Fleetbase\Models\User;
|
|
8
|
+
use Fleetbase\Models\Company;
|
|
9
|
+
use Fleetbase\FleetOps\Support\Utils;
|
|
10
|
+
use Fleetbase\Traits\HasOptionsAttributes;
|
|
11
|
+
use Fleetbase\Traits\HasUuid;
|
|
12
|
+
use Fleetbase\Traits\HasApiModelBehavior;
|
|
13
|
+
use Illuminate\Support\Str;
|
|
14
|
+
|
|
15
|
+
class NotificationChannel extends StorefrontModel
|
|
16
|
+
{
|
|
17
|
+
use HasUuid, HasApiModelBehavior, HasOptionsAttributes;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The database table used by the model.
|
|
21
|
+
*
|
|
22
|
+
* @var string
|
|
23
|
+
*/
|
|
24
|
+
protected $table = 'notification_channels';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* These attributes that can be queried
|
|
28
|
+
*
|
|
29
|
+
* @var array
|
|
30
|
+
*/
|
|
31
|
+
protected $searchableColumns = ['name', 'scheme'];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The attributes that are mass assignable.
|
|
35
|
+
*
|
|
36
|
+
* @var array
|
|
37
|
+
*/
|
|
38
|
+
protected $fillable = ['created_by_uuid', 'company_uuid', 'certificate_uuid', 'owner_uuid', 'owner_type', 'name', 'scheme', 'app_key', 'config', 'options'];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The attributes that should be cast to native types.
|
|
42
|
+
*
|
|
43
|
+
* @var array
|
|
44
|
+
*/
|
|
45
|
+
protected $casts = [
|
|
46
|
+
// 'config' => Json::class,
|
|
47
|
+
'options' => Json::class,
|
|
48
|
+
'owner_type' => PolymorphicType::class
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Dynamic attributes that are appended to object
|
|
53
|
+
*
|
|
54
|
+
* @var array
|
|
55
|
+
*/
|
|
56
|
+
protected $appends = [];
|
|
57
|
+
|
|
58
|
+
/** on boot generate key */
|
|
59
|
+
public static function boot()
|
|
60
|
+
{
|
|
61
|
+
parent::boot();
|
|
62
|
+
static::creating(function ($model) {
|
|
63
|
+
$model->app_key = 'noty_channel_' . md5(Str::random(14) . time());
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
69
|
+
*/
|
|
70
|
+
public function createdBy()
|
|
71
|
+
{
|
|
72
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(User::class);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
77
|
+
*/
|
|
78
|
+
public function company()
|
|
79
|
+
{
|
|
80
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Company::class);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
85
|
+
*/
|
|
86
|
+
public function certificate()
|
|
87
|
+
{
|
|
88
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(File::class);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
93
|
+
*/
|
|
94
|
+
public function owner()
|
|
95
|
+
{
|
|
96
|
+
return $this->morphTo(__FUNCTION__, 'owner_type', 'owner_uuid');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Sets the owner type
|
|
101
|
+
*/
|
|
102
|
+
public function setOwnerTypeAttribute($type)
|
|
103
|
+
{
|
|
104
|
+
$this->attributes['owner_type'] = Utils::getMutationType($type);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public function setConfigAttribute($config)
|
|
108
|
+
{
|
|
109
|
+
if (is_array($config) && isset($config['private_key_content'])) {
|
|
110
|
+
$config['private_key_content'] = trim($config['private_key_content']);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
$json = json_encode($config);
|
|
114
|
+
// $json = str_replace("\\n", "", $json);
|
|
115
|
+
|
|
116
|
+
$this->attributes['config'] = $json;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public function getConfigAttribute($config)
|
|
120
|
+
{
|
|
121
|
+
$config = json_decode($config, true);
|
|
122
|
+
// $config = Json::decode($config);
|
|
123
|
+
|
|
124
|
+
$sortedKeys = collect($config)->keys()->sort(function ($key) use ($config) {
|
|
125
|
+
$item = Utils::get($config, $key);
|
|
126
|
+
|
|
127
|
+
return Utils::isBooleanValue($item) ? 1 : 0;
|
|
128
|
+
});
|
|
129
|
+
$sortedConfig = [];
|
|
130
|
+
|
|
131
|
+
foreach ($sortedKeys as $key) {
|
|
132
|
+
$sortedConfig[$key] = $config[$key];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return (object) $sortedConfig;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public function getIsApnGatewayAttribute()
|
|
139
|
+
{
|
|
140
|
+
return $this->scheme === 'apn';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public function getIsFcmGatewayAttribute()
|
|
144
|
+
{
|
|
145
|
+
return $this->scheme === 'fcm';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Models;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Casts\Json;
|
|
6
|
+
use Fleetbase\Models\User;
|
|
7
|
+
use Fleetbase\Models\Company;
|
|
8
|
+
use Fleetbase\Traits\HasUuid;
|
|
9
|
+
use Fleetbase\Traits\HasApiModelBehavior;
|
|
10
|
+
use Fleetbase\Traits\HasPublicid;
|
|
11
|
+
|
|
12
|
+
class PaymentMethod extends StorefrontModel
|
|
13
|
+
{
|
|
14
|
+
use HasUuid, HasPublicid, HasApiModelBehavior;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The type of public Id to generate
|
|
18
|
+
*
|
|
19
|
+
* @var string
|
|
20
|
+
*/
|
|
21
|
+
protected $publicIdType = 'payment_method';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The database table used by the model.
|
|
25
|
+
*
|
|
26
|
+
* @var string
|
|
27
|
+
*/
|
|
28
|
+
protected $table = 'payment_methods';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* These attributes that can be queried
|
|
32
|
+
*
|
|
33
|
+
* @var array
|
|
34
|
+
*/
|
|
35
|
+
protected $searchableColumns = [];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The attributes that are mass assignable.
|
|
39
|
+
*
|
|
40
|
+
* @var array
|
|
41
|
+
*/
|
|
42
|
+
protected $fillable = ['company_uuid', 'created_by_uuid', 'gateway_uuid', 'store_uuid', 'owner_uuid', 'owner_type', 'gateway_id', 'type', 'brand', 'last4', 'meta'];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The attributes that should be cast to native types.
|
|
46
|
+
*
|
|
47
|
+
* @var array
|
|
48
|
+
*/
|
|
49
|
+
protected $casts = [
|
|
50
|
+
'meta' => Json::class
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Dynamic attributes that are appended to object
|
|
55
|
+
*
|
|
56
|
+
* @var array
|
|
57
|
+
*/
|
|
58
|
+
protected $appends = [];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
62
|
+
*/
|
|
63
|
+
public function createdBy()
|
|
64
|
+
{
|
|
65
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(User::class);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
70
|
+
*/
|
|
71
|
+
public function company()
|
|
72
|
+
{
|
|
73
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Company::class);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
78
|
+
*/
|
|
79
|
+
public function owner()
|
|
80
|
+
{
|
|
81
|
+
return $this->setConnection(config('fleetbase.connection.db'))->morphTo(__FUNCTION__, 'owner_type', 'owner_uuid')->withoutGlobalScopes();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
86
|
+
*/
|
|
87
|
+
public function store()
|
|
88
|
+
{
|
|
89
|
+
return $this->belongsTo(Store::class);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
94
|
+
*/
|
|
95
|
+
public function gateway()
|
|
96
|
+
{
|
|
97
|
+
return $this->belongsTo(Gateway::class);
|
|
98
|
+
}
|
|
99
|
+
}
|