From 5c5bccd293f412abddf506c180aec46fbe8c9862 Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Mon, 20 Aug 2018 19:17:42 +0530 Subject: [PATCH] product grid theme restructuring in mid way --- config/app.php | 1 + .../Admin/src/DataGrids/ProductDataGrid.php | 114 ++++++-- .../views/catalog/products/index.blade.php | 2 +- .../Attribute/src/Models/AttributeOption.php | 4 +- .../Ui/src/DataGrid/Facades/ProductGrid.php | 18 ++ .../Webkul/Ui/src/DataGrid/ProductGrid.php | 256 ++++++++++++++---- .../Ui/src/Providers/UiServiceProvider.php | 2 + 7 files changed, 304 insertions(+), 93 deletions(-) create mode 100644 packages/Webkul/Ui/src/DataGrid/Facades/ProductGrid.php diff --git a/config/app.php b/config/app.php index ac0cb2b2b..6a19f4e87 100644 --- a/config/app.php +++ b/config/app.php @@ -237,6 +237,7 @@ return [ 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, 'Datagrid' => Webkul\Ui\DataGrid\Facades\DataGrid::class, + 'ProductGrid' => Webkul\Ui\DataGrid\Facades\ProductGrid::class, 'Image' => Intervention\Image\Facades\Image::class ], diff --git a/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php b/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php index 252edea75..46896e02f 100644 --- a/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php @@ -3,8 +3,9 @@ namespace Webkul\Admin\DataGrids; use Illuminate\View\View; -use Webkul\Ui\DataGrid\Facades\DataGrid; - +use Webkul\Ui\DataGrid\Facades\ProductGrid; +use Webkul\Channel\Repositories\ChannelRepository; +use Webkul\Product\Repositories\ProductRepository; /** * Product DataGrid @@ -24,20 +25,20 @@ class ProductDataGrid public function createProductDataGrid() { - return DataGrid::make([ + return ProductGrid::make([ 'name' => 'Products', - 'table' => 'products as pr', - 'select' => 'pr.id', + 'table' => 'products as prods', + 'select' => 'prods.id', 'perpage' => 10, 'aliased' => true, //use this with false as default and true in case of joins 'massoperations' =>[ - [ - 'route' => route('admin.datagrid.delete'), - 'method' => 'DELETE', - 'label' => 'Delete', - 'type' => 'button', - ], + // [ + // 'route' => route('admin.datagrid.delete'), + // 'method' => 'DELETE', + // 'label' => 'Delete', + // 'type' => 'button', + // ], ], 'actions' => [ @@ -55,19 +56,38 @@ class ProductDataGrid ], 'join' => [ - // [ - // 'join' => 'leftjoin', - // 'table' => 'category_translations as ct', - // 'primaryKey' => 'cat.id', - // 'condition' => '=', - // 'secondaryKey' => 'ct.category_id', - // ], [ - // 'join' => 'leftjoin', - // 'table' => 'category_translations as cta', - // 'primaryKey' => 'cat.parent_id', - // 'condition' => '=', - // 'secondaryKey' => 'cta.category_id', - // ], + + //for getting name of attrib family. + [ + 'join' => 'leftjoin', + 'table' => 'attribute_families as attfam', + 'primaryKey' => 'prods.attribute_family_id', + 'condition' => '=', + 'secondaryKey' => 'attfam.id', + ], + + //for getting the attribute values. + [ + 'join' => 'leftjoin', + 'table' => 'product_attribute_values as pav', + 'primaryKey' => 'prods.id', + 'condition' => '=', + 'secondaryKey' => 'pav.product_id', + 'where' => [ + 'column1' => 'prods.id', + 'condition' => '=', + 'column2' => 'pav.product_id' + ] + ], + + //for getting the inventory quantity of a product + [ + 'join' => 'leftjoin', + 'table' => 'product_inventories as pi', + 'primaryKey' => 'prods.id', + 'condition' => '=', + 'secondaryKey' => 'pi.product_id', + ], ], @@ -76,21 +96,54 @@ class ProductDataGrid 'columns' => [ //name, alias, type, label, sortable [ - 'name' => 'pr.id', + 'name' => 'prods.id', 'alias' => 'productID', 'type' => 'number', - 'label' => 'Product ID', + 'label' => 'ID', 'sortable' => true, ], [ - 'name' => 'pr.sku', + 'name' => 'prods.sku', 'alias' => 'productCode', - 'type' => 'number', - 'label' => 'Product Code', + 'type' => 'string', + 'label' => 'SKU', 'sortable' => true, ], + [ + 'name' => 'attfam.name', + 'alias' => 'attributeFamily', + 'type' => 'string', + 'label' => 'Attribute Family', + 'sortable' => true, + ], + [ + 'name' => 'pi.qty', + 'alias' => 'ProductQuantity', + 'type' => 'string', + 'label' => 'Product Quatity', + 'sortable' => false, + ], + [ + 'name' => 'pav.product_id', + 'alias' => 'ProductID', + 'type' => 'string', + 'label' => 'Product ID', + 'sortable' => false, + + ], ], + //use this bag for fetching attributes as columns in product datagrid. + // 'attributes' => [ + // [ + // 'name' => 'pi.qty', + // 'alias' => 'ProductQuantity', + // 'type' => 'string', + // 'label' => 'Product Quatity', + // 'sortable' => false, + // ] + // ], + 'filterable' => [ ], @@ -121,8 +174,9 @@ class ProductDataGrid public function render() { - return $this->createProductDataGrid()->render(); + // return $this->getProducts(); } + } \ No newline at end of file diff --git a/packages/Webkul/Admin/src/Resources/views/catalog/products/index.blade.php b/packages/Webkul/Admin/src/Resources/views/catalog/products/index.blade.php index 039fc4a35..b08552252 100644 --- a/packages/Webkul/Admin/src/Resources/views/catalog/products/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/catalog/products/index.blade.php @@ -4,7 +4,7 @@