@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,315 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Models;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Casts\Json;
|
|
6
|
+
use Fleetbase\Models\Category;
|
|
7
|
+
use Fleetbase\Models\File;
|
|
8
|
+
use Fleetbase\Models\User;
|
|
9
|
+
use Fleetbase\FleetOps\Support\Utils;
|
|
10
|
+
use Fleetbase\Traits\HasMetaAttributes;
|
|
11
|
+
use Fleetbase\Traits\HasUuid;
|
|
12
|
+
use Fleetbase\Traits\HasApiModelBehavior;
|
|
13
|
+
use Fleetbase\Traits\HasPublicid;
|
|
14
|
+
use Fleetbase\Traits\Searchable;
|
|
15
|
+
use Illuminate\Support\Str;
|
|
16
|
+
use Spatie\Sluggable\HasSlug;
|
|
17
|
+
use Spatie\Sluggable\SlugOptions;
|
|
18
|
+
use Milon\Barcode\Facades\DNS2DFacade as DNS2D;
|
|
19
|
+
|
|
20
|
+
class ProductStatus
|
|
21
|
+
{
|
|
22
|
+
public const AVAILABLE = 'available';
|
|
23
|
+
public const DRAFT = 'draft';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class Product extends StorefrontModel
|
|
27
|
+
{
|
|
28
|
+
use HasUuid, HasPublicid, HasApiModelBehavior, HasMetaAttributes, HasSlug, Searchable;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The type of public Id to generate
|
|
32
|
+
*
|
|
33
|
+
* @var string
|
|
34
|
+
*/
|
|
35
|
+
protected $publicIdType = 'product';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The database table used by the model.
|
|
39
|
+
*
|
|
40
|
+
* @var string
|
|
41
|
+
*/
|
|
42
|
+
protected $table = 'products';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* These attributes that can be queried
|
|
46
|
+
*
|
|
47
|
+
* @var array
|
|
48
|
+
*/
|
|
49
|
+
protected $searchableColumns = ['name', 'description'];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The attributes that are mass assignable.
|
|
53
|
+
*
|
|
54
|
+
* @var array
|
|
55
|
+
*/
|
|
56
|
+
protected $fillable = [
|
|
57
|
+
'company_uuid',
|
|
58
|
+
'primary_image_uuid',
|
|
59
|
+
'created_by_uuid',
|
|
60
|
+
'store_uuid',
|
|
61
|
+
'category_uuid',
|
|
62
|
+
'name',
|
|
63
|
+
'description',
|
|
64
|
+
'tags',
|
|
65
|
+
'translations',
|
|
66
|
+
'meta',
|
|
67
|
+
'qr_code',
|
|
68
|
+
'barcode',
|
|
69
|
+
'youtube_urls',
|
|
70
|
+
'sku',
|
|
71
|
+
'price',
|
|
72
|
+
'currency',
|
|
73
|
+
'sale_price',
|
|
74
|
+
'is_service',
|
|
75
|
+
'is_bookable',
|
|
76
|
+
'is_available',
|
|
77
|
+
'is_on_sale',
|
|
78
|
+
'is_recommended',
|
|
79
|
+
'can_pickup',
|
|
80
|
+
'status',
|
|
81
|
+
'slug'
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The attributes that should be cast to native types.
|
|
86
|
+
*
|
|
87
|
+
* @var array
|
|
88
|
+
*/
|
|
89
|
+
protected $casts = [
|
|
90
|
+
'is_service' => 'boolean',
|
|
91
|
+
'is_bookable' => 'boolean',
|
|
92
|
+
'is_on_sale' => 'boolean',
|
|
93
|
+
'is_available' => 'boolean',
|
|
94
|
+
'is_recommended' => 'boolean',
|
|
95
|
+
'can_pickup' => 'boolean',
|
|
96
|
+
'tags' => 'array',
|
|
97
|
+
'meta' => Json::class,
|
|
98
|
+
'translations' => Json::class,
|
|
99
|
+
'youtube_urls' => Json::class
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Dynamic attributes that are appended to object
|
|
104
|
+
*
|
|
105
|
+
* @var array
|
|
106
|
+
*/
|
|
107
|
+
protected $appends = ['primary_image_url', 'store_id', 'meta_array'];
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Attributes that is filterable on this model
|
|
111
|
+
*
|
|
112
|
+
* @var array
|
|
113
|
+
*/
|
|
114
|
+
protected $filterParams = ['category_slug', 'category'];
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Generates QR Code & Barcode on creation.
|
|
118
|
+
*
|
|
119
|
+
* @return void
|
|
120
|
+
*/
|
|
121
|
+
public static function boot()
|
|
122
|
+
{
|
|
123
|
+
parent::boot();
|
|
124
|
+
static::creating(function ($model) {
|
|
125
|
+
$model->qr_code = DNS2D::getBarcodePNG($model->uuid, 'QRCODE');
|
|
126
|
+
$model->barcode = DNS2D::getBarcodePNG($model->uuid, 'PDF417');
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @var \Spatie\Sluggable\SlugOptions
|
|
132
|
+
*/
|
|
133
|
+
public function getSlugOptions(): SlugOptions
|
|
134
|
+
{
|
|
135
|
+
return SlugOptions::create()
|
|
136
|
+
->generateSlugsFrom('name')
|
|
137
|
+
->saveSlugsTo('slug');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
142
|
+
*/
|
|
143
|
+
public function createdBy()
|
|
144
|
+
{
|
|
145
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(User::class);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
150
|
+
*/
|
|
151
|
+
public function category()
|
|
152
|
+
{
|
|
153
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Category::class);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
158
|
+
*/
|
|
159
|
+
public function addonCategories()
|
|
160
|
+
{
|
|
161
|
+
return $this->hasMany(ProductAddonCategory::class);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
166
|
+
*/
|
|
167
|
+
public function variants()
|
|
168
|
+
{
|
|
169
|
+
return $this->hasMany(ProductVariant::class);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
174
|
+
*/
|
|
175
|
+
public function primaryImage()
|
|
176
|
+
{
|
|
177
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(File::class);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
182
|
+
*/
|
|
183
|
+
public function files()
|
|
184
|
+
{
|
|
185
|
+
return $this->setConnection(config('fleetbase.connection.db'))->hasMany(File::class, 'subject_uuid');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
190
|
+
*/
|
|
191
|
+
public function reviews()
|
|
192
|
+
{
|
|
193
|
+
return $this->hasMany(Review::class, 'subject_uuid');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
198
|
+
*/
|
|
199
|
+
public function votes()
|
|
200
|
+
{
|
|
201
|
+
return $this->hasMany(Vote::class, 'subject_uuid');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
206
|
+
*/
|
|
207
|
+
public function hours()
|
|
208
|
+
{
|
|
209
|
+
return $this->hasMany(ProductHour::class);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
214
|
+
*/
|
|
215
|
+
public function store()
|
|
216
|
+
{
|
|
217
|
+
return $this->belongsTo(Store::class);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @return array
|
|
222
|
+
*/
|
|
223
|
+
public function getMetaArrayAttribute()
|
|
224
|
+
{
|
|
225
|
+
$_meta = [];
|
|
226
|
+
|
|
227
|
+
if (empty($this->meta)) {
|
|
228
|
+
return $_meta;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
foreach ($this->meta as $key => $value) {
|
|
232
|
+
$_meta[] = [
|
|
233
|
+
'key' => Str::snake($key),
|
|
234
|
+
'label' => Utils::smartHumanize($key),
|
|
235
|
+
'value' => $value
|
|
236
|
+
];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return $_meta;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @return string
|
|
244
|
+
*/
|
|
245
|
+
public function getPrimaryImageUrlAttribute()
|
|
246
|
+
{
|
|
247
|
+
$default = $this->primaryImage->url ?? null;
|
|
248
|
+
$secondary = $this->files->first()->url ?? null;
|
|
249
|
+
$backup = 'https://flb-assets.s3.ap-southeast-1.amazonaws.com/static/image-file-icon.png';
|
|
250
|
+
|
|
251
|
+
return $default ?? $secondary ?? $backup;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @return string
|
|
256
|
+
*/
|
|
257
|
+
public function getStoreIdAttribute()
|
|
258
|
+
{
|
|
259
|
+
return static::attributeFromCache($this, 'store.public_id', function () {
|
|
260
|
+
return $this->store()->select(['public_id'])->first()->public_id;
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Set the price as only numbers
|
|
266
|
+
*
|
|
267
|
+
* @void
|
|
268
|
+
*/
|
|
269
|
+
public function setPriceAttribute($value)
|
|
270
|
+
{
|
|
271
|
+
$this->attributes['price'] = Utils::numbersOnly($value);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Set the sale price as only numbers
|
|
276
|
+
*
|
|
277
|
+
* @void
|
|
278
|
+
*/
|
|
279
|
+
public function setSalePriceAttribute($value)
|
|
280
|
+
{
|
|
281
|
+
$this->attributes['sale_price'] = Utils::numbersOnly($value);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Finds products that match the specified search query, store, and network.
|
|
286
|
+
*
|
|
287
|
+
* @param string $search The search query to use to find products.
|
|
288
|
+
* @param string|null $store The store to search for products in. If null, all stores are searched.
|
|
289
|
+
* @param int $limit The maximum number of products to return.
|
|
290
|
+
* @param string|null $network The network to search for products on. If null, the session network is used.
|
|
291
|
+
*
|
|
292
|
+
* @return \Illuminate\Database\Eloquent\Collection The collection of products that match the search query, store, and network.
|
|
293
|
+
*/
|
|
294
|
+
public static function findFromNetwork($search, $store = null, $limit = 20, $network = null): ?\Illuminate\Database\Eloquent\Collection
|
|
295
|
+
{
|
|
296
|
+
$network = session('storefront_network', $network);
|
|
297
|
+
|
|
298
|
+
$results = static::whereHas('store', function ($query) use ($network, $store) {
|
|
299
|
+
if ($store) {
|
|
300
|
+
$query->where('public_id', $store);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
$query->whereHas('networks', function ($networksQuery) use ($network) {
|
|
304
|
+
$networksQuery->where('network_uuid', $network);
|
|
305
|
+
});
|
|
306
|
+
})
|
|
307
|
+
->search($search)
|
|
308
|
+
->whereIsAvailable(1)
|
|
309
|
+
->whereStatus('published')
|
|
310
|
+
->limit($limit)
|
|
311
|
+
->get();
|
|
312
|
+
|
|
313
|
+
return $results;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
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\FleetOps\Support\Utils;
|
|
9
|
+
use Fleetbase\Traits\HasUuid;
|
|
10
|
+
use Fleetbase\Traits\HasApiModelBehavior;
|
|
11
|
+
use Fleetbase\Traits\HasPublicid;
|
|
12
|
+
use Spatie\Sluggable\HasSlug;
|
|
13
|
+
use Spatie\Sluggable\SlugOptions;
|
|
14
|
+
|
|
15
|
+
class ProductAddon extends StorefrontModel
|
|
16
|
+
{
|
|
17
|
+
use HasUuid, HasPublicid, HasApiModelBehavior, HasSlug;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The type of public Id to generate
|
|
21
|
+
*
|
|
22
|
+
* @var string
|
|
23
|
+
*/
|
|
24
|
+
protected $publicIdType = 'addon';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The database table used by the model.
|
|
28
|
+
*
|
|
29
|
+
* @var string
|
|
30
|
+
*/
|
|
31
|
+
protected $table = 'product_addons';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* These attributes that can be queried
|
|
35
|
+
*
|
|
36
|
+
* @var array
|
|
37
|
+
*/
|
|
38
|
+
protected $searchableColumns = ['name', 'description'];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The attributes that are mass assignable.
|
|
42
|
+
*
|
|
43
|
+
* @var array
|
|
44
|
+
*/
|
|
45
|
+
protected $fillable = [
|
|
46
|
+
'public_id',
|
|
47
|
+
'created_by_uuid',
|
|
48
|
+
'category_uuid',
|
|
49
|
+
'name',
|
|
50
|
+
'description',
|
|
51
|
+
'translations',
|
|
52
|
+
'price',
|
|
53
|
+
'sale_price',
|
|
54
|
+
'is_on_sale',
|
|
55
|
+
'slug'
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The attributes that should be cast to native types.
|
|
60
|
+
*
|
|
61
|
+
* @var array
|
|
62
|
+
*/
|
|
63
|
+
protected $casts = [
|
|
64
|
+
'is_on_sale' => 'boolean',
|
|
65
|
+
'translations' => Json::class
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Dynamic attributes that are appended to object
|
|
70
|
+
*
|
|
71
|
+
* @var array
|
|
72
|
+
*/
|
|
73
|
+
protected $appends = [];
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @var \Spatie\Sluggable\SlugOptions
|
|
77
|
+
*/
|
|
78
|
+
public function getSlugOptions(): SlugOptions
|
|
79
|
+
{
|
|
80
|
+
return SlugOptions::create()
|
|
81
|
+
->generateSlugsFrom('name')
|
|
82
|
+
->saveSlugsTo('slug');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
87
|
+
*/
|
|
88
|
+
public function createdBy()
|
|
89
|
+
{
|
|
90
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(User::class);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
95
|
+
*/
|
|
96
|
+
public function category()
|
|
97
|
+
{
|
|
98
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Category::class);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
103
|
+
*/
|
|
104
|
+
public function store()
|
|
105
|
+
{
|
|
106
|
+
return $this->belongsTo(Store::class);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Set the price as only numbers
|
|
111
|
+
*
|
|
112
|
+
* @void
|
|
113
|
+
*/
|
|
114
|
+
public function setPriceAttribute($value)
|
|
115
|
+
{
|
|
116
|
+
$this->attributes['price'] = Utils::numbersOnly($value);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Set the sale price as only numbers
|
|
121
|
+
*
|
|
122
|
+
* @void
|
|
123
|
+
*/
|
|
124
|
+
public function setSalePriceAttribute($value)
|
|
125
|
+
{
|
|
126
|
+
$this->attributes['sale_price'] = Utils::numbersOnly($value);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Models;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Casts\Json;
|
|
6
|
+
use Fleetbase\Traits\HasUuid;
|
|
7
|
+
use Fleetbase\Traits\HasApiModelBehavior;
|
|
8
|
+
|
|
9
|
+
class ProductAddonCategory extends StorefrontModel
|
|
10
|
+
{
|
|
11
|
+
use HasUuid, HasApiModelBehavior;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The database table used by the model.
|
|
15
|
+
*
|
|
16
|
+
* @var string
|
|
17
|
+
*/
|
|
18
|
+
protected $table = 'product_addon_categories';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* These attributes that can be queried
|
|
22
|
+
*
|
|
23
|
+
* @var array
|
|
24
|
+
*/
|
|
25
|
+
protected $searchableColumns = [];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The attributes that are mass assignable.
|
|
29
|
+
*
|
|
30
|
+
* @var array
|
|
31
|
+
*/
|
|
32
|
+
protected $fillable = [
|
|
33
|
+
'product_uuid',
|
|
34
|
+
'category_uuid',
|
|
35
|
+
'exluded_addons',
|
|
36
|
+
'max_selectable'
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The attributes that should be cast to native types.
|
|
41
|
+
*
|
|
42
|
+
* @var array
|
|
43
|
+
*/
|
|
44
|
+
protected $casts = [
|
|
45
|
+
'exluded_addons' => Json::class
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Dynamic attributes that are appended to object
|
|
50
|
+
*
|
|
51
|
+
* @var array
|
|
52
|
+
*/
|
|
53
|
+
protected $appends = ['name'];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Dynamic attributes should be hidden
|
|
57
|
+
*
|
|
58
|
+
* @var array
|
|
59
|
+
*/
|
|
60
|
+
protected $hidden = ['product'];
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
64
|
+
*/
|
|
65
|
+
public function category()
|
|
66
|
+
{
|
|
67
|
+
return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(AddonCategory::class)->with(['addons']);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
72
|
+
*/
|
|
73
|
+
public function product()
|
|
74
|
+
{
|
|
75
|
+
return $this->belongsTo(Product::class);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @var string
|
|
80
|
+
*/
|
|
81
|
+
public function getNameAttribute()
|
|
82
|
+
{
|
|
83
|
+
return static::attributeFromCache($this, 'category.name');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public function getExcludedAddonsAttribute($excluded)
|
|
87
|
+
{
|
|
88
|
+
return Json::decode($excluded);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Models;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Traits\HasUuid;
|
|
6
|
+
use Fleetbase\Traits\HasApiModelBehavior;
|
|
7
|
+
|
|
8
|
+
class ProductHour extends StorefrontModel
|
|
9
|
+
{
|
|
10
|
+
use HasUuid, HasApiModelBehavior;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The database table used by the model.
|
|
14
|
+
*
|
|
15
|
+
* @var string
|
|
16
|
+
*/
|
|
17
|
+
protected $table = 'product_hours';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* These attributes that can be queried
|
|
21
|
+
*
|
|
22
|
+
* @var array
|
|
23
|
+
*/
|
|
24
|
+
protected $searchableColumns = [];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The attributes that are mass assignable.
|
|
28
|
+
*
|
|
29
|
+
* @var array
|
|
30
|
+
*/
|
|
31
|
+
protected $fillable = [
|
|
32
|
+
'product_uuid',
|
|
33
|
+
'day_of_week',
|
|
34
|
+
'start',
|
|
35
|
+
'end'
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The attributes that should be cast to native types.
|
|
40
|
+
*
|
|
41
|
+
* @var array
|
|
42
|
+
*/
|
|
43
|
+
protected $casts = [];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Dynamic attributes that are appended to object
|
|
47
|
+
*
|
|
48
|
+
* @var array
|
|
49
|
+
*/
|
|
50
|
+
protected $appends = [];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
54
|
+
*/
|
|
55
|
+
public function product()
|
|
56
|
+
{
|
|
57
|
+
return $this->belongsTo(Product::class);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Models;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Traits\HasUuid;
|
|
6
|
+
use Fleetbase\Traits\HasApiModelBehavior;
|
|
7
|
+
use Spatie\Sluggable\HasSlug;
|
|
8
|
+
use Spatie\Sluggable\SlugOptions;
|
|
9
|
+
|
|
10
|
+
class ProductStoreLocation extends StorefrontModel
|
|
11
|
+
{
|
|
12
|
+
use HasUuid, HasApiModelBehavior, HasSlug;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The database table used by the model.
|
|
16
|
+
*
|
|
17
|
+
* @var string
|
|
18
|
+
*/
|
|
19
|
+
protected $table = 'product_store_locations';
|
|
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 = [
|
|
34
|
+
'product_uuid',
|
|
35
|
+
'store_location_uuid'
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The attributes that should be cast to native types.
|
|
40
|
+
*
|
|
41
|
+
* @var array
|
|
42
|
+
*/
|
|
43
|
+
protected $casts = [];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Dynamic attributes that are appended to object
|
|
47
|
+
*
|
|
48
|
+
* @var array
|
|
49
|
+
*/
|
|
50
|
+
protected $appends = [];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @var \Spatie\Sluggable\SlugOptions
|
|
54
|
+
*/
|
|
55
|
+
public function getSlugOptions(): SlugOptions
|
|
56
|
+
{
|
|
57
|
+
return SlugOptions::create()
|
|
58
|
+
->generateSlugsFrom('name')
|
|
59
|
+
->saveSlugsTo('slug');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
64
|
+
*/
|
|
65
|
+
public function product()
|
|
66
|
+
{
|
|
67
|
+
return $this->belongsTo(Product::class);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
72
|
+
*/
|
|
73
|
+
public function storeLocation()
|
|
74
|
+
{
|
|
75
|
+
return $this->belongsTo(StoreLocation::class);
|
|
76
|
+
}
|
|
77
|
+
}
|