diff --git a/packages/Webkul/Admin/src/Http/Controllers/ConfigurationController.php b/packages/Webkul/Admin/src/Http/Controllers/ConfigurationController.php index b62228784..769d15382 100755 --- a/packages/Webkul/Admin/src/Http/Controllers/ConfigurationController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/ConfigurationController.php @@ -2,31 +2,32 @@ namespace Webkul\Admin\Http\Controllers; -use Illuminate\Support\Facades\Event; -use Webkul\Core\Repositories\CoreConfigRepository; use Webkul\Core\Tree; +use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Storage; use Webkul\Admin\Http\Requests\ConfigurationForm; +use Webkul\Core\Repositories\CoreConfigRepository; class ConfigurationController extends Controller { /** * Display a listing of the resource. * - * @return \Illuminate\Http\Response + * @var \Illuminate\Http\Response */ protected $_config; /** - * CoreConfigRepository object + * Core config repository instance. * * @var \Webkul\Core\Repositories\CoreConfigRepository */ protected $coreConfigRepository; /** + * Tree instance. * - * @var array + * @var \Webkul\Core\Tree */ protected $configTree; @@ -48,7 +49,7 @@ class ConfigurationController extends Controller } /** - * Prepares config tree + * Prepares config tree. * * @return void */ @@ -82,7 +83,7 @@ class ConfigurationController extends Controller } /** - * Returns slugs + * Returns slugs. * * @return array */ @@ -114,7 +115,7 @@ class ConfigurationController extends Controller { Event::dispatch('core.configuration.save.before'); - $this->coreConfigRepository->create(request()->all()); + $this->coreConfigRepository->create($request->except(['_token', 'admin_locale'])); Event::dispatch('core.configuration.save.after'); @@ -124,7 +125,7 @@ class ConfigurationController extends Controller } /** - * download the file for the specified resource. + * Download the file for the specified resource. * * @return \Illuminate\Http\Response */ @@ -132,7 +133,7 @@ class ConfigurationController extends Controller { $path = request()->route()->parameters()['path']; - $fileName = 'configuration/'. $path; + $fileName = 'configuration/' . $path; $config = $this->coreConfigRepository->findOneByField('value', $fileName); @@ -140,6 +141,8 @@ class ConfigurationController extends Controller } /** + * Get slugs. + * * @param string $secondItem * @return array */ @@ -149,4 +152,4 @@ class ConfigurationController extends Controller return ['slug' => current($temp), 'slug2' => end($temp)]; } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/Http/Middleware/Locale.php b/packages/Webkul/Admin/src/Http/Middleware/Locale.php new file mode 100755 index 000000000..08cddd09d --- /dev/null +++ b/packages/Webkul/Admin/src/Http/Middleware/Locale.php @@ -0,0 +1,56 @@ +locale = $locale; + } + + /** + * Handle an incoming request. + * + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * @return mixed + */ + public function handle($request, Closure $next) + { + $locale = request()->get('admin_locale'); + + if ($locale) { + if ($this->locale->findOneByField('code', $locale)) { + app()->setLocale($locale); + + session()->put('admin_locale', $locale); + } + } else { + if ($locale = session()->get('admin_locale')) { + app()->setLocale($locale); + } else { + app()->setLocale(app()->getLocale()); + } + } + + unset($request['admin_locale']); + + return $next($request); + } +} diff --git a/packages/Webkul/Admin/src/Http/routes.php b/packages/Webkul/Admin/src/Http/routes.php index 62ef50969..01c8c9b31 100755 --- a/packages/Webkul/Admin/src/Http/routes.php +++ b/packages/Webkul/Admin/src/Http/routes.php @@ -1,6 +1,6 @@ ['web']], function () { +Route::group(['middleware' => ['web', 'admin_locale']], function () { Route::prefix(config('app.admin_url'))->group(function () { Route::get('/', 'Webkul\Admin\Http\Controllers\Controller@redirectToLogin'); diff --git a/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php b/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php index ce0abf143..0b8a55b59 100755 --- a/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php +++ b/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php @@ -2,8 +2,10 @@ namespace Webkul\Admin\Providers; -use Illuminate\Support\ServiceProvider; use Webkul\Core\Tree; +use Illuminate\Routing\Router; +use Illuminate\Support\ServiceProvider; +use Webkul\Admin\Http\Middleware\Locale; class AdminServiceProvider extends ServiceProvider { @@ -12,12 +14,13 @@ class AdminServiceProvider extends ServiceProvider * * @return void */ - public function boot() + public function boot(Router $router) { $this->loadRoutesFrom(__DIR__ . '/../Http/routes.php'); $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'admin'); - $this->publishes([__DIR__.'/../Resources/lang' => resource_path('lang/vendor/admin')]); + + $this->publishes([__DIR__ . '/../Resources/lang' => resource_path('lang/vendor/admin')]); $this->publishes([ __DIR__ . '/../../publishable/assets' => public_path('vendor/webkul/admin/assets'), @@ -29,6 +32,8 @@ class AdminServiceProvider extends ServiceProvider $this->registerACL(); + $router->aliasMiddleware('admin_locale', Locale::class); + $this->app->register(EventServiceProvider::class); } @@ -43,7 +48,7 @@ class AdminServiceProvider extends ServiceProvider } /** - * Bind the the data to the views + * Bind the data to the views. * * @return void */ @@ -118,7 +123,7 @@ class AdminServiceProvider extends ServiceProvider } /** - * Create acl tree + * Create ACL tree. * * @return mixed */ @@ -149,15 +154,18 @@ class AdminServiceProvider extends ServiceProvider protected function registerConfig() { $this->mergeConfigFrom( - dirname(__DIR__) . '/Config/menu.php', 'menu.admin' + dirname(__DIR__) . '/Config/menu.php', + 'menu.admin' ); $this->mergeConfigFrom( - dirname(__DIR__) . '/Config/acl.php', 'acl' + dirname(__DIR__) . '/Config/acl.php', + 'acl' ); $this->mergeConfigFrom( - dirname(__DIR__) . '/Config/system.php', 'core' + dirname(__DIR__) . '/Config/system.php', + 'core' ); } } diff --git a/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php index 71daa0b7b..6e8238ddc 100755 --- a/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php @@ -7,14 +7,9 @@ @section('content')
@php - $locale = request()->get('locale') ?: app()->getLocale(); - $channel = request()->get('channel') ?: core()->getDefaultChannelCode(); - - $channelLocales = app('Webkul\Core\Repositories\ChannelRepository')->findOneByField('code', $channel)->locales; - - if (! $channelLocales->contains('code', $locale)) { - $locale = config('app.fallback_locale'); - } + $locale = core()->checkRequestedLocaleCodeInRequestedChannel(); + $channel = core()->getRequestedChannelCode(); + $channelLocales = core()->getAllLocalesByRequestedChannel()['locales']; @endphp {!! view_render_event('bagisto.admin.catalog.product.edit.before', ['product' => $product]) !!} diff --git a/packages/Webkul/Admin/src/Resources/views/configuration/field-type.blade.php b/packages/Webkul/Admin/src/Resources/views/configuration/field-type.blade.php index 7f6790835..c7a696916 100755 --- a/packages/Webkul/Admin/src/Resources/views/configuration/field-type.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/configuration/field-type.blade.php @@ -64,8 +64,8 @@ $field['options'] = ''; } - $selectedOption = core()->getConfigData($name) ?? ''; - $dependSelectedOption = core()->getConfigData(implode('.', [$firstField, $secondField, $thirdField, $dependField])) ?? ''; + $selectedOption = core()->getConfigData($name, $channel, $locale) ?? ''; + $dependSelectedOption = core()->getConfigData(implode('.', [$firstField, $secondField, $thirdField, $dependField]), $channel, $locale) ?? ''; ?> @if (strpos($field['validation'], 'required_if') !== false) @@ -110,31 +110,31 @@ @if ($field['type'] == 'text') - + @elseif ($field['type'] == 'password') - + @elseif ($field['type'] == 'number') - + @elseif ($field['type'] == 'color') - + @elseif ($field['type'] == 'textarea') - + @elseif ($field['type'] == 'select') getConfigData($name) ?? ''; + $selectedOption = core()->getConfigData($name, $channel, $locale) ?? ''; ?> @if (isset($field['repository'])) @@ -208,7 +208,7 @@ @elseif ($field['type'] == 'country') getConfigData($name) ?? ''; + $countryCode = core()->getConfigData($name, $channel, $locale) ?? ''; ?> getConfigData($name) ?? ''; + $stateCode = core()->getConfigData($name, $channel, $locale) ?? ''; ?> getConfigData($name) ?? (isset($field['default_value']) ? $field['default_value'] : ''); ?> + getConfigData($name, $channel, $locale) ?? (isset($field['default_value']) ? $field['default_value'] : ''); ?>