Merge pull request #2211 from Haendlerbund/add-channel-and-locale-filter-to-product-grid

Add channel and locale filter to product grid
This commit is contained in:
Jitendra Singh 2020-01-31 12:03:59 +05:30 committed by GitHub
commit 3c16599ddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 104 additions and 9 deletions

View File

@ -3,7 +3,7 @@
namespace Webkul\Admin\DataGrids;
use Webkul\Ui\DataGrid\DataGrid;
use DB;
use Illuminate\Support\Facades\DB;
/**
* ProductDataGrid Class
@ -19,16 +19,44 @@ class ProductDataGrid extends DataGrid
protected $itemsPerPage = 10;
protected $locale = 'all';
protected $channel = 'all';
public function __construct()
{
parent::__construct();
$this->locale = request()->get('locale') ?? 'all';
$this->channel = request()->get('channel') ?? 'all';
}
public function prepareQueryBuilder()
{
$queryBuilder = DB::table('product_flat')
->leftJoin('products', 'product_flat.product_id', '=', 'products.id')
->leftJoin('attribute_families', 'products.attribute_family_id', '=', 'attribute_families.id')
->leftJoin('product_inventories', 'product_flat.product_id', '=', 'product_inventories.product_id')
->select('product_flat.product_id as product_id', 'products.sku as product_sku', 'product_flat.name as product_name', 'products.type as product_type', 'product_flat.status', 'product_flat.price', 'attribute_families.name as attribute_family', DB::raw('SUM(' . DB::getTablePrefix() . 'product_inventories.qty) as quantity'))
->where('channel', core()->getCurrentChannelCode())
->where('locale', app()->getLocale())
->groupBy('product_flat.product_id');
->select(
'product_flat.product_id as product_id',
'products.sku as product_sku',
'product_flat.name as product_name',
'products.type as product_type',
'product_flat.status',
'product_flat.price',
'attribute_families.name as attribute_family',
DB::raw('SUM(' . DB::getTablePrefix() . 'product_inventories.qty) as quantity')
);
if ($this->locale !== 'all') {
$queryBuilder->where('locale', $this->locale);
}
if ($this->channel !== 'all') {
$queryBuilder->where('channel', $this->channel);
}
$queryBuilder->groupBy('product_flat.product_id');
$this->addFilter('product_id', 'product_flat.product_id');
$this->addFilter('product_name', 'product_flat.name');

View File

@ -776,7 +776,8 @@ return [
'seo' => 'Home page SEO',
'seo-title' => 'Meta title',
'seo-description' => 'Meta description',
'seo-keywords' => 'Meta keywords'
'seo-keywords' => 'Meta keywords',
],
'sliders' => [
@ -1263,7 +1264,9 @@ return [
'order-number-length' => 'Order Number Length',
'order-number-suffix' => 'Order Number Suffix',
'default' => 'Default',
'sandbox' => 'Sandbox'
'sandbox' => 'Sandbox',
'all-channels' => 'All',
'all-locales' => 'All'
]
]
];

View File

@ -6,9 +6,45 @@
@section('content')
<div class="content" style="height: 100%;">
<?php $locale = request()->get('locale') ?: null; ?>
<?php $channel = request()->get('channel') ?: null; ?>
<div class="page-header">
<div class="page-title">
<h1>{{ __('admin::app.catalog.products.title') }}</h1>
<div class="control-group">
<select class="control" id="channel-switcher" name="channel" onchange="reloadPage('channel', this.value)" >
<option value="all" {{ ! isset($channel) ? 'selected' : '' }}>
{{ __('admin::app.admin.system.all-channels') }}
</option>
@foreach (core()->getAllChannels() as $channelModel)
<option
value="{{ $channelModel->code }}" {{ (isset($channel) && ($channelModel->code) == $channel) ? 'selected' : '' }}>
{{ $channelModel->name }}
</option>
@endforeach
</select>
</div>
<div class="control-group">
<select class="control" id="locale-switcher" name="locale" onchange="reloadPage('locale', this.value)" >
<option value="all" {{ ! isset($locale) ? 'selected' : '' }}>
{{ __('admin::app.admin.system.all-locales') }}
</option>
@foreach (core()->getAllLocales() as $localeModel)
<option
value="{{ $localeModel->code }}" {{ (isset($locale) && ($localeModel->code) == $locale) ? 'selected' : '' }}>
{{ $localeModel->name }}
</option>
@endforeach
</select>
</div>
</div>
<div class="page-action">
@ -46,4 +82,14 @@
@push('scripts')
@include('admin::export.export', ['gridName' => $products])
<script>
function reloadPage(getVar, getVal) {
let url = new URL(window.location.href);
url.searchParams.set(getVar, getVal);
window.location.href = url.href;
}
</script>
@endpush

View File

@ -0,0 +1,14 @@
<?php
use Faker\Generator as Faker;
use Webkul\Core\Models\Currency;
/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(Currency::class, function (Faker $faker, array $attributes) {
return [
'code' => $faker->unique()->currencyCode,
'name' => $faker->word,
];
});

View File

@ -1,10 +1,9 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Core\Models\Locale;
/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(Locale::class, function (Faker $faker, array $attributes) {
return [

View File

@ -3,6 +3,7 @@
namespace Webkul\Inventory\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
class InventoryServiceProvider extends ServiceProvider
{
@ -14,6 +15,8 @@ class InventoryServiceProvider extends ServiceProvider
public function boot()
{
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
$this->app->make(EloquentFactory::class)->load(__DIR__ . '/../Database/Factories');
}
/**

View File

@ -19,6 +19,8 @@ class ProductServiceProvider extends ServiceProvider
{
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
$this->app->make(EloquentFactory::class)->load(__DIR__ . '/../Database/Factories');
$this->app->register(EventServiceProvider::class);
$this->publishes([