Merge branch 'master' into config-field-improvement

This commit is contained in:
devansh bawari 2021-06-15 17:45:37 +05:30
commit 378db3e217
33 changed files with 145 additions and 112 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

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

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

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

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

@ -235,11 +235,18 @@ class Core
/**
* Get channel code from request.
*
* @param bool $fallback optional
* @return string
*/
public function getRequestedChannelCode(): string
public function getRequestedChannelCode($fallback = true)
{
return request()->get('channel') ?: ($this->getCurrentChannelCode() ?: $this->getDefaultChannelCode());
$channelCode = request()->get('channel');
if (! $fallback) {
return $channelCode;
}
return $channelCode ?: ($this->getCurrentChannelCode() ?: $this->getDefaultChannelCode());
}
/**
@ -318,11 +325,18 @@ class Core
* you can pass it as an argument.
*
* @param string $localeKey optional
* @param bool $fallback optional
* @return string
*/
public function getRequestedLocaleCode($localeKey = 'locale'): string
public function getRequestedLocaleCode($localeKey = 'locale', $fallback = true)
{
return request()->get($localeKey) ?: app()->getLocale();
$localeCode = request()->get($localeKey);
if (! $fallback) {
return $localeCode;
}
return $localeCode ?: app()->getLocale();
}
/**
@ -358,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.
*
@ -792,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

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

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

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

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

View File

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

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

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