@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,44 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
use Illuminate\Database\Migrations\Migration;
|
|
4
|
+
use Illuminate\Database\Schema\Blueprint;
|
|
5
|
+
use Illuminate\Database\Query\Expression;
|
|
6
|
+
use Illuminate\Support\Facades\Schema;
|
|
7
|
+
use Fleetbase\Support\Utils;
|
|
8
|
+
|
|
9
|
+
return new class extends Migration
|
|
10
|
+
{
|
|
11
|
+
/**
|
|
12
|
+
* Run the migrations.
|
|
13
|
+
*
|
|
14
|
+
* @return void
|
|
15
|
+
*/
|
|
16
|
+
public function up()
|
|
17
|
+
{
|
|
18
|
+
$databaseName = Utils::getFleetbaseDatabaseName();
|
|
19
|
+
|
|
20
|
+
Schema::connection(config('storefront.connection.db'))->table('products', function (Blueprint $table) use ($databaseName) {
|
|
21
|
+
$table->foreign(['category_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.categories'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
22
|
+
$table->foreign(['company_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.companies'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
23
|
+
$table->foreign(['created_by_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.users'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
24
|
+
$table->foreign(['primary_image_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.files'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
25
|
+
$table->foreign(['store_uuid'])->references(['uuid'])->on('stores')->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Reverse the migrations.
|
|
31
|
+
*
|
|
32
|
+
* @return void
|
|
33
|
+
*/
|
|
34
|
+
public function down()
|
|
35
|
+
{
|
|
36
|
+
Schema::connection(config('storefront.connection.db'))->table('products', function (Blueprint $table) {
|
|
37
|
+
$table->dropForeign('products_category_uuid_foreign');
|
|
38
|
+
$table->dropForeign('products_company_uuid_foreign');
|
|
39
|
+
$table->dropForeign('products_created_by_uuid_foreign');
|
|
40
|
+
$table->dropForeign('products_primary_image_uuid_foreign');
|
|
41
|
+
$table->dropForeign('products_store_uuid_foreign');
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
use Illuminate\Database\Migrations\Migration;
|
|
4
|
+
use Illuminate\Database\Schema\Blueprint;
|
|
5
|
+
use Illuminate\Database\Query\Expression;
|
|
6
|
+
use Illuminate\Support\Facades\Schema;
|
|
7
|
+
use Fleetbase\Support\Utils;
|
|
8
|
+
|
|
9
|
+
return new class extends Migration
|
|
10
|
+
{
|
|
11
|
+
/**
|
|
12
|
+
* Run the migrations.
|
|
13
|
+
*
|
|
14
|
+
* @return void
|
|
15
|
+
*/
|
|
16
|
+
public function up()
|
|
17
|
+
{
|
|
18
|
+
$databaseName = Utils::getFleetbaseDatabaseName();
|
|
19
|
+
|
|
20
|
+
Schema::connection(config('storefront.connection.db'))->table('reviews', function (Blueprint $table) use ($databaseName) {
|
|
21
|
+
$table->foreign(['created_by_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.users'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
22
|
+
$table->foreign(['customer_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.contacts'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Reverse the migrations.
|
|
28
|
+
*
|
|
29
|
+
* @return void
|
|
30
|
+
*/
|
|
31
|
+
public function down()
|
|
32
|
+
{
|
|
33
|
+
Schema::connection(config('storefront.connection.db'))->table('reviews', function (Blueprint $table) {
|
|
34
|
+
$table->dropForeign('reviews_created_by_uuid_foreign');
|
|
35
|
+
$table->dropForeign('reviews_customer_uuid_foreign');
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
use Illuminate\Database\Migrations\Migration;
|
|
4
|
+
use Illuminate\Database\Schema\Blueprint;
|
|
5
|
+
use Illuminate\Support\Facades\Schema;
|
|
6
|
+
|
|
7
|
+
return new class extends Migration
|
|
8
|
+
{
|
|
9
|
+
/**
|
|
10
|
+
* Run the migrations.
|
|
11
|
+
*
|
|
12
|
+
* @return void
|
|
13
|
+
*/
|
|
14
|
+
public function up()
|
|
15
|
+
{
|
|
16
|
+
Schema::connection(config('storefront.connection.db'))->table('store_hours', function (Blueprint $table) {
|
|
17
|
+
$table->foreign(['store_location_uuid'])->references(['uuid'])->on('store_locations')->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Reverse the migrations.
|
|
23
|
+
*
|
|
24
|
+
* @return void
|
|
25
|
+
*/
|
|
26
|
+
public function down()
|
|
27
|
+
{
|
|
28
|
+
Schema::connection(config('storefront.connection.db'))->table('store_hours', function (Blueprint $table) {
|
|
29
|
+
$table->dropForeign('store_hours_store_location_uuid_foreign');
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
use Illuminate\Database\Migrations\Migration;
|
|
4
|
+
use Illuminate\Database\Schema\Blueprint;
|
|
5
|
+
use Illuminate\Database\Query\Expression;
|
|
6
|
+
use Illuminate\Support\Facades\Schema;
|
|
7
|
+
use Fleetbase\Support\Utils;
|
|
8
|
+
|
|
9
|
+
return new class extends Migration
|
|
10
|
+
{
|
|
11
|
+
/**
|
|
12
|
+
* Run the migrations.
|
|
13
|
+
*
|
|
14
|
+
* @return void
|
|
15
|
+
*/
|
|
16
|
+
public function up()
|
|
17
|
+
{
|
|
18
|
+
$databaseName = Utils::getFleetbaseDatabaseName();
|
|
19
|
+
|
|
20
|
+
Schema::connection(config('storefront.connection.db'))->table('store_locations', function (Blueprint $table) use ($databaseName) {
|
|
21
|
+
$table->foreign(['created_by_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.users'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
22
|
+
$table->foreign(['place_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.places'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
23
|
+
$table->foreign(['store_uuid'])->references(['uuid'])->on('stores')->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Reverse the migrations.
|
|
29
|
+
*
|
|
30
|
+
* @return void
|
|
31
|
+
*/
|
|
32
|
+
public function down()
|
|
33
|
+
{
|
|
34
|
+
Schema::connection(config('storefront.connection.db'))->table('store_locations', function (Blueprint $table) {
|
|
35
|
+
$table->dropForeign('store_locations_created_by_uuid_foreign');
|
|
36
|
+
$table->dropForeign('store_locations_place_uuid_foreign');
|
|
37
|
+
$table->dropForeign('store_locations_store_uuid_foreign');
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
use Illuminate\Database\Migrations\Migration;
|
|
4
|
+
use Illuminate\Database\Schema\Blueprint;
|
|
5
|
+
use Illuminate\Database\Query\Expression;
|
|
6
|
+
use Illuminate\Support\Facades\Schema;
|
|
7
|
+
use Fleetbase\Support\Utils;
|
|
8
|
+
|
|
9
|
+
return new class extends Migration
|
|
10
|
+
{
|
|
11
|
+
/**
|
|
12
|
+
* Run the migrations.
|
|
13
|
+
*
|
|
14
|
+
* @return void
|
|
15
|
+
*/
|
|
16
|
+
public function up()
|
|
17
|
+
{
|
|
18
|
+
$databaseName = Utils::getFleetbaseDatabaseName();
|
|
19
|
+
|
|
20
|
+
Schema::connection(config('storefront.connection.db'))->table('stores', function (Blueprint $table) use ($databaseName) {
|
|
21
|
+
$table->foreign(['backdrop_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.files'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
22
|
+
$table->foreign(['company_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.companies'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
23
|
+
$table->foreign(['created_by_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.users'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
24
|
+
$table->foreign(['logo_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.files'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Reverse the migrations.
|
|
30
|
+
*
|
|
31
|
+
* @return void
|
|
32
|
+
*/
|
|
33
|
+
public function down()
|
|
34
|
+
{
|
|
35
|
+
Schema::connection(config('storefront.connection.db'))->table('stores', function (Blueprint $table) {
|
|
36
|
+
$table->dropForeign('stores_backdrop_uuid_foreign');
|
|
37
|
+
$table->dropForeign('stores_company_uuid_foreign');
|
|
38
|
+
$table->dropForeign('stores_created_by_uuid_foreign');
|
|
39
|
+
$table->dropForeign('stores_logo_uuid_foreign');
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
use Illuminate\Database\Migrations\Migration;
|
|
4
|
+
use Illuminate\Database\Schema\Blueprint;
|
|
5
|
+
use Illuminate\Database\Query\Expression;
|
|
6
|
+
use Illuminate\Support\Facades\Schema;
|
|
7
|
+
use Fleetbase\Support\Utils;
|
|
8
|
+
|
|
9
|
+
return new class extends Migration
|
|
10
|
+
{
|
|
11
|
+
/**
|
|
12
|
+
* Run the migrations.
|
|
13
|
+
*
|
|
14
|
+
* @return void
|
|
15
|
+
*/
|
|
16
|
+
public function up()
|
|
17
|
+
{
|
|
18
|
+
$databaseName = Utils::getFleetbaseDatabaseName();
|
|
19
|
+
|
|
20
|
+
Schema::connection(config('storefront.connection.db'))->table('votes', function (Blueprint $table) use ($databaseName) {
|
|
21
|
+
$table->foreign(['created_by_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.users'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
22
|
+
$table->foreign(['customer_uuid'])->references(['uuid'])->on(new Expression($databaseName . '.contacts'))->onUpdate('NO ACTION')->onDelete('NO ACTION');
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Reverse the migrations.
|
|
28
|
+
*
|
|
29
|
+
* @return void
|
|
30
|
+
*/
|
|
31
|
+
public function down()
|
|
32
|
+
{
|
|
33
|
+
Schema::connection(config('storefront.connection.db'))->table('votes', function (Blueprint $table) {
|
|
34
|
+
$table->dropForeign('votes_created_by_uuid_foreign');
|
|
35
|
+
$table->dropForeign('votes_customer_uuid_foreign');
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Auth\Schemas;
|
|
4
|
+
|
|
5
|
+
class Storefront
|
|
6
|
+
{
|
|
7
|
+
/**
|
|
8
|
+
* The permission schema Name.
|
|
9
|
+
*
|
|
10
|
+
* @var string
|
|
11
|
+
*/
|
|
12
|
+
public string $name = 'storefront';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The permission schema Polict Name.
|
|
16
|
+
*
|
|
17
|
+
* @var string
|
|
18
|
+
*/
|
|
19
|
+
public string $policyName = 'Storefront';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Guards these permissions should apply to.
|
|
23
|
+
*
|
|
24
|
+
* @var array
|
|
25
|
+
*/
|
|
26
|
+
public array $guards = ['web', 'api'];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The permission schema resources.
|
|
30
|
+
*
|
|
31
|
+
* @var array
|
|
32
|
+
*/
|
|
33
|
+
public array $resources = [
|
|
34
|
+
[
|
|
35
|
+
'name' => 'order',
|
|
36
|
+
'actions' => ['accept', 'mark-as-ready', 'mark-as-completed', 'reject']
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
'name' => 'product',
|
|
40
|
+
'actions' => ['import']
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
'name' => 'product-addon',
|
|
44
|
+
'actions' => []
|
|
45
|
+
],
|
|
46
|
+
[
|
|
47
|
+
'name' => 'product-addon-category',
|
|
48
|
+
'actions' => []
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
'name' => 'product-hour',
|
|
52
|
+
'actions' => []
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
'name' => 'product-store-location',
|
|
56
|
+
'actions' => []
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
'name' => 'product-variant',
|
|
60
|
+
'actions' => []
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
'name' => 'product-variant-option',
|
|
64
|
+
'actions' => []
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
'name' => 'gateway',
|
|
68
|
+
'actions' => []
|
|
69
|
+
],
|
|
70
|
+
[
|
|
71
|
+
'name' => 'notification-channel',
|
|
72
|
+
'actions' => []
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
'name' => 'network',
|
|
76
|
+
'actions' => []
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
'name' => 'network-store',
|
|
80
|
+
'actions' => []
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
'name' => 'store',
|
|
84
|
+
'actions' => []
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
'name' => 'store-location',
|
|
88
|
+
'actions' => []
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
'name' => 'store-hour',
|
|
92
|
+
'actions' => []
|
|
93
|
+
]
|
|
94
|
+
];
|
|
95
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Console\Commands;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\FleetOps\Models\Order;
|
|
6
|
+
use Fleetbase\FleetOps\Support\Utils;
|
|
7
|
+
use Fleetbase\Storefront\Notifications\StorefrontOrderNearby;
|
|
8
|
+
use Illuminate\Console\Command;
|
|
9
|
+
|
|
10
|
+
class NotifyStorefrontOrderNearby extends Command
|
|
11
|
+
{
|
|
12
|
+
/**
|
|
13
|
+
* The name and signature of the console command.
|
|
14
|
+
*
|
|
15
|
+
* @var string
|
|
16
|
+
*/
|
|
17
|
+
protected $signature = 'storefront:notify-order-nearby';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The console command description.
|
|
21
|
+
*
|
|
22
|
+
* @var string
|
|
23
|
+
*/
|
|
24
|
+
protected $description = 'Notifies customer when their order is nearby/ reaching';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Execute the console command.
|
|
28
|
+
*
|
|
29
|
+
* @return int
|
|
30
|
+
*/
|
|
31
|
+
public function handle()
|
|
32
|
+
{
|
|
33
|
+
// Get storefront orders that are enroute
|
|
34
|
+
$orders = $this->getActiveStorefrontOrders();
|
|
35
|
+
|
|
36
|
+
// Notify and update
|
|
37
|
+
$this->alert('Found (' . $orders->count() . ') Storefront Orders which are Enroute.');
|
|
38
|
+
|
|
39
|
+
// Iterate each order
|
|
40
|
+
$orders->each(
|
|
41
|
+
function ($order) {
|
|
42
|
+
$origin = $order->payload->getPickupOrFirstWaypoint();
|
|
43
|
+
$destination = $order->payload->getDropoffOrLastWaypoint();
|
|
44
|
+
$matrix = Utils::getDrivingDistanceAndTime($origin, $destination);
|
|
45
|
+
$distance = $matrix->distance;
|
|
46
|
+
$time = $matrix->time;
|
|
47
|
+
|
|
48
|
+
if (!$distance || !$time) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
$this->line('Order ' . $order->public_id . ' is ' . Utils::formatSeconds($time) . ' from being delivered');
|
|
53
|
+
$this->line('Order ' . $order->public_id . ' distance is ' . Utils::formatMeters($distance) . ' away');
|
|
54
|
+
|
|
55
|
+
if (round($distance) < 1500 && $order->missingMeta('storefront_order_nearby')) {
|
|
56
|
+
$this->line('Order ' . $order->public_id . ' is nearby');
|
|
57
|
+
$order->customer->notify(new StorefrontOrderNearby($order, $distance, $time));
|
|
58
|
+
$order->updateMeta('storefront_order_nearby', true);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Fetches active storefront orders based on certain criteria.
|
|
66
|
+
*
|
|
67
|
+
* @return \Illuminate\Database\Eloquent\Collection
|
|
68
|
+
*/
|
|
69
|
+
public function getActiveStorefrontOrders(): \Illuminate\Database\Eloquent\Collection
|
|
70
|
+
{
|
|
71
|
+
return Order::where(
|
|
72
|
+
[
|
|
73
|
+
'status' => 'driver_enroute',
|
|
74
|
+
'type' => 'storefront',
|
|
75
|
+
'dispatched' => true
|
|
76
|
+
]
|
|
77
|
+
)->with(
|
|
78
|
+
[
|
|
79
|
+
'payload',
|
|
80
|
+
'customer'
|
|
81
|
+
]
|
|
82
|
+
)
|
|
83
|
+
->withoutGlobalScopes()
|
|
84
|
+
->get();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Expansions;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Build\Expansion;
|
|
6
|
+
|
|
7
|
+
class EntityExpansion implements Expansion
|
|
8
|
+
{
|
|
9
|
+
/**
|
|
10
|
+
* Get the target class to expand.
|
|
11
|
+
*
|
|
12
|
+
* @return string|Class
|
|
13
|
+
*/
|
|
14
|
+
public static function target()
|
|
15
|
+
{
|
|
16
|
+
return \Fleetbase\FleetOps\Models\Entity::class;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a new Entity from a Storefront Product
|
|
21
|
+
*
|
|
22
|
+
* @return \Fleetbase\FleetOps\Models\Entity
|
|
23
|
+
*/
|
|
24
|
+
public function fromStorefrontProduct()
|
|
25
|
+
{
|
|
26
|
+
return static function (\Fleetbase\Storefront\Models\Product $product) {
|
|
27
|
+
return new static([
|
|
28
|
+
'company_uuid' => session('company'),
|
|
29
|
+
'photo_uuid' => $product->primary_image_uuid,
|
|
30
|
+
'internal_id' => $product->public_id,
|
|
31
|
+
'name' => $product->name,
|
|
32
|
+
'description' => $product->description,
|
|
33
|
+
'currency' => $product->currency,
|
|
34
|
+
'sku' => $product->sku,
|
|
35
|
+
'price' => $product->price,
|
|
36
|
+
'sale_price' => $product->sale_price,
|
|
37
|
+
'meta' => [
|
|
38
|
+
'product_id' => $product->public_id,
|
|
39
|
+
'image_url' => $product->primary_image_url,
|
|
40
|
+
]
|
|
41
|
+
]);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\Storefront\Http\Controllers;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Http\Controllers\Controller;
|
|
6
|
+
use Fleetbase\FleetOps\Models\Contact;
|
|
7
|
+
use Fleetbase\FleetOps\Models\Order;
|
|
8
|
+
use Fleetbase\Storefront\Models\Store;
|
|
9
|
+
use Illuminate\Http\Request;
|
|
10
|
+
use Illuminate\Support\Carbon;
|
|
11
|
+
|
|
12
|
+
class ActionController extends Controller
|
|
13
|
+
{
|
|
14
|
+
public function welcome()
|
|
15
|
+
{
|
|
16
|
+
return response()->json(['message' => 'Hello Friend!']);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get the number of storefronts created.
|
|
21
|
+
*
|
|
22
|
+
* @param \Illuminate\Http\Request $request
|
|
23
|
+
* @return \Illuminate\Http\Response
|
|
24
|
+
*/
|
|
25
|
+
public function getStoreCount(Request $request)
|
|
26
|
+
{
|
|
27
|
+
$count = Store::where('company_uuid', session('company'))->count();
|
|
28
|
+
|
|
29
|
+
return response()->json(['storeCount' => $count]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get key metrics for storefront.
|
|
34
|
+
*
|
|
35
|
+
* @param \Illuminate\Http\Request $request
|
|
36
|
+
* @return \Illuminate\Http\Response
|
|
37
|
+
*/
|
|
38
|
+
public function getMetrics(Request $request)
|
|
39
|
+
{
|
|
40
|
+
$store = $request->input('store');
|
|
41
|
+
$start = $request->has('start') ? Carbon::fromString($request->input('start'))->toDateTimeString() : Carbon::now()->startOfMonth()->toDateTimeString();
|
|
42
|
+
$end = $request->has('end') ? Carbon::fromString($request->input('end'))->toDateTimeString() : Carbon::now()->toDateTimeString();
|
|
43
|
+
|
|
44
|
+
// default metrics
|
|
45
|
+
$metrics = [
|
|
46
|
+
'orders_count' => 0,
|
|
47
|
+
'customers_count' => 0,
|
|
48
|
+
'stores_count' => 0,
|
|
49
|
+
'earnings_sum' => 0
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
// get the current active store
|
|
53
|
+
if (!$store) {
|
|
54
|
+
return response()->json($metrics);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
$store = Store::where('uuid', $store)->first();
|
|
58
|
+
|
|
59
|
+
if (!$store) {
|
|
60
|
+
return response()->json($metrics);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Query metrics between given time period
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
// send back currency
|
|
68
|
+
$metrics['currency'] = $store->currency;
|
|
69
|
+
|
|
70
|
+
// - orders count
|
|
71
|
+
$metrics['orders_count'] = Order::where([
|
|
72
|
+
'company_uuid' => session('company'),
|
|
73
|
+
'type' => 'storefront'
|
|
74
|
+
])
|
|
75
|
+
->where('meta->storefront_id', $store->public_id)
|
|
76
|
+
->whereNotIn('status', ['canceled'])
|
|
77
|
+
->whereBetween('created_at', [$start, $end])->count();
|
|
78
|
+
|
|
79
|
+
// - customers count -- change to where has orders where meta->storefront_id === store
|
|
80
|
+
$metrics['customers_count'] = Contact::where([
|
|
81
|
+
'company_uuid' => session('company'),
|
|
82
|
+
'type' => 'customer'
|
|
83
|
+
])->whereHas('customerOrders', function ($q) use ($start, $end, $store) {
|
|
84
|
+
$q->whereBetween('created_at', [$start, $end]);
|
|
85
|
+
$q->where('meta->storefront_id', $store->public_id);
|
|
86
|
+
$q->whereNotIn('status', ['canceled']);
|
|
87
|
+
})->count();
|
|
88
|
+
|
|
89
|
+
// - stores count
|
|
90
|
+
$metrics['stores_count'] = Store::where(['company_uuid' => session('company')])->count();
|
|
91
|
+
|
|
92
|
+
// - earnings sum
|
|
93
|
+
// $metrics['earnings_sum'] = Transaction::where(['company_uuid' => session('company'), 'type' => 'storefront', 'meta->storefront_id' => $store->public_id])->whereBetween('created_at', [$start, $end])->sum('amount');
|
|
94
|
+
$metrics['earnings_sum'] = Order::where([
|
|
95
|
+
'company_uuid' => session('company'),
|
|
96
|
+
'type' => 'storefront'
|
|
97
|
+
])
|
|
98
|
+
->whereBetween('created_at', [$start, $end])
|
|
99
|
+
->where('meta->storefront_id', $store->public_id)
|
|
100
|
+
->with(['transaction'])
|
|
101
|
+
->whereNotIn('status', ['canceled'])
|
|
102
|
+
->get()
|
|
103
|
+
->sum(function ($order) {
|
|
104
|
+
return $order->transaction->amount;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
response()->json($metrics);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* CORS OPTIONS.
|
|
112
|
+
*
|
|
113
|
+
* @return \Illuminate\Http\Response
|
|
114
|
+
*/
|
|
115
|
+
public function options()
|
|
116
|
+
{
|
|
117
|
+
return response()->json(['status' => 'ok']);
|
|
118
|
+
}
|
|
119
|
+
}
|