All Locales Request Are Not Centralized In Core Method

This commit is contained in:
devansh bawari 2021-06-09 13:11:14 +05:30
parent 85cf69b27a
commit de533e0541
30 changed files with 91 additions and 85 deletions

View File

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

View File

@ -30,7 +30,7 @@ class ProductDataGrid extends DataGrid
parent::__construct(); parent::__construct();
/* locale */ /* locale */
$this->locale = request()->get('locale') ?? app()->getLocale(); $this->locale = core()->getRequestedLocaleCode();
/* channel */ /* channel */
$this->channel = request()->get('channel') ?? (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $this->channel = request()->get('channel') ?? (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());

View File

@ -31,7 +31,7 @@ class SliderDataGrid extends DataGrid
parent::__construct(); parent::__construct();
/* locale */ /* locale */
$this->locale = request()->get('locale') ?? app()->getLocale(); $this->locale = core()->getRequestedLocaleCode();
/* channel */ /* channel */
$this->channel = request()->get('channel') ?? (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $this->channel = request()->get('channel') ?? (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());

View File

@ -6,7 +6,9 @@
@section('content') @section('content')
<div class="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"> <form method="POST" action="" @submit.prevent="onSubmit" enctype="multipart/form-data">

View File

@ -6,7 +6,9 @@
@section('content') @section('content')
<div class="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"> <form method="POST" id="page-form" action="" @submit.prevent="onSubmit">

View File

@ -1,5 +1,5 @@
<script type="text/x-template" id="export-form-template"> <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="page-content">
<div class="form-container"> <div class="form-container">

View File

@ -6,7 +6,7 @@
@section('content') @section('content')
<div class="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"> <form method="POST" action="{{ route('admin.channels.update', ['id' => $channel->id, 'locale' => $locale]) }}" @submit.prevent="onSubmit" enctype="multipart/form-data">
<div class="page-header"> <div class="page-header">

View File

@ -6,7 +6,7 @@
@section('content') @section('content')
<div class="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"> <form method="POST" action="{{ route('admin.sliders.update', $slider->id) }}" @submit.prevent="onSubmit" enctype="multipart/form-data">
<div class="page-header"> <div class="page-header">

View File

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

View File

@ -100,7 +100,7 @@ use Webkul\CMS\Repositories\CmsRepository;
*/ */
public function update($id) public function update($id)
{ {
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
$this->validate(request(), [ $this->validate(request(), [
$locale . '.url_key' => ['required', new \Webkul\Core\Contracts\Validations\Slug, function ($attribute, $value, $fail) use ($id) { $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) public function update($id)
{ {
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
$this->validate(request(), [ $this->validate(request(), [
$locale . '.slug' => ['required', function ($attribute, $value, $fail) use ($id) { $locale . '.slug' => ['required', function ($attribute, $value, $fail) use ($id) {

View File

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

View File

@ -796,7 +796,7 @@ class Core
} }
if (null === $locale) { if (null === $locale) {
$locale = request()->get('locale') ?: app()->getLocale(); $locale = $this->getRequestedLocaleCode();
} }
$loadedConfigs[$field] = $coreConfigValue = $this->getCoreConfigValue($field, $channel, $locale); $loadedConfigs[$field] = $coreConfigValue = $this->getCoreConfigValue($field, $channel, $locale);

View File

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

View File

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

View File

@ -1,48 +1,51 @@
<?php <?php
use Webkul\Core\Core;
if (! function_exists('core')) { if (! function_exists('core')) {
function core() /**
{ * Core helper.
return app()->make(Core::class); *
} * @return \Webkul\Core\Core
*/
function core()
{
return app()->make(\Webkul\Core\Core::class);
} }
}
if (! function_exists('array_permutation')) { if (! function_exists('array_permutation')) {
function array_permutation($input) function array_permutation($input)
{ {
$results = []; $results = [];
foreach ($input as $key => $values) { foreach ($input as $key => $values) {
if (empty($values)) { if (empty($values)) {
continue; 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);
}
} }
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

@ -27,7 +27,7 @@ abstract class AbstractProduct
{ {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
if ($attribute->value_per_channel) { if ($attribute->value_per_channel) {
if ($attribute->value_per_locale) { if ($attribute->value_per_locale) {

View File

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

View File

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

View File

@ -151,7 +151,7 @@ class ProductRepository extends Repository
$repository = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($params, $categoryId) { $repository = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($params, $categoryId) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
$qb = $query->distinct() $qb = $query->distinct()
->select('product_flat.*') ->select('product_flat.*')
@ -377,7 +377,7 @@ class ProductRepository extends Repository
$results = app(ProductFlatRepository::class)->scopeQuery(function ($query) { $results = app(ProductFlatRepository::class)->scopeQuery(function ($query) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
return $query->distinct() return $query->distinct()
->addSelect('product_flat.*') ->addSelect('product_flat.*')
@ -404,7 +404,7 @@ class ProductRepository extends Repository
$results = app(ProductFlatRepository::class)->scopeQuery(function ($query) { $results = app(ProductFlatRepository::class)->scopeQuery(function ($query) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
return $query->distinct() return $query->distinct()
->addSelect('product_flat.*') ->addSelect('product_flat.*')
@ -430,7 +430,7 @@ class ProductRepository extends Repository
{ {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
if (config('scout.driver') == 'algolia') { if (config('scout.driver') == 'algolia') {
$results = app(ProductFlatRepository::class)->getModel()::search('query', function ($searchDriver, string $query, array $options) use ($term, $channel, $locale) { $results = app(ProductFlatRepository::class)->getModel()::search('query', function ($searchDriver, string $query, array $options) use ($term, $channel, $locale) {
@ -531,7 +531,7 @@ class ProductRepository extends Repository
return app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($term) { return app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($term) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
return $query->distinct() return $query->distinct()
->addSelect('product_flat.*') ->addSelect('product_flat.*')

View File

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

View File

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

View File

@ -85,7 +85,7 @@ trait ProvideDataGridPlus
$locales = core()->getAllLocales(); $locales = core()->getAllLocales();
/* request and fallback handling */ /* request and fallback handling */
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$customer_group = request()->get('customer_group'); $customer_group = request()->get('customer_group');

View File

@ -3,7 +3,7 @@
$locales = core()->getAllLocales(); $locales = core()->getAllLocales();
/* request and fallback handling */ /* request and fallback handling */
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$customer_group = request()->get('customer_group'); $customer_group = request()->get('customer_group');

View File

@ -187,7 +187,7 @@ class Helper extends Review
} }
if (! $locale) { if (! $locale) {
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
} }
if (! $channel) { if (! $channel) {

View File

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

View File

@ -58,7 +58,7 @@ class ProductRepository extends Repository
$results = app(ProductFlatRepository::class)->scopeQuery(function($query) { $results = app(ProductFlatRepository::class)->scopeQuery(function($query) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
return $query->distinct() return $query->distinct()
->addSelect('product_flat.*') ->addSelect('product_flat.*')
@ -84,7 +84,7 @@ class ProductRepository extends Repository
$results = app(ProductFlatRepository::class)->scopeQuery(function($query) { $results = app(ProductFlatRepository::class)->scopeQuery(function($query) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
return $query->distinct() return $query->distinct()
->addSelect('product_flat.*') ->addSelect('product_flat.*')
@ -114,7 +114,7 @@ class ProductRepository extends Repository
$results = app(ProductFlatRepository::class)->scopeQuery(function($query) use($term, $categoryId, $params) { $results = app(ProductFlatRepository::class)->scopeQuery(function($query) use($term, $categoryId, $params) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale(); $locale = core()->getRequestedLocaleCode();
if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) { if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) {
$query = app('Webkul\Product\Repositories\ProductRepository')->checkOutOfStockItem($query); $query = app('Webkul\Product\Repositories\ProductRepository')->checkOutOfStockItem($query);

View File

@ -7,7 +7,7 @@
@section('content') @section('content')
<div class="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"> <form method="POST" action="" @submit.prevent="onSubmit" enctype="multipart/form-data">

View File

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

View File

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