Merge pull request #9 from bagisto/master

Update fork
This commit is contained in:
Glenn Hermans 2021-06-14 23:32:20 +02:00 committed by GitHub
commit daea0e63d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 384 additions and 205 deletions

View File

@ -25,9 +25,9 @@ class CartRuleDataGrid extends DataGrid
{
parent::__construct();
$this->customer_group = request()->get('customer_group') ?? 'all';
$this->customer_group = core()->getRequestedCustomerGroupCode() ?? 'all';
$this->channel = request()->get('channel') ?? 'all';
$this->channel = core()->getRequestedChannelCode(false) ?? 'all';
}
public function prepareQueryBuilder()

View File

@ -41,7 +41,7 @@ class ChannelDataGrid extends DataGrid
{
parent::__construct();
$this->locale = request()->get('locale') ?? app()->getLocale();
$this->locale = core()->getRequestedLocaleCode();
$this->channelRepository = $channelRepository;
}

View File

@ -30,10 +30,10 @@ class ProductDataGrid extends DataGrid
parent::__construct();
/* locale */
$this->locale = request()->get('locale') ?? app()->getLocale();
$this->locale = core()->getRequestedLocaleCode();
/* channel */
$this->channel = request()->get('channel') ?? (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$this->channel = core()->getRequestedChannelCode();
/* finding channel code */
if ($this->channel !== 'all') {

View File

@ -31,10 +31,10 @@ class SliderDataGrid extends DataGrid
parent::__construct();
/* locale */
$this->locale = request()->get('locale') ?? app()->getLocale();
$this->locale = core()->getRequestedLocaleCode();
/* channel */
$this->channel = request()->get('channel') ?? (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$this->channel = core()->getRequestedChannelCode();
/* finding channel code */
if ($this->channel !== 'all') {

View File

@ -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)];
}
}
}

View File

@ -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);
}
}

View File

@ -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');

View File

@ -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'
);
}
}

View File

@ -6,7 +6,9 @@
@section('content')
<div class="content">
<?php $locale = request()->get('locale') ?: app()->getLocale(); ?>
@php
$locale = core()->getRequestedLocaleCode();
@endphp
<form method="POST" action="" @submit.prevent="onSubmit" enctype="multipart/form-data">

View File

@ -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]) !!}

View File

@ -6,7 +6,9 @@
@section('content')
<div class="content">
<?php $locale = request()->get('locale') ?: app()->getLocale(); ?>
@php
$locale = core()->getRequestedLocaleCode();
@endphp
<form method="POST" id="page-form" action="" @submit.prevent="onSubmit">

View File

@ -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="&quot;{{ trans($field['title']) }}&quot;">
<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="&quot;{{ trans($field['title']) }}&quot;">
@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="&quot;{{ trans($field['title']) }}&quot;">
<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="&quot;{{ trans($field['title']) }}&quot;">
@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="&quot;{{ trans($field['title']) }}&quot;">
<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="&quot;{{ trans($field['title']) }}&quot;">
@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="&quot;{{ trans($field['title']) }}&quot;">
<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="&quot;{{ trans($field['title']) }}&quot;">
@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="&quot;{{ trans($field['title']) }}&quot;">{{ 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="&quot;{{ trans($field['title']) }}&quot;">{{ 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="&quot;{{ trans($field['title']) }}&quot;" >
<?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="&quot;{{ trans($field['title']) }}&quot;" 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="&quot;{{ trans($field['title']) }}&quot;" 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="&quot;{{ trans($field['title']) }}&quot;" 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="&quot;{{ trans($field['title']) }}&quot;" 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="&quot;{{ trans($field['title']) }}&quot;" style="padding-top: 5px;">
@if ($result)
<div class="control-group" style="margin-top: 5px;">

View File

@ -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">

View File

@ -1,5 +1,5 @@
<script type="text/x-template" id="export-form-template">
<form method="POST" action="{{ route('admin.datagrid.export', ['locale' => request()->get('locale')]) }}" @submit.prevent="onSubmit">
<form method="POST" action="{{ route('admin.datagrid.export', ['locale' => core()->getRequestedLocaleCode()]) }}" @submit.prevent="onSubmit">
<div class="page-content">
<div class="form-container">
@ -36,8 +36,8 @@
var this_this = this;
e.target.submit();
setTimeout(function() {
this_this.$root.$set(this_this.$root.modalIds, 'downloadDataGrid', false);
setTimeout(function() {
this_this.$root.$set(this_this.$root.modalIds, 'downloadDataGrid', false);
}, 0);
}
}

View File

@ -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;">

View File

@ -6,8 +6,11 @@
@section('content')
<div class="content">
<?php $customer_group = request()->get('customer_group') ?: null; ?>
<?php $channel = request()->get('channel') ?: null; ?>
@php
$customer_group = core()->getRequestedCustomerGroupCode();
$channel = core()->getRequestedChannelCode(false);
@endphp
<div class="page-header">
<div class="page-title">
<h1>{{ __('admin::app.promotions.cart-rules.title') }}</h1>
@ -26,6 +29,7 @@
</div>
</div>
@endsection
@push('scripts')
<script>
function reloadPage(getVar, getVal) {
@ -34,6 +38,5 @@
window.location.href = url.href;
}
</script>
@endpush

View File

@ -6,7 +6,7 @@
@section('content')
<div class="content">
@php $locale = request()->get('locale') ?: app()->getLocale(); @endphp
@php $locale = core()->getRequestedLocaleCode(); @endphp
<form method="POST" action="{{ route('admin.channels.update', ['id' => $channel->id, 'locale' => $locale]) }}" @submit.prevent="onSubmit" enctype="multipart/form-data">
<div class="page-header">

View File

@ -6,7 +6,7 @@
@section('content')
<div class="content">
<?php $locale = request()->get('locale') ?: app()->getLocale(); ?>
@php $locale = core()->getRequestedLocaleCode(); @endphp
<form method="POST" action="{{ route('admin.sliders.update', $slider->id) }}" @submit.prevent="onSubmit" enctype="multipart/form-data">
<div class="page-header">

View File

@ -8,8 +8,10 @@
<div class="content">
<?php $locale = request()->get('locale') ?: null; ?>
<?php $channel = request()->get('channel') ?: null; ?>
@php
$locale = core()->getRequestedLocaleCode('locale', false);
$channel = core()->getRequestedChannelCode(false);
@endphp
<div class="page-header">
<div class="page-title">

View File

@ -9,14 +9,14 @@ use Webkul\CMS\Repositories\CmsRepository;
{
/**
* To hold the request variables from route file
*
*
* @var array
*/
protected $_config;
/**
* To hold the CMSRepository instance
*
*
* @var \Webkul\CMS\Repositories\CmsRepository
*/
protected $cmsRepository;
@ -38,7 +38,7 @@ use Webkul\CMS\Repositories\CmsRepository;
/**
* Loads the index page showing the static pages resources
*
*
* @return \Illuminate\View\View
*/
public function index()
@ -71,7 +71,7 @@ use Webkul\CMS\Repositories\CmsRepository;
'channels' => 'required',
'html_content' => 'required',
]);
$page = $this->cmsRepository->create(request()->all());
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'page']));
@ -100,7 +100,7 @@ use Webkul\CMS\Repositories\CmsRepository;
*/
public function update($id)
{
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
$this->validate(request(), [
$locale . '.url_key' => ['required', new \Webkul\Core\Contracts\Validations\Slug, function ($attribute, $value, $fail) use ($id) {

View File

@ -119,7 +119,7 @@ class CategoryController extends Controller
*/
public function update($id)
{
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
$this->validate(request(), [
$locale . '.slug' => ['required', function ($attribute, $value, $fail) use ($id) {

View File

@ -148,7 +148,7 @@ class CategoryRepository extends Repository
get_class($this->model), $slug
);
}
/**
* Retrive category from slug.
*
@ -292,7 +292,7 @@ class CategoryRepository extends Repository
*/
private function setSameAttributeValueToAllLocale(array $data, ...$attributeNames)
{
$requestedLocale = request()->get('locale') ?: app()->getLocale();
$requestedLocale = core()->getRequestedLocaleCode();
$model = app()->make($this->model());

View File

@ -232,6 +232,23 @@ class Core
return ($channel = $this->getDefaultChannel()) ? $channelCode = $channel->code : '';
}
/**
* Get channel code from request.
*
* @param bool $fallback optional
* @return string
*/
public function getRequestedChannelCode($fallback = true)
{
$channelCode = request()->get('channel');
if (! $fallback) {
return $channelCode;
}
return $channelCode ?: ($this->getCurrentChannelCode() ?: $this->getDefaultChannelCode());
}
/**
* Returns the channel name.
*
@ -245,7 +262,7 @@ class Core
}
/**
* Returns all locales
* Return all locales.
*
* @return \Illuminate\Support\Collection
*/
@ -260,6 +277,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 +320,42 @@ 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
* @param bool $fallback optional
* @return string
*/
public function getRequestedLocaleCode($localeKey = 'locale', $fallback = true)
{
$localeCode = request()->get($localeKey);
if (! $fallback) {
return $localeCode;
}
return $localeCode ?: 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.
*
@ -298,6 +372,16 @@ class Core
return $customerGroups = $this->customerGroupRepository->all();
}
/**
* Get requested customer group code.
*
* @return null|string
*/
public function getRequestedCustomerGroupCode()
{
return request()->get('customer_group');
}
/**
* Returns all currencies.
*
@ -732,11 +816,11 @@ class Core
$coreConfigValue = $loadedConfigs[$field];
} else {
if (null === $channel) {
$channel = request()->get('channel') ?: ($this->getCurrentChannelCode() ?: $this->getDefaultChannelCode());
$channel = $this->getRequestedChannelCode();
}
if (null === $locale) {
$locale = request()->get('locale') ?: app()->getLocale();
$locale = $this->getRequestedLocaleCode();
}
$loadedConfigs[$field] = $coreConfigValue = $this->getCoreConfigValue($field, $channel, $locale);

View File

@ -128,7 +128,7 @@ class ChannelController extends Controller
*/
public function update($id)
{
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
$data = $this->validate(request(), [
/* general */

View File

@ -55,9 +55,7 @@ class SliderController extends Controller
*/
public function create()
{
$channels = core()->getAllChannels();
$locale = request()->get('locale') ?: core()->getCurrentLocale();
$locale = core()->getRequestedLocaleCode();
return view($this->_config['view'])->with("locale", $locale);
}

View File

@ -1,48 +1,51 @@
<?php
use Webkul\Core\Core;
if (! function_exists('core')) {
function core()
{
return app()->make(Core::class);
}
if (! function_exists('core')) {
/**
* Core helper.
*
* @return \Webkul\Core\Core
*/
function core()
{
return app()->make(\Webkul\Core\Core::class);
}
}
if (! function_exists('array_permutation')) {
function array_permutation($input)
{
$results = [];
if (! function_exists('array_permutation')) {
function array_permutation($input)
{
$results = [];
foreach ($input as $key => $values) {
if (empty($values)) {
continue;
}
if (empty($results)) {
foreach ($values as $value) {
$results[] = [$key => $value];
}
} else {
$append = [];
foreach ($results as &$result) {
$result[$key] = array_shift($values);
$copy = $result;
foreach ($values as $item) {
$copy[$key] = $item;
$append[] = $copy;
}
array_unshift($values, $result[$key]);
}
$results = array_merge($results, $append);
}
foreach ($input as $key => $values) {
if (empty($values)) {
continue;
}
return $results;
if (empty($results)) {
foreach ($values as $value) {
$results[] = [$key => $value];
}
} else {
$append = [];
foreach ($results as &$result) {
$result[$key] = array_shift($values);
$copy = $result;
foreach ($values as $item) {
$copy[$key] = $item;
$append[] = $copy;
}
array_unshift($values, $result[$key]);
}
$results = array_merge($results, $append);
}
}
return $results;
}
?>
}

View File

@ -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'];

View File

@ -25,9 +25,9 @@ abstract class AbstractProduct
*/
public function applyChannelLocaleFilter($attribute, $qb, $alias = 'product_attribute_values')
{
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$channel = core()->getRequestedChannelCode();
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
if ($attribute->value_per_channel) {
if ($attribute->value_per_locale) {

View File

@ -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) {

View File

@ -75,7 +75,7 @@ class ProductDownloadableLink extends TranslatableModel implements ProductDownlo
{
$array = parent::toArray();
$translation = $this->translate(request()->get('locale') ?: app()->getLocale());
$translation = $this->translate(core()->getRequestedLocaleCode());
$array['title'] = $translation ? $translation->title : '';

View File

@ -52,8 +52,7 @@ class ProductDownloadableSample extends TranslatableModel implements ProductDown
{
$array = parent::toArray();
$translation = $this->translate(request()->get('locale') ?: app()->getLocale());
$translation = $this->translate(core()->getRequestedLocaleCode());
$array['title'] = $translation ? $translation->title : '';

View File

@ -149,9 +149,9 @@ class ProductRepository extends Repository
$page = Paginator::resolveCurrentPage('page');
$repository = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($params, $categoryId) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$channel = core()->getRequestedChannelCode();
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
$qb = $query->distinct()
->select('product_flat.*')
@ -375,9 +375,9 @@ class ProductRepository extends Repository
$count = core()->getConfigData('catalog.products.homepage.no_of_new_product_homepage');
$results = app(ProductFlatRepository::class)->scopeQuery(function ($query) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$channel = core()->getRequestedChannelCode();
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
return $query->distinct()
->addSelect('product_flat.*')
@ -402,9 +402,9 @@ class ProductRepository extends Repository
$count = core()->getConfigData('catalog.products.homepage.no_of_featured_product_homepage');
$results = app(ProductFlatRepository::class)->scopeQuery(function ($query) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$channel = core()->getRequestedChannelCode();
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
return $query->distinct()
->addSelect('product_flat.*')
@ -428,9 +428,9 @@ class ProductRepository extends Repository
*/
public function searchProductByAttribute($term)
{
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$channel = core()->getRequestedChannelCode();
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
if (config('scout.driver') == 'algolia') {
$results = app(ProductFlatRepository::class)->getModel()::search('query', function ($searchDriver, string $query, array $options) use ($term, $channel, $locale) {
@ -529,9 +529,9 @@ class ProductRepository extends Repository
public function searchSimpleProducts($term)
{
return app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($term) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$channel = core()->getRequestedChannelCode();
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
return $query->distinct()
->addSelect('product_flat.*')

View File

@ -29,7 +29,7 @@ class Locale
*/
public function handle($request, Closure $next)
{
$locale = request()->get('locale');
$locale = core()->getRequestedLocaleCode('locale', false);
if ($locale) {
if ($this->locale->findOneByField('code', $locale)) {

View File

@ -2,7 +2,7 @@
$attributeRepository = app('\Webkul\Attribute\Repositories\AttributeFamilyRepository');
$comparableAttributes = $attributeRepository->getComparableAttributesBelongsToFamily();
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
$attributeOptionTranslations = DB::table('attribute_option_translations')->where('locale', $locale)->get()->toJson();
@endphp

File diff suppressed because one or more lines are too long

View File

@ -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"
}

View File

@ -85,9 +85,9 @@ trait ProvideDataGridPlus
$locales = core()->getAllLocales();
/* request and fallback handling */
$locale = request()->get('locale') ?: app()->getLocale();
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$customer_group = request()->get('customer_group');
$locale = core()->getRequestedLocaleCode();
$channel = core()->getRequestedChannelCode();
$customer_group = core()->getRequestedCustomerGroupCode();
/* handling cases for new locale if not present in current channel */
if ($channel !== 'all') {

View File

@ -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);
}

View File

@ -3,9 +3,9 @@
$locales = core()->getAllLocales();
/* request and fallback handling */
$locale = request()->get('locale') ?: app()->getLocale();
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$customer_group = request()->get('customer_group');
$locale = core()->getRequestedLocaleCode();
$channel = core()->getRequestedChannelCode();
$customer_group = core()->getRequestedCustomerGroupCode();
/* handling cases for new locale if not present in current channel */
if ($channel !== 'all') {
@ -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);
}

View File

@ -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)
{
@ -205,11 +205,11 @@ class Helper extends Review
}
if (! $locale) {
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
}
if (! $channel) {
$channel = request()->get('channel') ?: core()->getCurrentChannelCode() ?: 'default';
$channel = core()->getRequestedChannelCode();
}
try {

View File

@ -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)

View File

@ -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 () {

View File

@ -98,7 +98,7 @@ class ContentRepository extends Repository
{
$results = [];
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
$content = $this->model->find($id);

View File

@ -56,9 +56,9 @@ class ProductRepository extends Repository
public function getFeaturedProducts($count)
{
$results = app(ProductFlatRepository::class)->scopeQuery(function($query) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$channel = core()->getRequestedChannelCode();
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
return $query->distinct()
->addSelect('product_flat.*')
@ -82,9 +82,9 @@ class ProductRepository extends Repository
public function getNewProducts($count)
{
$results = app(ProductFlatRepository::class)->scopeQuery(function($query) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$channel = core()->getRequestedChannelCode();
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
return $query->distinct()
->addSelect('product_flat.*')
@ -112,9 +112,9 @@ class ProductRepository extends Repository
$categoryId = $params['category'] ?? '';
$results = app(ProductFlatRepository::class)->scopeQuery(function($query) use($term, $categoryId, $params) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$channel = core()->getRequestedChannelCode();
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) {
$query = app('Webkul\Product\Repositories\ProductRepository')->checkOutOfStockItem($query);

View File

@ -7,7 +7,7 @@
@section('content')
<div class="content">
<?php $locale = request()->get('locale') ?: app()->getLocale(); ?>
@php $locale = core()->getRequestedLocaleCode(); @endphp
<form method="POST" action="" @submit.prevent="onSubmit" enctype="multipart/form-data">

View File

@ -7,7 +7,7 @@
@section('content')
<div class="content">
@php
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
$translation = $content->translations->where('locale', $locale)->first();
@endphp

View File

@ -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')

View File

@ -42,7 +42,7 @@
error_message: '',
applied_coupon: "{{ $cart->coupon_code }}",
route_name: "{{ request()->route()->getName() }}",
disable_button: ("{{ $cart->coupon_code }}" == "" ? false : true),
disable_button: false,
}
},

View File

@ -2,7 +2,7 @@
$attributeRepository = app('\Webkul\Attribute\Repositories\AttributeFamilyRepository');
$comparableAttributes = $attributeRepository->getComparableAttributesBelongsToFamily();
$locale = request()->get('locale') ?: app()->getLocale();
$locale = core()->getRequestedLocaleCode();
$attributeOptionTranslations = app('\Webkul\Attribute\Repositories\AttributeOptionTranslationRepository')->where('locale', $locale)->get()->toJson();
@endphp