¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -9,6 +9,7 @@ use Modules\Support\Country;
use Modules\Support\TimeZone;
use Modules\Currency\Currency;
use Modules\User\Entities\Role;
use Modules\Payment\Gateways\MercadoPago;
class SettingTabs extends Tabs
{
@@ -77,6 +78,7 @@ class SettingTabs extends Tabs
{
return tap(new Tab('maintenance', trans('setting::settings.tabs.maintenance')), function (Tab $tab) {
$tab->weight(7);
$tab->view('setting::admin.settings.tabs.maintenance');
});
}
@@ -115,7 +117,9 @@ class SettingTabs extends Tabs
{
$currencyRateExchangeServices = ['' => trans('setting::settings.form.select_service')];
return $currencyRateExchangeServices += trans('currency::services');
$currencyRateExchangeServices += trans('currency::services');
return $currencyRateExchangeServices;
}
@@ -146,7 +150,9 @@ class SettingTabs extends Tabs
{
return tap(new Tab('mail', trans('setting::settings.tabs.mail')), function (Tab $tab) {
$tab->weight(30);
$tab->fields(['mail_from_address']);
$tab->view('setting::admin.settings.tabs.mail', [
'encryptionProtocols' => $this->getMailEncryptionProtocols(),
'orderStatuses' => trans('order::statuses'),
@@ -165,7 +171,9 @@ class SettingTabs extends Tabs
{
return tap(new Tab('newsletter', trans('setting::settings.tabs.newsletter')), function (Tab $tab) {
$tab->weight(32);
$tab->fields(['newsletter_enabled', 'mailchimp_api_key', 'mailchimp_list_id']);
$tab->view('setting::admin.settings.tabs.newsletter');
});
}
@@ -175,6 +183,7 @@ class SettingTabs extends Tabs
{
return tap(new Tab('custom_css_js', trans('setting::settings.tabs.custom_css_js')), function (Tab $tab) {
$tab->weight(35);
$tab->view('setting::admin.settings.tabs.custom_css_js');
});
}
@@ -208,7 +217,9 @@ class SettingTabs extends Tabs
{
return tap(new Tab('free_shipping', trans('setting::settings.tabs.free_shipping')), function (Tab $tab) {
$tab->weight(40);
$tab->fields(['free_shipping_enabled', 'translatable.free_shipping_label']);
$tab->view('setting::admin.settings.tabs.free_shipping');
});
}
@@ -218,7 +229,9 @@ class SettingTabs extends Tabs
{
return tap(new Tab('local_pickup', trans('setting::settings.tabs.local_pickup')), function (Tab $tab) {
$tab->weight(45);
$tab->fields(['local_pickup_enabled', 'translatable.local_pickup_label']);
$tab->view('setting::admin.settings.tabs.local_pickup');
});
}
@@ -296,18 +309,6 @@ class SettingTabs extends Tabs
}
private function paystack()
{
return tap(new Tab('paystack', trans('setting::settings.tabs.paystack')), function (Tab $tab) {
$tab->weight(66);
$tab->fields(['paystack_enabled', 'paystack_label', 'paystack_description', 'paystack_test_mode','paystack_public_key','paystack_secret_key']);
$tab->view('setting::admin.settings.tabs.paystack');
});
}
private function authorizenet()
{
return tap(new Tab('authorizenet', trans('setting::settings.tabs.authorizenet')), function (Tab $tab) {
@@ -320,16 +321,28 @@ class SettingTabs extends Tabs
}
private function paystack()
{
return tap(new Tab('paystack', trans('setting::settings.tabs.paystack')), function (Tab $tab) {
$tab->weight(66);
$tab->fields(['paystack_enabled', 'paystack_label', 'paystack_description', 'paystack_test_mode', 'paystack_public_key', 'paystack_secret_key']);
$tab->view('setting::admin.settings.tabs.paystack');
});
}
private function mercadopago()
{
return tap(new Tab('mercadopago', trans('setting::settings.tabs.mercadopago')), function (Tab $tab) {
$tab->weight(68);
$currencies = array_combine(
\Modules\Payment\Gateways\MercadoPago::CURRENCIES,
MercadoPago::CURRENCIES,
array_map(function ($currency) {
return Currency::name($currency);
}, \Modules\Payment\Gateways\MercadoPago::CURRENCIES),
}, MercadoPago::CURRENCIES),
);
$tab->fields(['mercadopago_enabled', 'mercadopago_label', 'mercadopago_description', 'mercadopago_supported_currency', 'mercadopago_test_mode', 'mercadopago_public_key', 'mercadopago_access_token']);
@@ -350,7 +363,6 @@ class SettingTabs extends Tabs
$tab->view('setting::admin.settings.tabs.flutterwave');
});
}

View File

@@ -22,6 +22,7 @@ class CreateSettingsTable extends Migration
});
}
/**
* Reverse the migrations.
*

View File

@@ -24,6 +24,7 @@ class CreateSettingTranslationsTable extends Migration
});
}
/**
* Reverse the migrations.
*

View File

@@ -52,10 +52,10 @@ class SettingDatabaseSeeder extends Seeder
'authorizenet_description' => 'Accept payments anytime, anywhere',
'paystack_label' => 'Paystack',
'paystack_description' => 'Modern online and offline payments for Africa',
'mercadopago_label'=> 'Mercado Pago',
'mercadopago_description'=>'From now on, do more with your money',
'flutterwave_label' => 'Flutterwave',
'flutterwave_description' => 'Endless possibilities for every business',
'mercadopago_label' => 'Mercado Pago',
'mercadopago_description' => 'From now on, do more with your money',
'cod_label' => 'Cash On Delivery',
'cod_description' => 'Pay with cash upon delivery.',
'bank_transfer_label' => 'Bank Transfer',

View File

@@ -6,6 +6,7 @@ use Modules\Support\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Modules\Setting\Events\SettingSaved;
use Modules\Support\Eloquent\Translatable;
use Illuminate\Database\Eloquent\Collection;
class Setting extends Model
{
@@ -50,10 +51,11 @@ class Setting extends Model
*/
protected $translatedAttributes = ['value'];
/**
* Get all settings with cache support.
*
* @return \Illuminate\Database\Eloquent\Collection
* @return Collection
*/
public static function allCached()
{
@@ -64,10 +66,12 @@ class Setting extends Model
});
}
/**
* Determine if the given setting key exists.
*
* @param string $key
*
* @return bool
*/
public static function has($key)
@@ -75,11 +79,13 @@ class Setting extends Model
return static::where('key', $key)->exists();
}
/**
* Get setting for the given key.
*
* @param string $key
* @param mixed $default
*
* @return string|array
*/
public static function get($key, $default = null)
@@ -87,11 +93,28 @@ class Setting extends Model
return static::where('key', $key)->first()->value ?? $default;
}
/**
* Set the given settings.
*
* @param array $settings
*
* @return void
*/
public static function setMany($settings)
{
foreach ($settings as $key => $value) {
self::set($key, $value);
}
}
/**
* Set the given setting.
*
* @param string $key
* @param mixed $value
*
* @return void
*/
public static function set($key, $value)
@@ -103,23 +126,12 @@ class Setting extends Model
static::updateOrCreate(['key' => $key], ['plain_value' => $value]);
}
/**
* Set the given settings.
*
* @param array $settings
* @return void
*/
public static function setMany($settings)
{
foreach ($settings as $key => $value) {
self::set($key, $value);
}
}
/**
* Set a translatable settings.
*
* @param array $settings
*
* @return void
*/
public static function setTranslatableSettings($settings = [])
@@ -132,6 +144,7 @@ class Setting extends Model
}
}
/**
* Get the value of the setting.
*
@@ -146,10 +159,12 @@ class Setting extends Model
return unserialize($this->plain_value);
}
/**
* Set the value of the setting.
*
* @param mixed $value
*
* @return mixed
*/
public function setPlainValueAttribute($value)

View File

@@ -13,10 +13,12 @@ class SettingTranslation extends TranslationModel
*/
protected $fillable = ['value'];
/**
* Get the value of the setting.
*
* @param mixed $value
*
* @return mixed
*/
public function getValueAttribute($value)
@@ -24,10 +26,12 @@ class SettingTranslation extends TranslationModel
return unserialize($value);
}
/**
* Set the value of the setting.
*
* @param mixed $value
*
* @return mixed
*/
public function setValueAttribute($value)

View File

@@ -12,14 +12,16 @@ class SettingSaved
/**
* The setting model.
*
* @var \Modules\Setting\Entities\Setting
* @var Setting
*/
public $setting;
/**
* Create a new event instance.
*
* @param \Modules\Setting\Entities\Setting $order
* @param Setting $order
*
* @return void
*/
public function __construct(Setting $setting)

View File

@@ -2,6 +2,8 @@
namespace Modules\Setting\Http\Controllers\Admin;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Artisan;
use Modules\Admin\Ui\Facades\TabManager;
use Modules\Setting\Http\Requests\UpdateSettingRequest;
@@ -11,7 +13,7 @@ class SettingController
/**
* Show the form for editing the specified resource.
*
* @return \Illuminate\Http\Response
* @return Response
*/
public function edit()
{
@@ -21,11 +23,13 @@ class SettingController
return view('setting::admin.settings.edit', compact('settings', 'tabs'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @param Request $request
*
* @return Response
*/
public function update(UpdateSettingRequest $request)
{
@@ -34,14 +38,15 @@ class SettingController
setting($request->except('_token', '_method'));
return redirect(non_localized_url())
->with('success', trans('setting::messages.settings_have_been_saved'));
->with('success', trans('setting::messages.settings_updated'));
}
private function handleMaintenanceMode($request)
{
if ($request->maintenance_mode) {
Artisan::call('down');
} elseif (app()->isDownForMaintenance()) {
} else if (app()->isDownForMaintenance()) {
Artisan::call('up');
}
}

View File

@@ -168,6 +168,23 @@ class UpdateSettingRequest extends Request
}
/**
* Get data to be validated from the request.
*
* @return array
*/
public function validationData()
{
foreach ($this->shouldCheck as $attribute) {
if (!$this->has($attribute)) {
$this->merge([$attribute => null]);
}
}
return $this->all();
}
/**
* Returns currency rate refresh frequencies..
*
@@ -210,21 +227,4 @@ class UpdateSettingRequest extends Request
{
return array_keys(trans('setting::settings.form.mail_encryption_protocols'));
}
/**
* Get data to be validated from the request.
*
* @return array
*/
public function validationData()
{
foreach ($this->shouldCheck as $attribute) {
if (!$this->has($attribute)) {
$this->merge([$attribute => null]);
}
}
return $this->all();
}
}

View File

@@ -2,6 +2,8 @@
namespace Modules\Setting\Providers;
use Modules\Setting\Events\SettingSaved;
use Modules\Setting\Listeners\ClearSettingCache;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
@@ -12,8 +14,8 @@ class EventServiceProvider extends ServiceProvider
* @var array
*/
protected $listen = [
\Modules\Setting\Events\SettingSaved::class => [
\Modules\Setting\Listeners\ClearSettingCache::class,
SettingSaved::class => [
ClearSettingCache::class,
],
];
}

View File

@@ -2,15 +2,12 @@
namespace Modules\Setting\Providers;
use Modules\Support\Traits\AddsAsset;
use Modules\Setting\Admin\SettingTabs;
use Illuminate\Support\ServiceProvider;
use Modules\Admin\Ui\Facades\TabManager;
class SettingServiceProvider extends ServiceProvider
{
use AddsAsset;
/**
* Bootstrap any application services.
*
@@ -19,7 +16,5 @@ class SettingServiceProvider extends ServiceProvider
public function boot()
{
TabManager::register('settings', SettingTabs::class);
$this->addAdminAssets('admin.settings.edit', ['admin.setting.js']);
}
}

View File

@@ -3,6 +3,7 @@
namespace Modules\Setting;
use ArrayAccess;
use Illuminate\Support\Collection;
use Modules\Setting\Entities\Setting;
class Repository implements ArrayAccess
@@ -10,20 +11,22 @@ class Repository implements ArrayAccess
/**
* Collection of all settings.
*
* @var \Illuminate\Support\Collection
* @var Collection
*/
private $settings;
/**
* Create a new repository instance.
*
* @param \Illuminate\Support\Collection $settings
* @param Collection $settings
*/
public function __construct($settings)
{
$this->settings = $settings;
}
/**
* Get all settings.
*
@@ -34,33 +37,12 @@ class Repository implements ArrayAccess
return $this->settings->all();
}
/**
* Get setting for the given key.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
{
return $this->settings->get($key) ?: $default;
}
/**
* Set the given settings.
*
* @param array $settings
* @return void
*/
public function set($settings = [])
{
Setting::setMany($settings);
}
/**
* Determine if an setting is exists.
* Determine if a setting is exists.
*
* @param string $key
*
* @return bool
*/
public function offsetExists($key)
@@ -68,44 +50,25 @@ class Repository implements ArrayAccess
return $this->settings->has($key);
}
/**
* Get setting for the given key.
*
* @param string $key
* @return mixed
*/
public function offsetGet($key)
{
return $this->get($key);
}
/**
* Set a key / value setting pair.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function offsetSet($key, $value)
{
$this->set([$key => $value]);
}
/**
* Unset a setting by the given key.
*
* @param string $key
* @return \Illuminate\Support\Collection
*
* @return Collection
*/
public function offsetUnset($key)
{
return $this->settings->forget($key);
}
/**
* Get setting for the given key.
*
* @param string $key
*
* @return mixed
*/
public function __get($key)
@@ -113,15 +76,71 @@ class Repository implements ArrayAccess
return $this->offsetGet($key);
}
/**
* Set a key / value setting pair.
*
* @param string $key
* @param mixed $value
*
* @return void
*/
public function __set($key, $value)
{
$this->offsetSet($key, $value);
}
/**
* Get setting for the given key.
*
* @param string $key
*
* @return mixed
*/
public function offsetGet($key)
{
return $this->get($key);
}
/**
* Get setting for the given key.
*
* @param string $key
* @param mixed $default
*
* @return mixed
*/
public function get($key, $default = null)
{
return $this->settings->get($key) ?: $default;
}
/**
* Set a key / value setting pair.
*
* @param string $key
* @param mixed $value
*
* @return void
*/
public function offsetSet($key, $value)
{
$this->set([$key => $value]);
}
/**
* Set the given settings.
*
* @param array $settings
*
* @return void
*/
public function set($settings = [])
{
Setting::setMany($settings);
}
}

View File

@@ -163,7 +163,7 @@ return [
'translatable.check_payment_description' => 'Description',
'translatable.check_payment_instructions' => 'Instructions',
// validation
# validation
'supported_countries.*' => 'Supported Countries',
'supported_locales.*' => 'Supported Locales',
'supported_currencies.*' => 'Supported Currencies',

View File

@@ -1,5 +1,5 @@
<?php
return [
'settings_have_been_saved' => 'Settings have been saved.',
'settings_updated' => 'Settings updated',
];

View File

@@ -62,7 +62,7 @@ return [
],
'send_welcome_email_after_registration' => 'Send welcome email after registration',
'send_invoice_email' => 'Send invoice email to the customer after checkout',
'allow_customers_to_subscribe' => 'Allow customers to subscribe to your newsletter.',
'allow_customers_to_subscribe' => 'Allow customers to subscribe to your newsletter',
'enable_facebook_login' => 'Enable Facebook Login',
'enable_google_login' => 'Enable Google Login',
'enable_free_shipping' => 'Enable Free Shipping',
@@ -83,6 +83,6 @@ return [
'enable_check_payment' => 'Enable Check / Money Order',
],
'validation' => [
'sqlite_is_not_installed' => 'SQLite is not installed.',
'sqlite_is_not_installed' => 'SQLite is not installed',
],
];

View File

@@ -19,3 +19,9 @@
{!! $tabs->render(compact('settings')) !!}
</form>
@endsection
@push('globals')
@vite([
'Modules/Setting/Resources/assets/admin/js/main.js'
])
@endpush

View File

@@ -1,6 +1,8 @@
<?php
if (! function_exists('setting')) {
use Modules\Setting\Repository;
if (!function_exists('setting')) {
/**
* Get / set the specified setting value.
*
@@ -8,7 +10,8 @@ if (! function_exists('setting')) {
*
* @param string|array $key
* @param mixed $default
* @return mixed|\Modules\Setting\Repository
*
* @return mixed|Repository
*/
function setting($key = null, $default = null)
{
@@ -22,7 +25,7 @@ if (! function_exists('setting')) {
try {
return app('setting')->get($key, $default);
} catch (PDOException $e) {
} catch (PDOException) {
return $default;
}
}