Product datagrid event binded with product create

This commit is contained in:
prashant-webkul 2018-10-26 09:49:19 +05:30
parent 021d918937
commit 7e75da7bdf
3 changed files with 42 additions and 40 deletions

View File

@ -94,12 +94,6 @@ class Product {
$qty = 0;
}
}
return [
'parent' => $gridObject,
'variants' => $variantObjects
];
} else {
$qty = 0;
@ -111,13 +105,13 @@ class Product {
$gridObject['quantity'] = $qty;
$qty = 0;
return [
'parent' => $gridObject,
'variants' => $variantObjects
];
}
}
// dd($gridObject, $variantObjects);
return [
'parent' => $gridObject,
'variants' => $variantObjects
];
}
/**
@ -139,31 +133,37 @@ class Product {
* @return boolean
*/
public function saveProduct($product, $data) {
die;
if ($this->productGrid->findOneByField('product_id', $product->id)) {
if($product->type == 'configurable') {
$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 {
if($this->productGrid->update($product, $id)) {
return true;
} else {
return false;
$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 {
if($product->type == 'configurable') {
$this->productGrid->create($data['parent']);
} else {
if($this->productGrid->create($product)) {
return true;
} else {
return false;
//no need for tese lines
if(count($data['variants'])) {
foreach($data['variants'] as $variant) {
$this->productGrid->create($variant);
}
}
}
return true;
}
/**

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
);
}
}