Export Issue Fixed

This commit is contained in:
devansh bawari 2021-10-05 10:27:34 +05:30
parent e3626e0ef3
commit 5bd5b3354a
2 changed files with 21 additions and 45 deletions

View File

@ -5,8 +5,6 @@ namespace Webkul\Admin\DataGrids;
use Illuminate\Support\Facades\DB;
use Webkul\Core\Models\Channel;
use Webkul\Core\Models\Locale;
use Webkul\Inventory\Repositories\InventorySourceRepository;
use Webkul\Product\Repositories\ProductRepository;
use Webkul\Ui\DataGrid\DataGrid;
class ProductDataGrid extends DataGrid
@ -56,33 +54,12 @@ class ProductDataGrid extends DataGrid
'locales',
];
/**
* Product repository instance.
*
* @var \Webkul\Product\Repositories\ProductRepository
*/
protected $productRepository;
/**
* Inventory source repository instance.
*
* @var \Webkul\Inventory\Repositories\InventorySourceRepository
*/
protected $inventorySourceRepository;
/**
* Create datagrid instance.
*
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
* @param \Webkul\Inventory\Repositories\InventorySourceRepository $inventorySourceRepository
* @return void
*/
public function __construct(
ProductRepository $productRepository,
InventorySourceRepository $inventorySourceRepository
) {
parent::__construct();
public function __construct() {
/* locale */
$this->locale = core()->getRequestedLocaleCode();
@ -95,9 +72,8 @@ class ProductDataGrid extends DataGrid
$this->channel = $this->channel ? $this->channel->code : 'all';
}
$this->productRepository = $productRepository;
$this->inventorySourceRepository = $inventorySourceRepository;
/* parent constructor */
parent::__construct();
}
/**
@ -281,6 +257,13 @@ class ProductDataGrid extends DataGrid
'confirm_text' => trans('ui::app.datagrid.massaction.delete', ['resource' => 'product']),
'icon' => 'icon trash-icon',
]);
$this->addAction([
'title' => trans('admin::app.datagrid.copy'),
'method' => 'GET',
'route' => 'admin.catalog.products.copy',
'icon' => 'icon copy-icon',
]);
}
/**
@ -290,13 +273,6 @@ class ProductDataGrid extends DataGrid
*/
public function prepareMassActions()
{
$this->addAction([
'title' => trans('admin::app.datagrid.copy'),
'method' => 'GET',
'route' => 'admin.catalog.products.copy',
'icon' => 'icon copy-icon',
]);
$this->addMassAction([
'type' => 'delete',
'label' => trans('admin::app.datagrid.delete'),
@ -319,14 +295,14 @@ class ProductDataGrid extends DataGrid
/**
* Render quantity view.
*
* @parma object $row
* @param object $row
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
*/
private function renderQuantityView($row)
{
$product = $this->productRepository->find($row->product_id);
$product = app(\Webkul\Product\Repositories\ProductRepository::class)->find($row->product_id);
$inventorySources = $this->inventorySourceRepository->findWhere(['status' => 1]);
$inventorySources = app(\Webkul\Inventory\Repositories\InventorySourceRepository::class)->findWhere(['status' => 1]);
$totalQuantity = $row->quantity;

View File

@ -2,8 +2,8 @@
namespace Webkul\Admin\Http\Controllers;
use Webkul\Admin\Exports\DataGridExport;
use Excel;
use Webkul\Admin\Exports\DataGridExport;
class ExportController extends Controller
{
@ -18,10 +18,10 @@ class ExportController extends Controller
}
/**
* function for export datagrid
* Export datagrid.
*
* @return \Illuminate\Http\Response
*/
*/
public function export()
{
$criteria = request()->all();
@ -30,10 +30,10 @@ class ExportController extends Controller
$gridName = explode('\\', $criteria['gridName']);
$path = '\Webkul\Admin\DataGrids'.'\\'.last($gridName);
$path = '\Webkul\Admin\DataGrids' . '\\' . last($gridName);
$gridInstance = new $path;
$records = $gridInstance->export();
if (! count($records)) {
@ -43,15 +43,15 @@ class ExportController extends Controller
}
if ($format == 'csv') {
return Excel::download(new DataGridExport($records), last($gridName).'.csv');
return Excel::download(new DataGridExport($records), last($gridName) . '.csv');
}
if ($format == 'xls') {
return Excel::download(new DataGridExport($records), last($gridName).'.xlsx');
return Excel::download(new DataGridExport($records), last($gridName) . '.xlsx');
}
session()->flash('warning', trans('admin::app.export.illegal-format'));
return redirect()->back();
}
}
}