Example #1
0
 /**
  * [infomationNewProduct description]
  * @param  [type] $slug [description]
  * @return [type]       [description]
  */
 public function saveNewProduct($slug)
 {
     $newProduct = Input::all();
     unset($newProduct['image']);
     $destinationPath = 'lib/images/products/';
     if (Input::hasFile('image')) {
         $filename = "product_" . Str::slug(Input::get('name')) . "." . Input::file('image')->getClientOriginalExtension();
         $filename_small = "product_" . Str::slug(Input::get('name')) . "_small." . Input::file('image')->getClientOriginalExtension();
         Input::file('image')->move($destinationPath, $filename);
         $img = $destinationPath . $filename;
         $img_small = $destinationPath . $filename_small;
         $image = new ResizeImages($img);
         $image->resizeImage(73, 73, 'exact');
         $image->saveImage($img_small, 100);
         $newProduct['image'] = $img;
         $newProduct['image_small'] = $img_small;
     }
     $product_id = Product::saveNewProduct($newProduct);
     if (Input::hasFile('image_slide')) {
         foreach (array_filter(Input::file('image_slide')) as $key => $image_slide) {
             $tmp_slide = "product_" . Str::slug(Input::get('name')) . "_{$key}." . $image_slide->getClientOriginalExtension();
             $tmp_slide_thumb = "product_" . Str::slug(Input::get('name')) . "_thumb_{$key}." . $image_slide->getClientOriginalExtension();
             $image_slide->move($destinationPath, $tmp_slide);
             $tmp_name = $destinationPath . $tmp_slide;
             $tmp_name_thmub = $destinationPath . $tmp_slide_thumb;
             $image = new ResizeImages($tmp_name);
             $image->resizeImage(67, 60, 'exact');
             $image->saveImage($tmp_name_thmub, 100);
             $array_image_slide[$key]['image'] = $tmp_name;
             $array_image_slide[$key]['image_small'] = $tmp_name_thmub;
         }
     } else {
         for ($i = 1; $i <= 4; $i++) {
             $array_image_slide[$i]['image'] = 'lib/images/products/default-product-gallery.jpg';
             $array_image_slide[$i]['image_small'] = 'lib/images/products/default-gallery-thumb.jpg';
         }
     }
     ProductInfomation::saveNewInfoProduct(Input::get('info'), Input::get('name'), $product_id);
     ProductImage::saveImagePrduct($array_image_slide, $product_id);
     Session::flash('success', 'Thêm mới thành công !');
     return Redirect::to('admin/product/' . $slug);
 }