Skip to content

Commit 882c0b9

Browse files
Merge pull request #2209 from suraj-webkul/issue#2146
issue #2146 has been fixed.
2 parents e409dfd + d8a21a6 commit 882c0b9

File tree

8 files changed

+33
-3
lines changed

8 files changed

+33
-3
lines changed

packages/Webkul/Admin/src/DataGrids/Product/ProductDataGrid.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Database\Query\Builder;
66
use Illuminate\Support\Facades\DB;
77
use Webkul\DataGrid\DataGrid;
8+
use Webkul\Tag\Repositories\TagRepository;
89

910
class ProductDataGrid extends DataGrid
1011
{
@@ -17,15 +18,18 @@ public function prepareQueryBuilder(): Builder
1718

1819
$queryBuilder = DB::table('products')
1920
->leftJoin('product_inventories', 'products.id', '=', 'product_inventories.product_id')
21+
->leftJoin('product_tags', 'products.id', '=', 'product_tags.product_id')
22+
->leftJoin('tags', 'tags.id', '=', 'product_tags.tag_id')
2023
->select(
2124
'products.id',
2225
'products.sku',
2326
'products.name',
2427
'products.price',
28+
'tags.name as tag_name',
2529
)
26-
->addSelect(DB::raw('SUM('.$tablePrefix.'product_inventories.in_stock) as total_in_stock'))
27-
->addSelect(DB::raw('SUM('.$tablePrefix.'product_inventories.allocated) as total_allocated'))
28-
->addSelect(DB::raw('SUM('.$tablePrefix.'product_inventories.in_stock - '.$tablePrefix.'product_inventories.allocated) as total_on_hand'))
30+
->addSelect(DB::raw('SUM(product_inventories.in_stock) as total_in_stock'))
31+
->addSelect(DB::raw('SUM(product_inventories.allocated) as total_allocated'))
32+
->addSelect(DB::raw('SUM(product_inventories.in_stock - product_inventories.allocated) as total_on_hand'))
2933
->groupBy('products.id');
3034

3135
if (request()->route('id')) {
@@ -36,6 +40,7 @@ public function prepareQueryBuilder(): Builder
3640
$this->addFilter('total_in_stock', DB::raw('SUM('.$tablePrefix.'product_inventories.in_stock'));
3741
$this->addFilter('total_allocated', DB::raw('SUM('.$tablePrefix.'product_inventories.allocated'));
3842
$this->addFilter('total_on_hand', DB::raw('SUM('.$tablePrefix.'product_inventories.in_stock - '.$tablePrefix.'product_inventories.allocated'));
43+
$this->addFilter('tag_name', 'tags.name');
3944

4045
return $queryBuilder;
4146
}
@@ -93,6 +98,24 @@ public function prepareColumns(): void
9398
'type' => 'string',
9499
'sortable' => true,
95100
]);
101+
102+
$this->addColumn([
103+
'index' => 'tag_name',
104+
'label' => trans('admin::app.products.index.datagrid.tag-name'),
105+
'type' => 'string',
106+
'searchable' => false,
107+
'sortable' => true,
108+
'filterable' => true,
109+
'filterable_type' => 'searchable_dropdown',
110+
'closure' => fn ($row) => $row->tag_name ?? '--',
111+
'filterable_options' => [
112+
'repository' => TagRepository::class,
113+
'column' => [
114+
'label' => 'name',
115+
'value' => 'name',
116+
],
117+
],
118+
]);
96119
}
97120

98121
/**

packages/Webkul/Admin/src/Resources/lang/ar/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@
690690
'edit' => 'تعديل',
691691
'id' => 'المعرف',
692692
'in-stock' => 'في المخزون',
693+
'tag-name' => 'اسم الوسم',
693694
'name' => 'الاسم',
694695
'on-hand' => 'متوفر',
695696
'price' => 'السعر',

packages/Webkul/Admin/src/Resources/lang/en/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@
694694
'in-stock' => 'In Stock',
695695
'name' => 'Name',
696696
'on-hand' => 'On Hand',
697+
'tag-name' => 'Tag Name',
697698
'price' => 'Price',
698699
'sku' => 'SKU',
699700
'view' => 'View',

packages/Webkul/Admin/src/Resources/lang/es/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@
694694
'edit' => 'Editar',
695695
'id' => 'ID',
696696
'in-stock' => 'En Stock',
697+
'tag-name' => 'Nombre de etiqueta',
697698
'name' => 'Nombre',
698699
'on-hand' => 'Disponible',
699700
'price' => 'Precio',

packages/Webkul/Admin/src/Resources/lang/fa/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@
694694
'edit' => 'ویرایش',
695695
'id' => 'شناسه',
696696
'in-stock' => 'در انبار',
697+
'tag-name' => 'نام برچسب',
697698
'name' => 'نام',
698699
'on-hand' => 'موجودی',
699700
'price' => 'قیمت',

packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@
688688
'edit' => 'Editar',
689689
'id' => 'ID',
690690
'in-stock' => 'Em Estoque',
691+
'tag-name' => 'Nome da Tag',
691692
'name' => 'Nome',
692693
'on-hand' => 'Disponível',
693694
'price' => 'Preço',

packages/Webkul/Admin/src/Resources/lang/tr/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@
694694
'edit' => 'Düzenle',
695695
'id' => 'ID',
696696
'in-stock' => 'Stokta',
697+
'tag-name' => 'Etiket Adı',
697698
'name' => 'Ad',
698699
'on-hand' => 'Elinde',
699700
'price' => 'Fiyat',

packages/Webkul/Admin/src/Resources/lang/vi/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@
691691
'edit' => 'Chỉnh sửa',
692692
'id' => 'ID',
693693
'in-stock' => 'Có sẵn',
694+
'tag-name' => 'Tên thẻ',
694695
'name' => 'Tên',
695696
'on-hand' => 'Sẵn có',
696697
'price' => 'Giá',

0 commit comments

Comments
 (0)