Merge pull request #4915 from devansh-webkul/multi-lang-support
Enhancement completed multi-lang support in admin #4257
This commit is contained in:
commit
39ee02475d
|
|
@ -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)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Admin\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Webkul\Core\Repositories\LocaleRepository;
|
||||
|
||||
class Locale
|
||||
{
|
||||
/**
|
||||
* Locale repository.
|
||||
*
|
||||
* @var LocaleRepository
|
||||
*/
|
||||
protected $locale;
|
||||
|
||||
/**
|
||||
* Create a new middleware instance.
|
||||
*
|
||||
* @param \Webkul\Core\Repositories\LocaleRepository $locale
|
||||
*/
|
||||
public function __construct(LocaleRepository $locale)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
Route::group(['middleware' => ['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');
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,14 +7,9 @@
|
|||
@section('content')
|
||||
<div class="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]) !!}
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
<input type="text" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: (core()->getConfigData($name) ? core()->getConfigData($name) : (isset($field['default_value']) ? $field['default_value'] : '')) }}" data-vv-as=""{{ trans($field['title']) }}"">
|
||||
<input type="text" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: (core()->getConfigData($name, $channel, $locale) ? core()->getConfigData($name, $channel, $locale) : (isset($field['default_value']) ? $field['default_value'] : '')) }}" data-vv-as=""{{ trans($field['title']) }}"">
|
||||
|
||||
@elseif ($field['type'] == 'password')
|
||||
|
||||
<input type="password" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as=""{{ trans($field['title']) }}"">
|
||||
<input type="password" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as=""{{ trans($field['title']) }}"">
|
||||
|
||||
@elseif ($field['type'] == 'number')
|
||||
|
||||
<input type="number" min="0" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as=""{{ trans($field['title']) }}"">
|
||||
<input type="number" min="0" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as=""{{ trans($field['title']) }}"">
|
||||
|
||||
@elseif ($field['type'] == 'color')
|
||||
|
||||
<input type="color" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as=""{{ trans($field['title']) }}"">
|
||||
<input type="color" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as=""{{ trans($field['title']) }}"">
|
||||
|
||||
|
||||
@elseif ($field['type'] == 'textarea')
|
||||
|
||||
<textarea v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as=""{{ trans($field['title']) }}"">{{ old($name) ?: core()->getConfigData($name) ?: (isset($field['default_value']) ? $field['default_value'] : '') }}</textarea>
|
||||
<textarea v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as=""{{ trans($field['title']) }}"">{{ old($name) ?: core()->getConfigData($name, $channel, $locale) ?: (isset($field['default_value']) ? $field['default_value'] : '') }}</textarea>
|
||||
|
||||
@elseif ($field['type'] == 'select')
|
||||
|
||||
<select v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" data-vv-as=""{{ trans($field['title']) }}"" >
|
||||
|
||||
<?php
|
||||
$selectedOption = core()->getConfigData($name) ?? '';
|
||||
$selectedOption = core()->getConfigData($name, $channel, $locale) ?? '';
|
||||
?>
|
||||
|
||||
@if (isset($field['repository']))
|
||||
|
|
@ -172,7 +172,7 @@
|
|||
<select v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}][]" data-vv-as=""{{ trans($field['title']) }}"" multiple>
|
||||
|
||||
<?php
|
||||
$selectedOption = core()->getConfigData($name) ?? '';
|
||||
$selectedOption = core()->getConfigData($name, $channel, $locale) ?? '';
|
||||
?>
|
||||
|
||||
@if (isset($field['repository']))
|
||||
|
|
@ -208,7 +208,7 @@
|
|||
@elseif ($field['type'] == 'country')
|
||||
|
||||
<?php
|
||||
$countryCode = core()->getConfigData($name) ?? '';
|
||||
$countryCode = core()->getConfigData($name, $channel, $locale) ?? '';
|
||||
?>
|
||||
|
||||
<country
|
||||
|
|
@ -220,7 +220,7 @@
|
|||
@elseif ($field['type'] == 'state')
|
||||
|
||||
<?php
|
||||
$stateCode = core()->getConfigData($name) ?? '';
|
||||
$stateCode = core()->getConfigData($name, $channel, $locale) ?? '';
|
||||
?>
|
||||
|
||||
<state
|
||||
|
|
@ -231,7 +231,7 @@
|
|||
|
||||
@elseif ($field['type'] == 'boolean')
|
||||
|
||||
<?php $selectedOption = core()->getConfigData($name) ?? (isset($field['default_value']) ? $field['default_value'] : ''); ?>
|
||||
<?php $selectedOption = core()->getConfigData($name, $channel, $locale) ?? (isset($field['default_value']) ? $field['default_value'] : ''); ?>
|
||||
|
||||
<label class="switch">
|
||||
<input type="hidden" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="0" />
|
||||
|
|
@ -242,8 +242,8 @@
|
|||
@elseif ($field['type'] == 'image')
|
||||
|
||||
<?php
|
||||
$src = Storage::url(core()->getConfigData($name));
|
||||
$result = core()->getConfigData($name);
|
||||
$src = Storage::url(core()->getConfigData($name, $channel, $locale));
|
||||
$result = core()->getConfigData($name, $channel, $locale);
|
||||
?>
|
||||
|
||||
@if ($result)
|
||||
|
|
@ -252,7 +252,7 @@
|
|||
</a>
|
||||
@endif
|
||||
|
||||
<input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as=""{{ trans($field['title']) }}"" style="padding-top: 5px;">
|
||||
<input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as=""{{ trans($field['title']) }}"" style="padding-top: 5px;">
|
||||
|
||||
@if ($result)
|
||||
<div class="control-group" style="margin-top: 5px;">
|
||||
|
|
@ -268,7 +268,7 @@
|
|||
@elseif ($field['type'] == 'file')
|
||||
|
||||
<?php
|
||||
$result = core()->getConfigData($name);
|
||||
$result = core()->getConfigData($name, $channel, $locale);
|
||||
$src = explode("/", $result);
|
||||
$path = end($src);
|
||||
?>
|
||||
|
|
@ -279,7 +279,7 @@
|
|||
</a>
|
||||
@endif
|
||||
|
||||
<input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name) }}" data-vv-as=""{{ trans($field['title']) }}"" style="padding-top: 5px;">
|
||||
<input type="file" v-validate="'{{ $validations }}'" class="control" id="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" name="{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]" value="{{ old($name) ?: core()->getConfigData($name, $channel, $locale) }}" data-vv-as=""{{ trans($field['title']) }}"" style="padding-top: 5px;">
|
||||
|
||||
@if ($result)
|
||||
<div class="control-group" style="margin-top: 5px;">
|
||||
|
|
|
|||
|
|
@ -7,14 +7,9 @@
|
|||
@section('content')
|
||||
<div class="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
|
||||
|
||||
<form method="POST" action="" @submit.prevent="onSubmit" enctype="multipart/form-data">
|
||||
|
|
|
|||
|
|
@ -16,6 +16,42 @@
|
|||
<span class="avatar">
|
||||
</span>
|
||||
|
||||
<div class="profile-info">
|
||||
@php
|
||||
$allLocales = core()->getAllLocales()->pluck('name', 'code');
|
||||
|
||||
$currentLocaleCode = core()->getRequestedLocaleCode('admin_locale');
|
||||
@endphp
|
||||
|
||||
<div class="dropdown-toggle">
|
||||
<div style="display: inline-block; vertical-align: middle;">
|
||||
<span class="name">
|
||||
{{ __('admin::app.datagrid.locale') }}
|
||||
</span>
|
||||
|
||||
<span class="role">
|
||||
{{ $allLocales[$currentLocaleCode] }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<i class="icon arrow-down-icon active"></i>
|
||||
</div>
|
||||
|
||||
<div class="dropdown-list bottom-right">
|
||||
<div class="dropdown-container">
|
||||
<ul>
|
||||
@foreach ($allLocales as $code => $name)
|
||||
<li>
|
||||
<a href="{{ url()->current() . '?' . http_build_query(array_merge(request()->all(), ['admin_locale' => $code])) }}">
|
||||
{{ $name }}
|
||||
</a>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="profile-info">
|
||||
<div class="dropdown-toggle">
|
||||
<div style="display: inline-block; vertical-align: middle;">
|
||||
|
|
|
|||
|
|
@ -232,6 +232,16 @@ class Core
|
|||
return ($channel = $this->getDefaultChannel()) ? $channelCode = $channel->code : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get channel code from request.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestedChannelCode(): string
|
||||
{
|
||||
return request()->get('channel') ?: ($this->getCurrentChannelCode() ?: $this->getDefaultChannelCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the channel name.
|
||||
*
|
||||
|
|
@ -245,7 +255,7 @@ class Core
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all locales
|
||||
* Return all locales.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
|
|
@ -260,6 +270,27 @@ class Core
|
|||
return $locales = $this->localeRepository->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all locales which are present in requested channel.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllLocalesByRequestedChannel()
|
||||
{
|
||||
static $data = [];
|
||||
|
||||
if (! empty($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$channel = $this->channelRepository->findOneByField('code', $this->getRequestedChannelCode());
|
||||
|
||||
return $data = [
|
||||
'channel' => $channel,
|
||||
'locales' => $channel->locales
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current locale.
|
||||
*
|
||||
|
|
@ -282,6 +313,35 @@ class Core
|
|||
return $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get locale code from request. Here if you want to use admin locale,
|
||||
* you can pass it as an argument.
|
||||
*
|
||||
* @param string $localeKey optional
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestedLocaleCode($localeKey = 'locale'): string
|
||||
{
|
||||
return request()->get($localeKey) ?: app()->getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check requested locale code in requested channel. If not found,
|
||||
* then set channel default locale code.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function checkRequestedLocaleCodeInRequestedChannel()
|
||||
{
|
||||
$localeCode = $this->getRequestedLocaleCode();
|
||||
|
||||
$channelLocales = $this->getAllLocalesByRequestedChannel();
|
||||
|
||||
return ! $channelLocales['locales']->contains('code', $localeCode)
|
||||
? $channelLocales['channel']->default_locale->code
|
||||
: $localeCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all customer groups.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ class CoreConfigRepository extends Repository
|
|||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
unset($data['_token']);
|
||||
|
||||
if ($data['locale'] || $data['channel']) {
|
||||
$locale = $data['locale'];
|
||||
$channel = $data['channel'];
|
||||
|
|
|
|||
|
|
@ -391,9 +391,8 @@ class Product extends Model implements ProductContract
|
|||
return;
|
||||
}
|
||||
|
||||
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
|
||||
|
||||
$locale = request()->get('locale') ?: app()->getLocale();
|
||||
$locale = core()->checkRequestedLocaleCodeInRequestedChannel();
|
||||
$channel = core()->getRequestedChannelCode();
|
||||
|
||||
if ($attribute->value_per_channel) {
|
||||
if ($attribute->value_per_locale) {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"/js/ui.js": "/js/ui.js?id=ced6a4796cf138d5cb34",
|
||||
"/js/ui.js": "/js/ui.js?id=1a2a11fc54d0a5962a66",
|
||||
"/css/ui.css": "/css/ui.css?id=6d93a4a052e38d6aa795"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1355,7 +1355,7 @@
|
|||
break;
|
||||
}
|
||||
|
||||
if (obj.column !== undefined && obj.val !== undefined) {
|
||||
if (obj.column !== undefined && obj.column !== 'admin_locale' && obj.val !== undefined) {
|
||||
this.filters.push(obj);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -782,7 +782,7 @@
|
|||
break;
|
||||
}
|
||||
|
||||
if (obj.column !== undefined && obj.val !== undefined) {
|
||||
if (obj.column !== undefined && obj.column !== 'admin_locale' && obj.val !== undefined) {
|
||||
this.filters.push(obj);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ class Helper extends Review
|
|||
/**
|
||||
* Returns the count rating of the product.
|
||||
*
|
||||
* @return array
|
||||
* @return \Webkul\Velocity\Repositories\VelocityMetadataRepository
|
||||
*/
|
||||
public function getVelocityMetaData($locale = null, $channel = null, $default = true)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Webkul\Velocity\Http\Controllers\Admin;
|
|||
|
||||
use Illuminate\Support\Str;
|
||||
use Webkul\Core\Traits\Sanitizer;
|
||||
use Webkul\Velocity\Helpers\Helper;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Webkul\Velocity\Repositories\VelocityMetadataRepository;
|
||||
|
||||
|
|
@ -12,17 +13,14 @@ class ConfigurationController extends Controller
|
|||
use Sanitizer;
|
||||
|
||||
/**
|
||||
* Locale
|
||||
* Velocity helper instance.
|
||||
*
|
||||
* @var \Webkul\Velocity\Helpers\Helper
|
||||
*/
|
||||
protected $locale;
|
||||
protected $velocityHelper;
|
||||
|
||||
/**
|
||||
* Channel
|
||||
*/
|
||||
protected $channel;
|
||||
|
||||
/**
|
||||
* VelocityMetadataRepository $velocityMetaDataRepository
|
||||
* Velocity meta data repository intance.
|
||||
*
|
||||
* @var \Webkul\Velocity\Repositories\VelocityMetadataRepository
|
||||
*/
|
||||
|
|
@ -34,15 +32,16 @@ class ConfigurationController extends Controller
|
|||
* @param \Webkul\Velocity\Repositories\MetadataRepository $velocityMetaDataRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct (VelocityMetadataRepository $velocityMetadataRepository)
|
||||
public function __construct (
|
||||
Helper $velocityHelper,
|
||||
VelocityMetadataRepository $velocityMetadataRepository
|
||||
)
|
||||
{
|
||||
$this->_config = request('_config');
|
||||
|
||||
$this->velocityHelper = app('Webkul\Velocity\Helpers\Helper');
|
||||
$this->velocityMetaDataRepository = $velocityMetadataRepository;
|
||||
$this->velocityHelper = $velocityHelper;
|
||||
|
||||
$this->locale = request()->get('locale') ?: app()->getLocale();
|
||||
$this->channel = request()->get('channel') ?: 'default';
|
||||
$this->velocityMetaDataRepository = $velocityMetadataRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,14 +51,16 @@ class ConfigurationController extends Controller
|
|||
*/
|
||||
public function renderMetaData()
|
||||
{
|
||||
$this->locale = request()->get('locale') ? request()->get('locale') : app()->getLocale();
|
||||
$locale = core()->checkRequestedLocaleCodeInRequestedChannel();
|
||||
|
||||
$velocityMetaData = $this->velocityHelper->getVelocityMetaData($this->locale, $this->channel, false);
|
||||
$channel = core()->getRequestedChannelCode();
|
||||
|
||||
$velocityMetaData = $this->velocityHelper->getVelocityMetaData($locale, $channel, false);
|
||||
|
||||
if (! $velocityMetaData) {
|
||||
$this->createMetaData($this->locale, $this->channel);
|
||||
$this->createMetaData($locale, $channel);
|
||||
|
||||
$velocityMetaData = $this->velocityHelper->getVelocityMetaData($this->locale, $this->channel);
|
||||
$velocityMetaData = $this->velocityHelper->getVelocityMetaData($locale, $channel);
|
||||
}
|
||||
|
||||
$velocityMetaData->advertisement = $this->manageAddImages(json_decode($velocityMetaData->advertisement, true) ?: []);
|
||||
|
|
@ -77,7 +78,9 @@ class ConfigurationController extends Controller
|
|||
*/
|
||||
public function storeMetaData($id)
|
||||
{
|
||||
// check if radio button value
|
||||
$locale = core()->checkRequestedLocaleCodeInRequestedChannel();
|
||||
|
||||
/* check if radio button value */
|
||||
if (request()->get('slides') == "on") {
|
||||
$params = request()->all() + [
|
||||
'slider' => 1,
|
||||
|
|
@ -118,14 +121,14 @@ class ConfigurationController extends Controller
|
|||
unset($params['images']);
|
||||
unset($params['slides']);
|
||||
|
||||
$params['locale'] = $this->locale;
|
||||
$params['locale'] = $locale;
|
||||
|
||||
// update row
|
||||
$product = $this->velocityMetaDataRepository->update($params, $id);
|
||||
/* update row */
|
||||
$this->velocityMetaDataRepository->update($params, $id);
|
||||
|
||||
session()->flash('success', trans('admin::app.response.update-success', ['name' => trans('velocity::app.admin.meta-data.title')]));
|
||||
|
||||
return redirect()->route($this->_config['redirect'], ['locale' => $this->locale]);
|
||||
return redirect()->route($this->_config['redirect'], ['locale' => $locale]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -203,7 +206,6 @@ class ConfigurationController extends Controller
|
|||
* Manage add images.
|
||||
*
|
||||
* @param array $addImages
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function manageAddImages($addImages)
|
||||
|
|
@ -233,7 +235,6 @@ class ConfigurationController extends Controller
|
|||
*
|
||||
* @param string $locale
|
||||
* @param string $channel
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function createMetaData($locale, $channel)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
Route::group(['middleware' => ['web']], function () {
|
||||
Route::group(['middleware' => ['web', 'admin_locale']], function () {
|
||||
Route::prefix(config('app.admin_url') . '/velocity')->group(function () {
|
||||
Route::group(['middleware' => ['admin']], function () {
|
||||
Route::namespace('Webkul\Velocity\Http\Controllers\Admin')->group(function () {
|
||||
|
|
|
|||
|
|
@ -5,14 +5,9 @@
|
|||
@stop
|
||||
|
||||
@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
|
||||
|
||||
@section('content')
|
||||
|
|
|
|||
Loading…
Reference in New Issue