This commit is contained in:
jitendra 2018-10-26 09:51:39 +05:30
commit cc7b20e607
18 changed files with 168 additions and 62 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,26 +43,127 @@ 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;
}
}
} else {
$qty = 0;
foreach($product->toArray()['inventories'] as $inventorySource) {
$qty = $qty + $inventorySource['qty'];
}
$gridObject['price'] = $product->price;
$gridObject['quantity'] = $qty;
$qty = 0;
}
}
// dd($gridObject, $variantObjects);
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($product, $data);
if($this->productGrid->create($gridObject)) {
return true;
return $result;
}
/**
* Save the product to the product as the product data grid instance
*
* @return boolean
*/
public function saveProduct($product, $data) {
$productGridObject = $this->productGrid->findOneByField('product_id', $product->id);
// dd($product, $data, $productGridObject);
if (!is_null($productGridObject)) {
if($product->type == 'simple') {
$r = $productGridObject->update($data['parent']);
} else {
$productGridObject->update($data['parent']);
if(count($data['variants'])) {
dd($data['variants']);
foreach($data['variants'] as $variant) {
$variantObject = $this->productGrid->findOneByField('product_id', $variant['product_id']);
if(!is_null($variantObject)) {
$variantObject->update($variant);
} else {
$this->productGrid->create($variant);
}
}
}
}
} else {
return false;
$this->productGrid->create($data['parent']);
//no need for tese lines
if(count($data['variants'])) {
foreach($data['variants'] as $variant) {
$this->productGrid->create($variant);
}
}
}
return true;
}
/**

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

@ -1,7 +1,7 @@
<?php
<?php
namespace Webkul\Product\Repositories;
use Illuminate\Container\Container as App;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Core\Eloquent\Repository;
@ -14,7 +14,7 @@ use Webkul\Product\Models\ProductAttributeValue;
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ProductAttributeValueRepository extends Repository
{
{
/**
* AttributeRepository object
*

View File

@ -154,15 +154,16 @@ class ProductRepository extends Repository
$product->update($data);
if(isset($data['categories']))
if(isset($data['categories'])) {
$product->categories()->sync($data['categories']);
}
$attributes = $product->attribute_family->custom_attributes;
foreach ($attributes as $attribute) {
if(!isset($data[$attribute->code]) || ($attribute->code == 'boolean' && !$data[$attribute->code]))
continue;
$attributeValue = $this->attributeValue->findOneWhere([
'product_id' => $product->id,
'attribute_id' => $attribute->id,
@ -172,16 +173,17 @@ class ProductRepository extends Repository
if(!$attributeValue) {
$this->attributeValue->create([
'product_id' => $product->id,
'attribute_id' => $attribute->id,
'value' => $data[$attribute->code],
'channel' => $attribute->value_per_channel ? $data['channel'] : null,
'locale' => $attribute->value_per_locale ? $data['locale'] : null
]);
'product_id' => $product->id,
'attribute_id' => $attribute->id,
'value' => $data[$attribute->code],
'channel' => $attribute->value_per_channel ? $data['channel'] : null,
'locale' => $attribute->value_per_locale ? $data['locale'] : null
]);
} else {
$this->attributeValue->update([
ProductAttributeValue::$attributeTypeFields[$attribute->type] => $data[$attribute->code]
], $attributeValue->id);
ProductAttributeValue::$attributeTypeFields[$attribute->type] => $data[$attribute->code]
], $attributeValue->id
);
}
}

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