Ejemplo n.º 1
0
 public static function addProduct($i)
 {
     $item_name = ['Jacket', 'Hoodie', 'Kaos', 'Kemeja', 'Short Pants', 'Long Pants', 'Topi', 'Tas'];
     $color = ['Red', 'Blue', 'Green', 'Tosca', 'Tourquish', 'Orange', 'Lavender', 'Purple', 'Deep Purple', 'Pink', 'White', 'Black'];
     $style = ['Arrival', 'Retro', 'Minimalist', 'Simple', 'Unique', 'Fresh', 'Vintage', 'Stylish', 'Cool', 'Calm'];
     $kataunik = ['Komandan', 'Kopral', 'Sersan', 'Homeless', 'Rocker', 'Freaker', 'Temporary', 'Hancur', 'Baper', 'Kuper', 'Gawl'];
     $deskripsi = ['cocok untuk bepergian ke mana-mana', 'cocok bagi anak muda yang mencari jati diri', 'dipakai untuk segala momen', 'mencerahkan penampilanmu'];
     $harga = ['200000', '250000', '300000', '350000', '400000', '450000', '500000'];
     $gambar = ['jacket_distro.jpg', 'hoodie_distro.jpg', 'kaos_distro.jpg', 'kemeja_distro.jpg', 'short_pants_distro.jpg', 'long_pants_distro.png', 'topi_distro.jpg', 'tas_distro.jpg'];
     $ukuran = ['XS', 'S', 'M', 'L', 'XL', 'XXL'];
     $product = new Product();
     $product->brand_id = Brand::max('id');
     $product->category_id = $i;
     $product->name = $item_name[$i - 1] . ' ' . $color[rand(1, count($color) - 1)] . ' ' . $style[rand(1, count($style) - 1)] . ' ' . $kataunik[rand(1, count($kataunik) - 1)];
     $product->description = $item_name[$i - 1] . ' ' . $color[rand(1, count($color) - 1)] . ' ' . $style[rand(1, count($style) - 1)] . ' ' . $kataunik[rand(1, count($kataunik) - 1)] . ' ' . $deskripsi[rand(1, count($deskripsi) - 1)];
     $product->total_stock = rand(6, 10);
     $product->price_origin = $harga[rand(1, count($harga) - 1)];
     $product->price_discount = $harga[rand(1, count($harga) - 1)];
     $product->discount = '20';
     $product->available_from = '2015-07-01';
     $product->available_to = '2015-07-15';
     $product->save();
     $photo = new Photo();
     $photo->product_id = Product::max('id');
     $photo->caption = $item_name[$i - 1];
     $photo->photo_name = $gambar[$i - 1];
     $photo->photo_url = 'assets/sandbox/' . $gambar[$i - 1];
     $photo->save();
     $size = new Size();
     $size->product_id = Product::max('id');
     $size->name = $ukuran[rand(1, count($ukuran) - 1)];
     $size->stock = rand(1, 3);
     $size->save();
 }
Ejemplo n.º 2
0
 public function add_product(Request $request)
 {
     $form = array('name' => $request->prodname, 'desc' => $request->desc_input, 'price' => $request->price_input, 'category_id' => $request->category, 'subcategory_id' => $request->subcategory, 'weight' => $request->weight);
     $rules = array('name' => 'required', 'desc' => 'required', 'price' => 'required', 'category_id' => 'required', 'subcategory_id' => 'required', 'weight' => 'required');
     $validator = Validator::make($form, $rules);
     if (!$validator->fails()) {
         $category = Category::where('id', $request->category)->first();
         $category->total_product += 1;
         $category->save();
         $category = Subcategory::where('id', $request->category)->first();
         $category->total_product += 1;
         $category->save();
         $product = new Product();
         $product->category_id = $request->category;
         $product->name = $request->prodname;
         $product->slug = str_replace(" ", "-", $request->prodname);
         $product->desc = $request->desc_input;
         $product->price = $request->price_input;
         $product->subcategory_id = $request->subcategory;
         $product->weight = $request->weight;
         $product->distributor_id = $request->distributor;
         $product->status = "unactive";
         $product->save();
         $insert_id = $product->id;
         $photos = array();
         for ($i = 0; $i < 5; $i++) {
             $form = strval('tes_' . $i);
             if (!is_null($request->{$form})) {
                 $file = Input::file($form);
                 $img = Image::make($file);
                 $filename = rand() . '.jpg';
                 $img->widen(370);
                 $img->save(storage_path('photo_product/' . $filename), 50);
                 if ($i == 0) {
                     $img->fit(220);
                     $img->save(storage_path('photo_product/2_' . $filename), 50);
                 }
                 array_push($photos, $filename);
             }
         }
         $product->image = serialize($photos);
         $product->save();
         return redirect('master/produk/create')->with('completed', 'Produk berhasil ditambahkan');
     } else {
         return redirect('master/produk/create')->with('failed', 'Produk gagal ditambahkan');
     }
 }
Ejemplo n.º 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required']);
     $product = new Product();
     $product->name = $request->get('name');
     $product->save();
     return redirect()->route('products.index')->with('message_success', 'Product ' . $product->name . ' has been successfully created');
 }
 public function store()
 {
     $modelObj = new Product();
     $modelObj->category_id = Request::input('category_id');
     $modelObj->name = Request::input('name');
     $modelObj->status = Request::input('status');
     $modelObj->price = Request::input('price');
     $modelObj->description = Request::input('description');
     $modelObj->img = 'products/product-1.jpg';
     $modelObj->save();
     return $this->lists($modelObj->product_id);
 }
Ejemplo n.º 5
0
 function save_product($input)
 {
     $product = new Product();
     // echo Request::file('image');
     $product->name = $input['name'];
     // $product->category = $input['category'];
     // $product->type = $input['type'];
     // $product->age = $input['age'];
     $product->description = $input['description'];
     $product->price = $input['price'];
     $product->price_disc = $input['price_disc'];
     $product->price_reseller = $input['price_reseller'];
     $product->brand = $input['product_brand'];
     $product->code = $input['product_code'];
     $product->created_date = Carbon::now();
     $type = explode(',', $input['type']);
     $age = explode(',', $input['age']);
     $file = Request::file('image');
     $extension = $file->getClientOriginalExtension();
     $destinationPath = './public/upload/';
     $fileName = $input['product_code'] . '.jpg';
     // Request::file('image')->move($destinationPath, $fileName);
     $img = Image::make($file->getRealPath());
     $img->resize(null, 600, function ($constraint) {
         $constraint->aspectRatio();
     })->save($destinationPath . $fileName);
     // $db_type = new Product_type();
     if ($product->save()) {
         $arr_type = [];
         $arr_age = [];
         foreach ($type as $key => $value) {
             array_push($arr_type, ['product_id' => $product->id, 'type' => $value]);
         }
         foreach ($age as $key => $value) {
             array_push($arr_age, ['product_id' => $product->id, 'age' => $value]);
         }
         DB::table('product_type')->insert($arr_type);
         DB::table('product_age')->insert($arr_age);
         return Response::json(array('success' => true, 'pages' => $product->code, 'last_insert_id' => $product->id), 200);
     }
 }