left with only the save product function for creating products datagrid

This commit is contained in:
prashant-webkul 2018-10-25 19:29:34 +05:30
parent dc939d4ff2
commit 55f6e2f29a
16 changed files with 131 additions and 51 deletions

View File

@ -29,7 +29,7 @@ class AttributeDataGrid
'name' => 'Attributes',
'table' => 'attributes',
'select' => 'id',
'perpage' => 5,
'perpage' => 10,
'aliased' => true,
'massoperations' => [

View File

@ -62,12 +62,6 @@ class CategoryDataGrid
'primaryKey' => 'cat.id',
'condition' => '=',
'secondaryKey' => 'ct.category_id',
], [
'join' => 'leftjoin',
'table' => 'category_translations as cta',
'primaryKey' => 'cat.parent_id',
'condition' => '=',
'secondaryKey' => 'cta.category_id',
],
],
@ -92,13 +86,15 @@ class CategoryDataGrid
'type' => 'string',
'label' => 'Category Position',
'sortable' => false,
], [
'name' => 'cta.name',
'alias' => 'parent_name',
'type' => 'string',
'label' => 'Parent Name',
'sortable' => true,
], [
],
// [
// 'name' => 'cta.name',
// 'alias' => 'parent_name',
// 'type' => 'string',
// 'label' => 'Parent Name',
// 'sortable' => true,
// ],
[
'name' => 'cat.status',
'alias' => 'cat_status',
'type' => 'string',
@ -110,15 +106,16 @@ class CategoryDataGrid
else
return "True";
},
], [
'name' => 'cta.locale',
],
[
'name' => 'ct.locale',
'alias' => 'cat_locale',
'type' => 'string',
'label' => 'Locale',
'sortable' => true,
'filter' => [
'function' => 'where',
'condition' => ['cta.locale', app()->getLocale()]
'function' => 'orWhere',
'condition' => ['ct.locale', app()->getLocale()]
],
]
],
@ -134,12 +131,14 @@ class CategoryDataGrid
'alias' => 'catName',
'type' => 'string',
'label' => 'Category Name',
], [
'column' => 'cta.name',
'alias' => 'parentName',
'type' => 'string',
'label' => 'Parent Name',
], [
],
// [
// 'column' => 'cta.name',
// 'alias' => 'parentName',
// 'type' => 'string',
// 'label' => 'Parent Name',
// ],
[
'column' => 'cat.status',
'alias' => 'catStatus',
'type' => 'string',

View File

@ -29,7 +29,7 @@ class ChannelDataGrid
'name' => 'Channels',
'table' => 'channels',
'select' => 'id',
'perpage' => 5,
'perpage' => 10,
'aliased' => false, //use this with false as default and true in case of joins
'massoperations' =>[

View File

@ -28,7 +28,7 @@ class CurrencyDataGrid
'name' => 'Currencies',
'table' => 'currencies',
'select' => 'id',
'perpage' => 5,
'perpage' => 10,
'aliased' => false, //use this with false as default and true in case of joins
'massoperations' =>[

View File

@ -29,7 +29,7 @@ class ExchangeRatesDataGrid
'name' => 'Exchange Rates',
'table' => 'currency_exchange_rates as cer',
'select' => 'cer.id',
'perpage' => 5,
'perpage' => 10,
'aliased' => true, //use this with false as default and true in case of joins
'massoperations' =>[

View File

@ -27,7 +27,7 @@ class InventorySourcesDataGrid
'name' => 'Inventory Sources',
'table' => 'inventory_sources',
'select' => 'id',
'perpage' => 5,
'perpage' => 10,
'aliased' => false, //use this with false as default and true in case of joins
'massoperations' =>[

View File

@ -28,7 +28,7 @@ class LocalesDataGrid
'name' => 'Locales',
'table' => 'locales',
'select' => 'id',
'perpage' => 5,
'perpage' => 10,
'aliased' => false, //use this with false as default and true in case of joins
'massoperations' =>[

View File

@ -27,7 +27,7 @@ class OrderDataGrid
'name' => 'orders',
'table' => 'orders as or',
'select' => 'or.id',
'perpage' => 5,
'perpage' => 10,
'aliased' => false,
//True in case of joins else aliasing key required on all cases

View File

@ -26,7 +26,7 @@ class ProductDataGrid
'name' => 'Products',
'table' => 'products_grid as prods',
'select' => 'prods.product_id',
'perpage' => 5,
'perpage' => 10,
'aliased' => true, //use this with false as default and true in case of joins
'massoperations' =>[

View File

@ -29,7 +29,7 @@ class RolesDataGrid
'name' => 'Roles',
'table' => 'roles',
'select' => 'id',
'perpage' => 5,
'perpage' => 10,
'aliased' => false, //use this with false as default and true in case of joins
'massoperations' =>[

View File

@ -28,7 +28,7 @@ class SliderDataGrid
'name' => 'Sliders',
'table' => 'sliders as s',
'select' => 's.id',
'perpage' => 5,
'perpage' => 10,
'aliased' => true, //use this with false as default and true in case of joins
'massoperations' =>[

View File

@ -29,7 +29,7 @@ class UserDataGrid
'name' => 'Admins',
'table' => 'admins as u',
'select' => 'u.id',
'perpage' => 5,
'perpage' => 10,
'aliased' => true, //use this with false as default and true in case of joins
'massoperations' =>[

View File

@ -43,22 +43,107 @@ class Product {
$this->price = $price;
}
/**
* Prepare the data from the product created
*
* @return array $data
*/
public function prepareData($product) {
$gridObject = [];
$gridObject = [
'product_id' => $product->id,
'sku' => $product->sku,
'type' => $product->type,
'attribute_family_name' => $product->attribute_family->name,
];
$variantObjects = [];
if($this->productGrid->findOneByField('product_id', $product->id)) {
$gridObject['name'] = $product->name;
$gridObject['status'] = $product->status;
if($product->type == 'configurable') {
$gridObject['quantity'] = 0;
$gridObject['price'] = $this->price->getMinimalPrice($product);
$variants = $product->variants;
if(count($variants)) {
foreach($variants as $variant) {
$variantObject = [
'product_id' => $variant->id,
'sku' => $variant->sku,
'type' => $variant->type,
'attribute_family_name' => $variant->toArray()['attribute_family']['name'],
'name' => $variant->name,
'status' => $variant->status,
];
$qty = 1;
foreach($variant->toArray()['inventories'] as $inventorySource) {
$qty = $qty + $inventorySource['qty'];
}
$variantObject['price'] = $product->price;
$variantObject['quantity'] = $qty;
array_push($variantObjects, $variantObject);
$qty = 0;
}
}
return [
'parent' => $gridObject,
'variants' => $variantObjects
];
} else {
$qty = 0;
foreach($product->toArray()['inventories'] as $inventorySource) {
$qty = $qty + $inventorySource['qty'];
}
$gridObject['price'] = $product->price;
$gridObject['quantity'] = $qty;
$qty = 0;
return [
'parent' => $gridObject,
'variants' => $variantObjects
];
}
}
}
/**
* Creates a new entry in the product grid whenever a new product is created.
*
* @return boolean
*/
public function afterProductCreated($product) {
$gridObject = [];
$data = $this->prepareData($product);
$gridObject = [
'product_id' => $product->id,
'sku' => $product->sku,
'type' => $product->type,
'attribute_family_name' => $product->toArray()['attribute_family']['name'],
];
$result = $this->saveProduct($data);
if($this->productGrid->create($gridObject)) {
return $result;
}
/**
* Save the product to the product as the product data grid instance
*
* @return boolean
*/
public function saveProduct($product) {
dd('check here whether to create or update there');
//two cases already created and update previous with simple and configurable
if($this->productGrid->create($product)) {
return true;
} else {
return false;

View File

@ -182,10 +182,10 @@ class ProductController extends Controller
// before update of product
// Event::fire('product.update.before', $id);
$this->product->update(request()->all(), $id);
$product = $this->product->update(request()->all(), $id);
//after update of product
Event::fire('product.update.after', $this->product->find($id));
Event::fire('product.save.after', $product);
session()->flash('success', 'Product updated successfully.');

View File

@ -774,7 +774,7 @@ class DataGrid
$this->results = $this->query->get();
$this->results = $this->query->distinct()->paginate($this->perpage)->appends(request()->except('page'));
$this->results = $this->query->paginate($this->perpage)->appends(request()->except('page'));
return $this->results;

File diff suppressed because one or more lines are too long