Exemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(ProductRequest $request)
 {
     $product = new Product();
     $product->fill($request->all());
     $product->section = str_replace('products.', '', $request->section);
     $product->save();
     return redirect(route($request->section))->with('message', 'Producto creado corectamente');
 }
Exemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, Product $product)
 {
     $product->fill($request->all());
     $product->slug = str_slug($request->get('name'));
     $product->visible = $request->has('visible') ? 1 : 0;
     $updated = $product->save();
     $message = $updated ? 'Producto actualizado correctamente!' : 'El producto NO pudo actualizarse!';
     return redirect()->route('admin.product.index')->with('message', $message);
 }
Exemplo n.º 3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(SaveProductRequest $request, Product $product)
 {
     $product->fill($request->all());
     $product->slug = str_slug($request->get('name'));
     $product->visible = $request->has('visible') ? 1 : 0;
     $updated = $product->save();
     $message = $updated ? 'Product was updated successfully!' : 'Could not update product!';
     return redirect()->route('admin.product.index')->with('message', $message);
 }
 /**
  * Update the specified resource in storage.
  *
  */
 public function update(SaveProductRequest $request, Product $product)
 {
     $product->fill($request->all());
     $product->slug = str_slug($request->get('name'));
     $product->visible = $request->has('visible') ? 1 : 0;
     $updated = $product->save();
     $message = $updated ? "Producto actualizado" : "Error al actualizar";
     return redirect()->route('admin.product.index')->with('message', $message);
 }
Exemplo n.º 5
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Product $product
  * @return Response
  */
 public function update($product)
 {
     $product->fill(Input::data());
     if (Input::data('module') && ($module = Module::find(Input::data('module')['id']))) {
         $product->module()->associate($module);
     }
     $product->save();
     return $product;
 }
Exemplo n.º 6
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $a = new Product();
     if (!$a->validate(Input::all())) {
         return redirect('product/create')->withErrors($a->errors())->withInput();
     }
     $a->fill(Input::all());
     $a->save();
     Flash::success('New product is created');
     return Redirect::to('product');
 }
Exemplo n.º 7
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $object = new Model();
     $params = $request->only('img', 'slider_img', 'ru_slider', 'en_slider', 'ua_slider', 'product_category_id', 'unit_id', 'ru_title', 'ru_description', 'ru_file', 'ru_seo_title', 'ru_seo_keywords', 'ru_seo_description', 'en_title', 'en_description', 'en_file', 'en_seo_title', 'en_seo_keywords', 'en_seo_description', 'ua_title', 'ua_description', 'ua_file', 'ua_seo_title', 'ua_seo_keywords', 'ua_seo_description');
     $filter = $object->validator($params);
     if ($filter->fails()) {
         if ($request->ajax()) {
             return $this->responseAnswer(true, $params, $filter->errors());
         } else {
             $error = $filter->errors()->toArray();
             $categories = ProductCategory::all();
             $units = Unit::all();
             return view('admin.product.create', ['input' => $params, 'categories' => $categories, 'units' => $units, 'error' => $error]);
         }
     }
     if ($request->hasFile('img')) {
         $params['img'] = $this->upload('img');
     }
     if ($request->hasFile('slider_img')) {
         $params['slider_img'] = $this->upload('slider_img');
     }
     if ($request->hasFile('ru_file')) {
         $params['ru_file'] = $this->uploadPdf('ru_file');
     }
     if ($request->hasFile('en_file')) {
         $params['en_file'] = $this->uploadPdf('en_file');
     }
     if ($request->hasFile('ua_file')) {
         $params['ua_file'] = $this->uploadPdf('ua_file');
     }
     $params['on_top'] = $request->has('on_top');
     $params['alias'] = $this->makeAlias($params['ru_title']);
     $object->fill($params);
     $object->save();
     $category = ProductCategory::find($params['product_category_id']);
     $category->count = DB::table('products')->where('product_category_id', '=', $params['product_category_id'])->where('deleted_at', '=', NULL)->count();
     $category->save();
     if ($request->ajax()) {
         return $this->responseAnswer(false, $object);
     } else {
         return redirect('admin/product/' . $object->id . '/edit');
     }
 }
Exemplo n.º 8
0
 private function saveProduct(Request $request, Product $product)
 {
     $validator = Product::validate($request->all());
     if ($validator->fails()) {
         return redirect(route(Route::currentRouteName()))->withErrors($validator->errors());
     } else {
         if (!is_null($product->id)) {
             $product->update($request->all());
             Session::flash('success', "Le produit a bien été mis à jour.");
         } else {
             $product->fill($request->all());
             $product->save();
             Session::flash('success', "Le produit a bien été crée.");
         }
     }
     if ($param = Route::current()->getParameter('id')) {
         return redirect()->route(Route::currentRouteName(), $param);
     }
     return redirect()->route(Route::currentRouteName());
 }
 public function update(Request $request, Product $product)
 {
     $insert = $product->fill($request->input())->save();
     $image = \Input::get('image');
     if ($image != '') {
         $imagename = 'product-' . rand(11111, 99999) . '-gudperna.png';
         $image = str_replace(' ', '+', $image);
         list($type, $image) = explode(';', $image);
         list(, $image) = explode(',', $image);
         $image = base64_decode($image);
         file_put_contents('upload/img/' . $imagename, $image);
         $product->image = $imagename;
         $product->save();
     }
     if ($insert) {
         return 0;
     } else {
         return 1;
     }
 }
Exemplo n.º 10
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Product $product, Request $request)
 {
     //
     $data = $request->all();
     $data['created_by'] = \Auth::user()->id;
     $data['updated_by'] = \Auth::user()->id;
     $data['is_active'] = 1;
     if (Input::file('image')) {
         $destinationPath = 'img/product';
         // upload path
         $extension = Input::file('image')->getClientOriginalExtension();
         // getting image extension
         $fileName = rand(11111, 99999) . '.' . $extension;
         // renameing image
         $data['photo'] = $fileName;
         Input::file('image')->move($destinationPath, $fileName);
         // uploading file to given path
     }
     $product->fill($data)->save();
     return Redirect::route('products.index');
 }
Exemplo n.º 11
-1
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // parse url
     $url = $this->parseURLPDF();
     // Parse pdf file and build necessary objects.
     $parser = new \Smalot\PdfParser\Parser();
     $pdf = $parser->parseFile($url);
     $pages = $pdf->getPages();
     foreach ($pages as $page) {
         $p = new ParsePage($page->getArray());
         $products = $p->parseProducts();
         foreach ($products as $product) {
             $p = Product::whereCode($product['code'])->first();
             if (is_null($p)) {
                 $p = new Product();
             }
             $p->fill($product);
             $p->save();
         }
     }
 }