fix: 🐛 Added store_enabled option

This commit is contained in:
IceToast 2023-03-04 20:41:02 +01:00 committed by IceToast
parent d7a36c61b2
commit d7ed67a842
8 changed files with 61 additions and 91 deletions

View file

@ -127,9 +127,6 @@ class ExtensionHelper
}
}
error_log(print_r($settings, true));
return $settings;
}

View file

@ -44,7 +44,6 @@ class SettingsController extends Controller
$className = $file;
// instantiate the class and call toArray method to get all options
$options = (new $className())->toArray();
error_log(print_r($className, true));
// call getOptionInputData method to get all options
if (method_exists($className, 'getOptionInputData')) {
@ -52,7 +51,6 @@ class SettingsController extends Controller
} else {
$optionInputData = [];
}
error_log(print_r($optionInputData, true));
// collect all option input data
$optionsData = [];

View file

@ -22,20 +22,13 @@ class ShopProductController extends Controller
*
* @return Application|Factory|View|Response
*/
public function index(LocaleSettings $locale_settings)
public function index(LocaleSettings $locale_settings, GeneralSettings $general_settings)
{
$isPaymentSetup = false;
$isStoreEnabled = $general_settings->store_enabled;
if (
env('APP_ENV') == 'local' ||
config('SETTINGS::PAYMENTS:PAYPAL:SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID') ||
config('SETTINGS::PAYMENTS:STRIPE:SECRET') && config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') && config('SETTINGS::PAYMENTS:STRIPE:METHODS')
) {
$isPaymentSetup = true;
}
return view('admin.store.index', [
'isPaymentSetup' => $isPaymentSetup,
'isStoreEnabled' => $isStoreEnabled,
'locale_datatables' => $locale_settings->datatables
]);
}

View file

@ -12,29 +12,21 @@ class StoreController extends Controller
/** Display a listing of the resource. */
public function index(UserSettings $user_settings, GeneralSettings $general_settings)
{
$isPaymentSetup = false;
if (
env('APP_ENV') == 'local' ||
config('SETTINGS::PAYMENTS:PAYPAL:SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID') ||
config('SETTINGS::PAYMENTS:STRIPE:SECRET') && config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') && config('SETTINGS::PAYMENTS:STRIPE:METHODS')
) {
$isPaymentSetup = true;
}
$isStoreEnabled = $general_settings->store_enabled;
//Required Verification for creating an server
if ($user_settings->force_email_verification && ! Auth::user()->hasVerifiedEmail()) {
if ($user_settings->force_email_verification && !Auth::user()->hasVerifiedEmail()) {
return redirect()->route('profile.index')->with('error', __('You are required to verify your email address before you can purchase credits.'));
}
//Required Verification for creating an server
if ($user_settings->force_discord_verification && ! Auth::user()->discordUser) {
if ($user_settings->force_discord_verification && !Auth::user()->discordUser) {
return redirect()->route('profile.index')->with('error', __('You are required to link your discord account before you can purchase Credits'));
}
return view('store.index')->with([
'products' => ShopProduct::where('disabled', '=', false)->orderBy('type', 'asc')->orderBy('price', 'asc')->get(),
'isPaymentSetup' => true,
'isStoreEnabled' => $isStoreEnabled,
'credits_display_name' => $general_settings->credits_display_name
]);
}

View file

@ -6,6 +6,7 @@ use Spatie\LaravelSettings\Settings;
class GeneralSettings extends Settings
{
public bool $store_enabled = true;
public string $credits_display_name;
public bool $recaptcha_enabled;
public string $recaptcha_site_key;
@ -31,27 +32,6 @@ class GeneralSettings extends Settings
];
}
/**
* Summary of validations array
* @return array<string, string>
*/
public static function getValidations()
{
return [
'credits_display_name' => 'required|string',
'initial_user_credits' => 'required|numeric',
'initial_server_limit' => 'required|numeric',
'recaptcha_enabled' => 'nullable|string',
'recaptcha_site_key' => 'nullable|string',
'recaptcha_secret_key' => 'nullable|string',
'phpmyadmin_url' => 'nullable|string',
'alert_enabled' => 'nullable|string',
'alert_type' => 'nullable|string',
'alert_message' => 'nullable|string',
'theme' => 'required|string'
];
}
/**
* Summary of optionTypes
* Only used for the settings page
@ -61,6 +41,11 @@ class GeneralSettings extends Settings
{
return [
'category_icon' => "fas fa-cog",
'store_enabled' => [
'type' => 'boolean',
'label' => 'Enable Store',
'description' => 'Enable the store for users to purchase credits.'
],
'credits_display_name' => [
'type' => 'string',
'label' => 'Credits Display Name',

View file

@ -10,6 +10,7 @@ class CreateGeneralSettings extends SettingsMigration
$table_exists = DB::table('settings_old')->exists();
// Get the user-set configuration values from the old table.
$this->migrator->add('general.store_enabled', true);
$this->migrator->add('general.credits_display_name', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME') : 'Credits');
$this->migrator->addEncrypted('general.recaptcha_site_key', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:SITE_KEY") : env('RECAPTCHA_SITE_KEY', '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'));
$this->migrator->addEncrypted('general.recaptcha_secret_key', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:SECRET_KEY") : env('RECAPTCHA_SECRET_KEY', '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe'));
@ -88,6 +89,7 @@ class CreateGeneralSettings extends SettingsMigration
],
]);
$this->migrator->delete('general.store_enabled');
$this->migrator->delete('general.credits_display_name');
$this->migrator->delete('general.recaptcha_site_key');
$this->migrator->delete('general.recaptcha_secret_key');

View file

@ -3,13 +3,16 @@
<head>
@php($website_settings = app(App\Settings\WebsiteSettings::class))
@php($general_settings = app(App\Settings\GeneralSettings::class))
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta content="{{ $website_settings->seo_title }}" property="og:title">
<meta content="{{ $website_settings->seo_description }}" property="og:description">
<meta content='{{ \Illuminate\Support\Facades\Storage::disk('public')->exists('logo.png') ? asset('storage/logo.png') : asset('images/controlpanel_logo.png') }}' property="og:image">
<meta
content='{{ \Illuminate\Support\Facades\Storage::disk('public')->exists('logo.png') ? asset('storage/logo.png') : asset('images/controlpanel_logo.png') }}'
property="og:image">
<title>{{ config('app.name', 'Laravel') }}</title>
<link rel="icon"
href="{{ \Illuminate\Support\Facades\Storage::disk('public')->exists('favicon.ico') ? asset('storage/favicon.ico') : asset('favicon.ico') }}"
@ -87,11 +90,11 @@
</li>
<!-- End Language Selection -->
@endif
@foreach($useful_links as $link)
<li class="nav-item d-none d-sm-inline-block">
<a href="{{ $link->link }}" class="nav-link" target="__blank"><i
class="{{$link->icon}}"></i> {{ $link->title }}</a>
</li>
@foreach ($useful_links as $link)
<li class="nav-item d-none d-sm-inline-block">
<a href="{{ $link->link }}" class="nav-link" target="__blank"><i
class="{{ $link->icon }}"></i> {{ $link->title }}</a>
</li>
@endforeach
</ul>
@ -232,11 +235,7 @@
</a>
</li>
@if (env('APP_ENV') == 'local' ||
(config('SETTINGS::PAYMENTS:PAYPAL:SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID')) ||
(config('SETTINGS::PAYMENTS:STRIPE:SECRET') &&
config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') &&
config('SETTINGS::PAYMENTS:STRIPE:METHODS')))
@if (env('APP_ENV') == 'local' || $general_settings->store_enabled)
<li class="nav-item">
<a href="{{ route('store.index') }}"
class="nav-link @if (Request::routeIs('store.*') || Request::routeIs('checkout')) active @endif">
@ -384,7 +383,7 @@
<li class="nav-item">
<a href="{{ route('admin.legal.index') }}"
class="nav-link @if (Request::routeIs('admin.legal.*')) active @endif">
class="nav-link @if (Request::routeIs('admin.legal.*')) active @endif">
<i class="nav-icon fas fa-link"></i>
<p>{{ __('Legal Sites') }}</p>
</a>
@ -458,7 +457,8 @@
<a target="_blank" href="{{ route('privacy') }}"><strong>{{ __('Privacy') }}</strong></a>
@endif
@if ($website_settings->show_tos)
| <a target="_blank" href="{{ route('tos') }}"><strong>{{ __('Terms of Service') }}</strong></a>
| <a target="_blank"
href="{{ route('tos') }}"><strong>{{ __('Terms of Service') }}</strong></a>
@endif
</div>
</footer>

View file

@ -10,10 +10,9 @@
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a class=""
href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
<li class="breadcrumb-item"><a class="" href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
<li class="breadcrumb-item"><a class="text-muted"
href="{{ route('store.index') }}">{{ __('Store') }}</a></li>
href="{{ route('store.index') }}">{{ __('Store') }}</a></li>
</ol>
</div>
</div>
@ -31,8 +30,7 @@
</button>
</div>
@if ($isPaymentSetup && $products->count() > 0)
@if ($isStoreEnabled && $products->count() > 0)
<div class="card">
<div class="card-header">
<h5 class="card-title"><i class="fa fa-coins mr-2"></i>{{ $credits_display_name }}</h5>
@ -40,43 +38,48 @@
<div class="card-body">
<table class="table table-striped table-responsive-sm">
<thead>
<tr>
<th>{{ __('Price') }}</th>
<th>{{ __('Type') }}</th>
<th>{{ __('Description') }}</th>
<th></th>
</tr>
<tr>
<th>{{ __('Price') }}</th>
<th>{{ __('Type') }}</th>
<th>{{ __('Description') }}</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($products as $product)
<tr>
<td>{{ $product->formatToCurrency($product->price) }}</td>
<td>{{ strtolower($product->type) == 'credits' ? $credits_display_name : $product->type }}</td>
<td>
@if(strtolower($product->type) == 'credits')
<i class="fa fa-coins mr-2"></i>
@elseif (strtolower($product->type) == 'server slots')
<i class="fa fa-server mr-2"></i>
@endif
@foreach ($products as $product)
<tr>
<td>{{ $product->formatToCurrency($product->price) }}</td>
<td>{{ strtolower($product->type) == 'credits' ? $credits_display_name : $product->type }}
</td>
<td>
@if (strtolower($product->type) == 'credits')
<i class="fa fa-coins mr-2"></i>
@elseif (strtolower($product->type) == 'server slots')
<i class="fa fa-server mr-2"></i>
@endif
{{ $product->display }}</td>
<td><a href="{{ route('checkout', $product->id) }}"
class="btn btn-info">{{ __('Purchase') }}</a>
</td>
</tr>
@endforeach
{{ $product->display }}
</td>
<td><a href="{{ route('checkout', $product->id) }}"
class="btn btn-info">{{ __('Purchase') }}</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@else
<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> @if ($products->count() == 0) {{ __('There are no store products!') }} @else {{ __('The store is not correctly configured!') }} @endif
<h4><i class="icon fa fa-ban"></i>
@if ($products->count() == 0)
{{ __('There are no store products!') }}
@else
{{ __('The store is not correctly configured!') }}
@endif
</h4>
</div>
@endif