Skip to content

issue #2146 has been fixed. #2209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions packages/Webkul/Admin/src/DataGrids/Product/ProductDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
use Webkul\DataGrid\DataGrid;
use Webkul\Tag\Repositories\TagRepository;

class ProductDataGrid extends DataGrid
{
Expand All @@ -17,15 +18,18 @@ public function prepareQueryBuilder(): Builder

$queryBuilder = DB::table('products')
->leftJoin('product_inventories', 'products.id', '=', 'product_inventories.product_id')
->leftJoin('product_tags', 'products.id', '=', 'product_tags.product_id')
->leftJoin('tags', 'tags.id', '=', 'product_tags.tag_id')
->select(
'products.id',
'products.sku',
'products.name',
'products.price',
'tags.name as tag_name',
)
->addSelect(DB::raw('SUM('.$tablePrefix.'product_inventories.in_stock) as total_in_stock'))
->addSelect(DB::raw('SUM('.$tablePrefix.'product_inventories.allocated) as total_allocated'))
->addSelect(DB::raw('SUM('.$tablePrefix.'product_inventories.in_stock - '.$tablePrefix.'product_inventories.allocated) as total_on_hand'))
->addSelect(DB::raw('SUM(product_inventories.in_stock) as total_in_stock'))
->addSelect(DB::raw('SUM(product_inventories.allocated) as total_allocated'))
->addSelect(DB::raw('SUM(product_inventories.in_stock - product_inventories.allocated) as total_on_hand'))
->groupBy('products.id');

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

return $queryBuilder;
}
Expand Down Expand Up @@ -93,6 +98,24 @@ public function prepareColumns(): void
'type' => 'string',
'sortable' => true,
]);

$this->addColumn([
'index' => 'tag_name',
'label' => trans('admin::app.products.index.datagrid.tag-name'),
'type' => 'string',
'searchable' => false,
'sortable' => true,
'filterable' => true,
'filterable_type' => 'searchable_dropdown',
'closure' => fn ($row) => $row->tag_name ?? '--',
'filterable_options' => [
'repository' => TagRepository::class,
'column' => [
'label' => 'name',
'value' => 'name',
],
],
]);
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/ar/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@
'edit' => 'تعديل',
'id' => 'المعرف',
'in-stock' => 'في المخزون',
'tag-name' => 'اسم الوسم',
'name' => 'الاسم',
'on-hand' => 'متوفر',
'price' => 'السعر',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@
'in-stock' => 'In Stock',
'name' => 'Name',
'on-hand' => 'On Hand',
'tag-name' => 'Tag Name',
'price' => 'Price',
'sku' => 'SKU',
'view' => 'View',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/es/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@
'edit' => 'Editar',
'id' => 'ID',
'in-stock' => 'En Stock',
'tag-name' => 'Nombre de etiqueta',
'name' => 'Nombre',
'on-hand' => 'Disponible',
'price' => 'Precio',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/fa/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@
'edit' => 'ویرایش',
'id' => 'شناسه',
'in-stock' => 'در انبار',
'tag-name' => 'نام برچسب',
'name' => 'نام',
'on-hand' => 'موجودی',
'price' => 'قیمت',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@
'edit' => 'Editar',
'id' => 'ID',
'in-stock' => 'Em Estoque',
'tag-name' => 'Nome da Tag',
'name' => 'Nome',
'on-hand' => 'Disponível',
'price' => 'Preço',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/tr/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@
'edit' => 'Düzenle',
'id' => 'ID',
'in-stock' => 'Stokta',
'tag-name' => 'Etiket Adı',
'name' => 'Ad',
'on-hand' => 'Elinde',
'price' => 'Fiyat',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Resources/lang/vi/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@
'edit' => 'Chỉnh sửa',
'id' => 'ID',
'in-stock' => 'Có sẵn',
'tag-name' => 'Tên thẻ',
'name' => 'Tên',
'on-hand' => 'Sẵn có',
'price' => 'Giá',
Expand Down
Loading