fixed product create
This commit is contained in:
parent
b194c7670f
commit
614757ecaf
|
|
@ -64,9 +64,12 @@ class ProductController extends Controller
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
(new ProductService)->create($request->all());
|
(new ProductService)->create($request->all());
|
||||||
return redirect()->to($this->getRedirect())->with('success', trans('common.created_success'));
|
return redirect()->to(admin_route('products.index'))
|
||||||
|
->with('success', trans('common.created_success'));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return redirect(admin_route('product.create'))->withErrors(['error' => $e->getMessage()]);
|
return redirect(admin_route('products.create'))
|
||||||
|
->withInput()
|
||||||
|
->withErrors(['error' => $e->getMessage()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ class ProductService
|
||||||
try {
|
try {
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$data['brand_id'] = (int)$data['brand_id'];
|
||||||
$data['variables'] = json_decode($data['variables']);
|
$data['variables'] = json_decode($data['variables']);
|
||||||
$product->fill($data);
|
$product->fill($data);
|
||||||
$product->save();
|
$product->save();
|
||||||
|
|
@ -47,6 +48,9 @@ class ProductService
|
||||||
$skus = [];
|
$skus = [];
|
||||||
foreach ($data['skus'] as $index => $sku) {
|
foreach ($data['skus'] as $index => $sku) {
|
||||||
$sku['position'] = $index;
|
$sku['position'] = $index;
|
||||||
|
$sku['origin_price'] = (float)$sku['origin_price'];
|
||||||
|
$sku['cost_price'] = (float)$sku['cost_price'];
|
||||||
|
$sku['quantity'] = (int)$sku['quantity'];
|
||||||
$skus[] = $sku;
|
$skus[] = $sku;
|
||||||
}
|
}
|
||||||
$product->skus()->createMany($skus);
|
$product->skus()->createMany($skus);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue