Merged
This commit is contained in:
commit
cc7b20e607
|
|
@ -29,7 +29,7 @@ class AttributeDataGrid
|
||||||
'name' => 'Attributes',
|
'name' => 'Attributes',
|
||||||
'table' => 'attributes',
|
'table' => 'attributes',
|
||||||
'select' => 'id',
|
'select' => 'id',
|
||||||
'perpage' => 5,
|
'perpage' => 10,
|
||||||
'aliased' => true,
|
'aliased' => true,
|
||||||
|
|
||||||
'massoperations' => [
|
'massoperations' => [
|
||||||
|
|
|
||||||
|
|
@ -62,12 +62,6 @@ class CategoryDataGrid
|
||||||
'primaryKey' => 'cat.id',
|
'primaryKey' => 'cat.id',
|
||||||
'condition' => '=',
|
'condition' => '=',
|
||||||
'secondaryKey' => 'ct.category_id',
|
'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',
|
'type' => 'string',
|
||||||
'label' => 'Category Position',
|
'label' => 'Category Position',
|
||||||
'sortable' => false,
|
'sortable' => false,
|
||||||
], [
|
],
|
||||||
'name' => 'cta.name',
|
// [
|
||||||
'alias' => 'parent_name',
|
// 'name' => 'cta.name',
|
||||||
'type' => 'string',
|
// 'alias' => 'parent_name',
|
||||||
'label' => 'Parent Name',
|
// 'type' => 'string',
|
||||||
'sortable' => true,
|
// 'label' => 'Parent Name',
|
||||||
], [
|
// 'sortable' => true,
|
||||||
|
// ],
|
||||||
|
[
|
||||||
'name' => 'cat.status',
|
'name' => 'cat.status',
|
||||||
'alias' => 'cat_status',
|
'alias' => 'cat_status',
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
|
|
@ -110,15 +106,16 @@ class CategoryDataGrid
|
||||||
else
|
else
|
||||||
return "True";
|
return "True";
|
||||||
},
|
},
|
||||||
], [
|
],
|
||||||
'name' => 'cta.locale',
|
[
|
||||||
|
'name' => 'ct.locale',
|
||||||
'alias' => 'cat_locale',
|
'alias' => 'cat_locale',
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'label' => 'Locale',
|
'label' => 'Locale',
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'filter' => [
|
'filter' => [
|
||||||
'function' => 'where',
|
'function' => 'orWhere',
|
||||||
'condition' => ['cta.locale', app()->getLocale()]
|
'condition' => ['ct.locale', app()->getLocale()]
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
@ -134,12 +131,14 @@ class CategoryDataGrid
|
||||||
'alias' => 'catName',
|
'alias' => 'catName',
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'label' => 'Category Name',
|
'label' => 'Category Name',
|
||||||
], [
|
],
|
||||||
'column' => 'cta.name',
|
// [
|
||||||
'alias' => 'parentName',
|
// 'column' => 'cta.name',
|
||||||
'type' => 'string',
|
// 'alias' => 'parentName',
|
||||||
'label' => 'Parent Name',
|
// 'type' => 'string',
|
||||||
], [
|
// 'label' => 'Parent Name',
|
||||||
|
// ],
|
||||||
|
[
|
||||||
'column' => 'cat.status',
|
'column' => 'cat.status',
|
||||||
'alias' => 'catStatus',
|
'alias' => 'catStatus',
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class ChannelDataGrid
|
||||||
'name' => 'Channels',
|
'name' => 'Channels',
|
||||||
'table' => 'channels',
|
'table' => 'channels',
|
||||||
'select' => 'id',
|
'select' => 'id',
|
||||||
'perpage' => 5,
|
'perpage' => 10,
|
||||||
'aliased' => false, //use this with false as default and true in case of joins
|
'aliased' => false, //use this with false as default and true in case of joins
|
||||||
|
|
||||||
'massoperations' =>[
|
'massoperations' =>[
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class CurrencyDataGrid
|
||||||
'name' => 'Currencies',
|
'name' => 'Currencies',
|
||||||
'table' => 'currencies',
|
'table' => 'currencies',
|
||||||
'select' => 'id',
|
'select' => 'id',
|
||||||
'perpage' => 5,
|
'perpage' => 10,
|
||||||
'aliased' => false, //use this with false as default and true in case of joins
|
'aliased' => false, //use this with false as default and true in case of joins
|
||||||
|
|
||||||
'massoperations' =>[
|
'massoperations' =>[
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class ExchangeRatesDataGrid
|
||||||
'name' => 'Exchange Rates',
|
'name' => 'Exchange Rates',
|
||||||
'table' => 'currency_exchange_rates as cer',
|
'table' => 'currency_exchange_rates as cer',
|
||||||
'select' => 'cer.id',
|
'select' => 'cer.id',
|
||||||
'perpage' => 5,
|
'perpage' => 10,
|
||||||
'aliased' => true, //use this with false as default and true in case of joins
|
'aliased' => true, //use this with false as default and true in case of joins
|
||||||
|
|
||||||
'massoperations' =>[
|
'massoperations' =>[
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class InventorySourcesDataGrid
|
||||||
'name' => 'Inventory Sources',
|
'name' => 'Inventory Sources',
|
||||||
'table' => 'inventory_sources',
|
'table' => 'inventory_sources',
|
||||||
'select' => 'id',
|
'select' => 'id',
|
||||||
'perpage' => 5,
|
'perpage' => 10,
|
||||||
'aliased' => false, //use this with false as default and true in case of joins
|
'aliased' => false, //use this with false as default and true in case of joins
|
||||||
|
|
||||||
'massoperations' =>[
|
'massoperations' =>[
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class LocalesDataGrid
|
||||||
'name' => 'Locales',
|
'name' => 'Locales',
|
||||||
'table' => 'locales',
|
'table' => 'locales',
|
||||||
'select' => 'id',
|
'select' => 'id',
|
||||||
'perpage' => 5,
|
'perpage' => 10,
|
||||||
'aliased' => false, //use this with false as default and true in case of joins
|
'aliased' => false, //use this with false as default and true in case of joins
|
||||||
|
|
||||||
'massoperations' =>[
|
'massoperations' =>[
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class OrderDataGrid
|
||||||
'name' => 'orders',
|
'name' => 'orders',
|
||||||
'table' => 'orders as or',
|
'table' => 'orders as or',
|
||||||
'select' => 'or.id',
|
'select' => 'or.id',
|
||||||
'perpage' => 5,
|
'perpage' => 10,
|
||||||
'aliased' => false,
|
'aliased' => false,
|
||||||
//True in case of joins else aliasing key required on all cases
|
//True in case of joins else aliasing key required on all cases
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ class ProductDataGrid
|
||||||
'name' => 'Products',
|
'name' => 'Products',
|
||||||
'table' => 'products_grid as prods',
|
'table' => 'products_grid as prods',
|
||||||
'select' => 'prods.product_id',
|
'select' => 'prods.product_id',
|
||||||
'perpage' => 5,
|
'perpage' => 10,
|
||||||
'aliased' => true, //use this with false as default and true in case of joins
|
'aliased' => true, //use this with false as default and true in case of joins
|
||||||
|
|
||||||
'massoperations' =>[
|
'massoperations' =>[
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class RolesDataGrid
|
||||||
'name' => 'Roles',
|
'name' => 'Roles',
|
||||||
'table' => 'roles',
|
'table' => 'roles',
|
||||||
'select' => 'id',
|
'select' => 'id',
|
||||||
'perpage' => 5,
|
'perpage' => 10,
|
||||||
'aliased' => false, //use this with false as default and true in case of joins
|
'aliased' => false, //use this with false as default and true in case of joins
|
||||||
|
|
||||||
'massoperations' =>[
|
'massoperations' =>[
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class SliderDataGrid
|
||||||
'name' => 'Sliders',
|
'name' => 'Sliders',
|
||||||
'table' => 'sliders as s',
|
'table' => 'sliders as s',
|
||||||
'select' => 's.id',
|
'select' => 's.id',
|
||||||
'perpage' => 5,
|
'perpage' => 10,
|
||||||
'aliased' => true, //use this with false as default and true in case of joins
|
'aliased' => true, //use this with false as default and true in case of joins
|
||||||
|
|
||||||
'massoperations' =>[
|
'massoperations' =>[
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class UserDataGrid
|
||||||
'name' => 'Admins',
|
'name' => 'Admins',
|
||||||
'table' => 'admins as u',
|
'table' => 'admins as u',
|
||||||
'select' => 'u.id',
|
'select' => 'u.id',
|
||||||
'perpage' => 5,
|
'perpage' => 10,
|
||||||
'aliased' => true, //use this with false as default and true in case of joins
|
'aliased' => true, //use this with false as default and true in case of joins
|
||||||
|
|
||||||
'massoperations' =>[
|
'massoperations' =>[
|
||||||
|
|
|
||||||
|
|
@ -43,26 +43,127 @@ class Product {
|
||||||
$this->price = $price;
|
$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.
|
* Creates a new entry in the product grid whenever a new product is created.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function afterProductCreated($product) {
|
public function afterProductCreated($product) {
|
||||||
$gridObject = [];
|
$data = $this->prepareData($product);
|
||||||
|
|
||||||
$gridObject = [
|
$result = $this->saveProduct($product, $data);
|
||||||
'product_id' => $product->id,
|
|
||||||
'sku' => $product->sku,
|
|
||||||
'type' => $product->type,
|
|
||||||
'attribute_family_name' => $product->toArray()['attribute_family']['name'],
|
|
||||||
];
|
|
||||||
|
|
||||||
if($this->productGrid->create($gridObject)) {
|
return $result;
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
} 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -182,10 +182,10 @@ class ProductController extends Controller
|
||||||
// before update of product
|
// before update of product
|
||||||
// Event::fire('product.update.before', $id);
|
// Event::fire('product.update.before', $id);
|
||||||
|
|
||||||
$this->product->update(request()->all(), $id);
|
$product = $this->product->update(request()->all(), $id);
|
||||||
|
|
||||||
//after update of product
|
//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.');
|
session()->flash('success', 'Product updated successfully.');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Webkul\Product\Repositories;
|
namespace Webkul\Product\Repositories;
|
||||||
|
|
||||||
use Illuminate\Container\Container as App;
|
use Illuminate\Container\Container as App;
|
||||||
use Webkul\Attribute\Repositories\AttributeRepository;
|
use Webkul\Attribute\Repositories\AttributeRepository;
|
||||||
use Webkul\Core\Eloquent\Repository;
|
use Webkul\Core\Eloquent\Repository;
|
||||||
|
|
@ -14,7 +14,7 @@ use Webkul\Product\Models\ProductAttributeValue;
|
||||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||||
*/
|
*/
|
||||||
class ProductAttributeValueRepository extends Repository
|
class ProductAttributeValueRepository extends Repository
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* AttributeRepository object
|
* AttributeRepository object
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -154,15 +154,16 @@ class ProductRepository extends Repository
|
||||||
|
|
||||||
$product->update($data);
|
$product->update($data);
|
||||||
|
|
||||||
if(isset($data['categories']))
|
if(isset($data['categories'])) {
|
||||||
$product->categories()->sync($data['categories']);
|
$product->categories()->sync($data['categories']);
|
||||||
|
}
|
||||||
|
|
||||||
$attributes = $product->attribute_family->custom_attributes;
|
$attributes = $product->attribute_family->custom_attributes;
|
||||||
|
|
||||||
foreach ($attributes as $attribute) {
|
foreach ($attributes as $attribute) {
|
||||||
if(!isset($data[$attribute->code]) || ($attribute->code == 'boolean' && !$data[$attribute->code]))
|
if(!isset($data[$attribute->code]) || ($attribute->code == 'boolean' && !$data[$attribute->code]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$attributeValue = $this->attributeValue->findOneWhere([
|
$attributeValue = $this->attributeValue->findOneWhere([
|
||||||
'product_id' => $product->id,
|
'product_id' => $product->id,
|
||||||
'attribute_id' => $attribute->id,
|
'attribute_id' => $attribute->id,
|
||||||
|
|
@ -172,16 +173,17 @@ class ProductRepository extends Repository
|
||||||
|
|
||||||
if(!$attributeValue) {
|
if(!$attributeValue) {
|
||||||
$this->attributeValue->create([
|
$this->attributeValue->create([
|
||||||
'product_id' => $product->id,
|
'product_id' => $product->id,
|
||||||
'attribute_id' => $attribute->id,
|
'attribute_id' => $attribute->id,
|
||||||
'value' => $data[$attribute->code],
|
'value' => $data[$attribute->code],
|
||||||
'channel' => $attribute->value_per_channel ? $data['channel'] : null,
|
'channel' => $attribute->value_per_channel ? $data['channel'] : null,
|
||||||
'locale' => $attribute->value_per_locale ? $data['locale'] : null
|
'locale' => $attribute->value_per_locale ? $data['locale'] : null
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$this->attributeValue->update([
|
$this->attributeValue->update([
|
||||||
ProductAttributeValue::$attributeTypeFields[$attribute->type] => $data[$attribute->code]
|
ProductAttributeValue::$attributeTypeFields[$attribute->type] => $data[$attribute->code]
|
||||||
], $attributeValue->id);
|
], $attributeValue->id
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -774,7 +774,7 @@ class DataGrid
|
||||||
|
|
||||||
$this->results = $this->query->get();
|
$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;
|
return $this->results;
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue