public function editFavoritos(Request $request) { $vatiant = $this->variantRepo->find($request->id); //var_dump($vatiant); //die(); $manager = new VariantManager($vatiant, $request->all()); $manager->save(); //Event::fire('update.store',$store->all()); return response()->json(['estado' => true, 'nombre' => $vatiant->nombreTienda]); }
public function edit(Request $request) { \DB::beginTransaction(); //$customer = $this->customerRepo->find($request->id); //$manager = new CustomerManager($customer,$request->except('fechaNac')); //$manager->save(); $product = $this->productRepo->find($request->id); //$detPres = $this->detPres->getModel(); if ($request->input('estado') == 1) { } else { $request->merge(array('estado' => '0')); } if ($request->input('hasVariants') == 1) { } else { $request->merge(array('hasVariants' => '0')); } if ($request->input('track') == 1) { } else { $request->merge(array('track' => '0')); } $request->merge(array('user_id' => Auth()->user()->id)); //var_dump($request->all());die(); $managerPro = new ProductManager($product, $request->except('sku', 'suppPri', 'markup', 'price', 'track')); //================================PROD CON VARIANTES==============================// if ($request->input('hasVariants') === true) { $managerPro->save(); $request->merge(array('product_id' => $product->id)); $product->quantVar = 0; //cantidad de variantes igual a 0; $product->save(); //$managerVar = new VariantManager($variant,$request->only('sku','suppPri','markup','price','track','product_id')); //$managerVar->save(); //================================./PROD CON VARIANTES==============================// //================================PROD SIN VARIANTES==============================// } elseif ($request->input('hasVariants') === '0') { $managerPro->save(); $request->merge(array('product_id' => $product->id)); if ($request->input('autogenerado') === true) { $sku = \DB::table('variants')->max('sku'); if (!empty($sku)) { $sku = $sku + 1; } else { $sku = 1000; //inicializar el sku; } $request->merge(array('sku' => $sku)); } else { } $product->quantVar = 0; //aunq presenta una fila en la tabla variantes por defecto $product->save(); $variant = $this->variantRepo->getModel()->where('product_id', $product->id)->first(); $managerVar = new VariantManager($variant, $request->only('sku', 'suppPri', 'markup', 'price', 'track', 'codigo', 'product_id', 'user_id')); $managerVar->save(); //var_dump($request->input('presentations')); die(); //$variant->presentation()->detach(); foreach ($request->input('presentations') as $presentation) { //var_dump('o'); die(); $presentation['variant_id'] = $variant->id; $presentation['presentation_id'] = $presentation['id']; /*$detpresRepo = new DetPresRepo(); //$oPres = $detpresRepo->getModel()->where('presentation_id',$presentation['presentation_id'])->where('variant_id',$presentation['variant_id'])->first(); $oPres = $detpresRepo->getModel(); $presManager = new DetPresManager($oPres,$presentation); $presManager->save();*/ $oPres = new DetPresRepo(); //$oStock = $stockRepo->getModel()->where('variant_id',$stock['variant_id'])->where('warehouse_id',$stock['warehouse_id'])->first(); $obj = $oPres->getModel()->where('variant_id', $presentation['variant_id'])->where('presentation_id', $presentation['presentation_id'])->first(); if (!isset($obj->id)) { $presManager = new DetPresManager($oPres->getModel(), $presentation); $presManager->save(); } else { $presManager = new DetPresManager($obj, $presentation); $presManager->save(); } } if ($request->input('track') == 1) { //$variant->warehouse()->detach(); foreach ($request->input('stock') as $stock) { if (isset($stock['stockActual']) && $stock['stockActual'] == null) { $stock['stockActual'] = 0; } if (isset($stock['stockMin']) && $stock['stockMin'] == null) { $stock['stockMin'] = 0; } if (isset($stock['stockMinSoles']) && $stock['stockMinSoles'] == null) { $stock['stockMinSoles'] = 0; } $stock['variant_id'] = $variant->id; $stockRepo = new StockRepo(); //$oStock = $stockRepo->getModel()->where('variant_id',$stock['variant_id'])->where('warehouse_id',$stock['warehouse_id'])->first(); $obj = $stockRepo->getModel()->where('variant_id', $stock['variant_id'])->where('warehouse_id', $stock['warehouse_id'])->first(); if (!isset($obj->id)) { $stockManager = new StockManager($stockRepo->getModel(), $stock); $stockManager->save(); } else { $stockManager = new StockManager($obj, $stock); $stockManager->save(); } /*$oStock = $stockRepo->getModel(); $stockManager = new StockManager($oStock, $stock); $stockManager->save(); */ } } } //================================./PROD SIN VARIANTES==============================// //================================ADD IMAGE TO PROD==============================// if ($request->has('image') and substr($request->input('image'), 5, 5) === 'image') { $image = $request->input('image'); $mime = $this->get_string_between($image, '/', ';'); $image = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $image)); Image::make($image)->resize(200, 200)->save('images/products/' . $product->id . '.' . $mime); $product->image = '/images/products/' . $product->id . '.' . $mime; $product->save(); } //================================./ADD IMAGE TO PROD==============================// \DB::commit(); return response()->json(['estado' => true, 'nombres' => $product->nombre]); }