public function postAddProduct(Request $request) { if (Auth::user()->email == '*****@*****.**') { $validator = Validator::make($request->all(), ['category_id' => 'required|integer', 'subcategory_id' => 'required|integer', 'name' => 'required', 'brand_id' => 'required|integer', 'model_id' => 'required|integer', 'weight' => 'required', 'klimatik' => 'required', 'count_doors' => 'required', 'engine' => 'required', 'kubatura' => 'required', 'transmission' => 'required', 'car_type' => 'required', 'status' => 'required', 'position' => 'required', 'vt_number' => 'required', 'price' => 'required']); if ($validator->fails()) { return redirect('/admin/add-products')->withErrors($validator)->withInput(); } $product = new Products(); $product->category = $request->input('category_id'); $product->sub_category = $request->input('subcategory_id'); $product->name = $request->input('name'); $product->brand = $request->input('brand_id'); $product->model = $request->input('model_id'); $product->weight = $request->input('weight'); $product->klimatik = $request->input('klimatik'); $product->count_doors = $request->input('count_doors'); $product->engine = $request->input('engine'); $product->kubatura = $request->input('kubatura'); $product->transmission = $request->input('transmission'); $product->car_type = $request->input('car_type'); $product->status = $request->input('status'); $product->position = $request->input('position'); $product->vt_number = $request->input('vt_number'); $product->price = $request->input('price'); $product->price_count = $request->input('price_count'); $product->save(); return redirect()->back()->with($request->session()->flash('admin-success', 'Успешно създадохте продукт.')); } return redirect('/'); }
public function create(Request $request) { $validator = Validator::make($request->all(), ['name' => 'required', 'status' => 'required', 'publisher_id' => 'required', 'image' => 'required']); if ($validator->fails()) { return Response::json(array('result' => false, 'data' => 'data is valid.')); } $validate = Products::where('name', $request->input('name'))->count(); if ($validate > 0) { return Response::json(array('result' => false, 'data' => 'Producrs name can not duplicate.')); } $now = Carbon::now('Asia/Bangkok'); $pro = new Products(); $pro->name = $request->input('name'); $pro->code = md5($request->input('name') . '' . $now->format("Y-m-d H:i:s")); //$pro->name_th = $request->input('name_th'); $pro->status = $request->input('status'); $pro->image = $request->input('image'); $pro->author = $request->input('author'); $pro->resume = $request->input('resume'); $pro->created_at = Carbon::now('Asia/Bangkok'); $pro->updated_at = Carbon::now('Asia/Bangkok'); $pro->publisher_id = $request->input('publisher_id'); $result = $pro->save(); if ($result) { return Response::json(array('result' => true, 'data' => $pro)); } return Response::json(array('result' => false, 'data' => 'Create has been error.')); }
/** * Run the migrations. * * @return void */ public function up() { Schema::create('products', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('colors'); $table->string('sizes'); $table->text('content'); $table->integer('price')->unsigned; $table->string('picture'); $table->string('size_picture'); $table->timestamps(); $table->string('seller_id'); }); $prosJson = File::get(storage_path() . '/data/seed.json'); $pros = json_decode($prosJson); foreach ($pros as $proData) { $pro = new Products(); $pro->name = $proData->name; $pro->colors = '["black", "white"]'; $pro->sizes = '["S", "M", "L"]'; $pro->content = 'This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.This is a the content of the clothes.'; $proData->price = str_replace('$', '', $proData->price); $pro->price = str_replace(',', '', $proData->price); $pro->picture = $proData->picture; if (isset($proData->{'size-picture'})) { $pro->size_picture = $proData->{'size-picture'}; } $pro->seller_id = 'A1234'; $pro->save(); } }
public function postAdd(Request $request) { if (!ACL::hasPermission('products', 'add')) { return redirect(route('products'))->withErrors(['Você não pode adicionar produtos.']); } $this->validate($request, ['name' => 'required|max:100', 'productsCategoriesId' => 'required', 'presentation' => 'required', 'bull' => 'required', 'image' => 'required|image|mimes:jpeg,gif,png'], ['name.required' => 'Informe o nome do produto', 'name.max' => 'O nome do produto não pode passar de :max caracteres', 'productsCategoriesId.required' => 'Escolha a categoria do produto', 'presentation.required' => 'Informe a apresentação do produto', 'bull.required' => 'Informe o endereço da bula', 'image.required' => 'Envie a imagem do produto', 'image.image' => 'Envie um formato de imagem válida', 'image.mimes' => 'Formatos suportados: .jpg, .gif e .png']); $product = new Products(); $product->name = $request->name; $product->productsCategoriesId = $request->productsCategoriesId; $product->activePrinciple = $request->activePrinciple; $product->presentation = $request->presentation; $product->bull = $request->bull; $product->slug = str_slug($request->name, '-'); //IMAGE $extension = $request->image->getClientOriginalExtension(); $nameImage = Carbon::now()->format('YmdHis') . "." . $extension; $image = Image::make($request->file('image')); if ($request->imageCropAreaW > 0 or $request->imageCropAreaH > 0 or $request->imagePositionX or $request->imagePositionY) { $image->crop($request->imageCropAreaW, $request->imageCropAreaH, $request->imagePositionX, $request->imagePositionY); } $image->resize($this->imageWidth, $this->imageHeight)->save($this->folder . $nameImage); $product->image = $nameImage; $product->save(); $success = "Produto adicionado com sucesso."; return redirect(route('products'))->with(compact('success')); }
public function productsave(ProductRequest $request) { //$carbondatetime = Carbon::now();date('\YY\Mm\Dd\THi') $imageName = date('\\YY\\Mm\\Dd\\THi') . str_random(3) . str_random(4) . '.' . $request->file('image')->getClientOriginalExtension(); $request->file('image')->move(public_path() . '/uploads/', $imageName); $product = new Products(array('name' => $request->get('name'), 'brand_id' => $request->get('brand_id'), 'imgurl' => $imageName, 'price' => $request->get('price'), 'description' => $request->get('description'), 'image' => url('uploads/' . $imageName))); $product->save(); Session::flash('flash_message', 'Well done! Sản phẩm mới đã được tạo thành công.'); Session::flash('flash_type', 'alert-success'); return \Redirect::route('products'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $pros = new Products(); $pros->name = $request->input('name'); $pros->colors = $request->input('colors'); $pros->sizes = $request->input('sizes'); $pros->content = $request->input('content'); $pros->price = $request->input('price'); $pros->picture = $request->input('picture'); $pros->seller_id = $request->input('seller_id'); $pros->save(); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $input = $request->only('name', 'modelNo', 'price', 'description', 'category_id', 'brand', 'quantityInStock', 'size', 'sale', 'timeSale'); $validator = $this->validator($input); if ($validator->fails()) { return redirect('admin/product_add')->withErrors($validator); } else { $product = new Products(); $product->name = $request->input('name'); $product->modelNo = $request->input('modelNo'); $product->price = $request->input('price'); $product->sale = $request->input('sale'); $product->timeSale = $request->input('timeSale'); $product->description = $request->input('description'); $product->category_id = $request->input('category_id'); $product->brand = $request->input('brand'); $product->quantityInStock = $request->input('quantityInStock'); $product->save(); $sizes = $request->input('size'); foreach ($sizes as $size) { $productSize = new productSize(); $productSize->name = $size; $productSize->product_id = $product->id; $productSize->save(); } $imageName = ''; $images = $request->file('image'); foreach ($images as $image) { $rules = ['image' => 'required|image|mimes:jpg,jpeg,png,gif|image_size:<=30000']; $validator = Validator::make(array('image' => $image), $rules); if ($validator->passes()) { global $imageName; $rand = rand(1, 10000); $imageName = $rand . '.' . $request->input('modelNo') . '.' . $image->getClientOriginalExtension(); $image->move(base_path() . '/public/images_product', $imageName); $image = new Images(); $image->name = 'images_product/' . $imageName; $image->product_id = $product->id; $image->save(); } else { return redirect('admin/product_add')->withErrors($validator); } } return redirect('admin/product_list'); } }
public function postAdd(Request $request) { if (!ACL::hasPermission('products', 'add')) { return redirect(route('products'))->withErrors(['Você não pode adicionar produtos.']); } $this->validate($request, ['title' => 'required|max:45', 'description' => 'required', 'urlBuy' => 'required', 'image' => 'required|image|mimes:png'], ['title.required' => 'Informe o título do produto', 'title.max' => 'O título do produto não pode passar de :max caracteres', 'description.required' => 'Informe a descrição do produto', 'urlBuy.required' => 'Informe o link para compra do produto', 'image.image' => 'Envie um formato de imagem válida', 'image.mimes' => 'Formato suportado: .png com fundo transparente']); $lastProduct = Products::orderBy('sortorder', 'DESC')->addSelect('sortorder')->first(); $product = new Products(); $product->title = $request->title; $product->description = $request->description; $product->urlBuy = $request->urlBuy; $product->sortorder = $lastProduct->sortorder + 1; //IMAGE $extension = $request->image->getClientOriginalExtension(); $nameImage = Carbon::now()->format('YmdHis') . "." . $extension; Image::make($request->file('image'))->resize($this->imageWidth, $this->imageHeight)->save($this->folder . $nameImage); $product->image = $nameImage; $product->save(); $success = "Produto adicionado com sucesso."; return redirect(route('products'))->with(compact('success')); }
public function store(Request $request) { $categories = $request->input('category'); $name = $request->input('name'); $duplicate = Products::where('name', $name)->first(); if ($duplicate) { return redirect('/product/create')->withErrors('The name already exists'); } $description = $request->input('description'); $price = $request->input('price'); $user_id = $request->user()->id; $product = new Products(); $product->name = $name; $product->description = $description; $product->price = $price; $product->quantity = $request->input('quantity'); $product->author_id = $user_id; $product->slug = str_slug($request->input('name')); $product->active = 1; if (Input::file('image') != null) { $destinationPath = 'images/catalog'; // upload path $extension = Input::file('image')->getClientOriginalExtension(); // getting image extension $fileName = rand(11111, 99999) . '.' . $extension; // renameing image $product->image = $fileName; Input::file('image')->move($destinationPath, $fileName); // uploading file to given path } $product->save(); if ($categories) { foreach ($categories as $category) { $category = Categories::where('title', $category)->first(); $product->categories()->attach($category->id); } } return redirect('/')->withMessage('New product created'); }
public function indexGames() { $crawler = new Crawler(); //--------------------extract all product details---------------------- global $products; $products = array(); $html = file_get_contents("http://www.lelong.com.my/toys-and-games/game-console/"); $crawler->addContent($html); //------------------extract retailer logo------------------------ //$retailer_logo = $crawler->filter('div#top1Logo img')->attr('src'); //--------------------------------------------------------------- //---------------------------filter category------------------------------- $category = $crawler->filter('a[href="/toys-and-games/game-console/"]')->text(); //------------------------------------------------------------------------- $crawler->filter('div.item4inline')->each(function ($crawler) { for ($i = 2; $i <= 5;) { $url = 'http://www.lelong.com.my/toys-and-games/game-console/?D=' . $i; $html = file_get_contents($url); $crawler->addContent($html); global $products; global $rank; $rank = $crawler->filter('span.catalogTitle')->each(function ($crawler, $i) use(&$products) { $products[$i]['title'] = $crawler->text(); $products[$i]['url'] = str_replace('//', '', $crawler->parents()->attr('href')); }); $rank = $crawler->filter('div.catalogPrice b')->each(function ($crawler, $i) use(&$products) { $toReplace = array('RM', ','); $with = array('', ''); $products[$i]['price'] = str_replace($toReplace, $with, $crawler->text()); }); $rank = $crawler->filter('div.catalog-wrap')->each(function ($crawler, $i) use(&$products) { $products[$i]['image'] = $crawler->parents()->attr('id'); }); $rank = $crawler->filter('div.catalogIcon')->each(function ($crawler, $i) use(&$products) { $products[$i]['shipping'] = $crawler->children()->text(); }); ++$rank; $i++; //print_r($products); } }); //--------------insert data using model----------------- foreach ($products as $pro) { $product = new Products(); if ($category == 'Game Console') { $product->category_id = 6; $product->condition_id = 3; } $arrProduct = explode(' ', $pro['title']); $brands = \DB::table('brand')->whereIn('brand_title', $arrProduct)->get(); if ($brands) { foreach ($brands as $brand) { $product->brand_id = $brand->id; } } else { $product->brand_id = 204; } $product->product_name = $pro['title']; $product->shopper_link = $pro['url']; $product->product_price = $pro['price']; $product->picture_link = $pro['image']; $product->product_shipping = $pro['shipping']; $product->save(); } //------------------------------------------------------- }
public function indexNewGames() { $crawler = new Crawler(); //--------------------extract all product details---------------------- global $products; $products = array(); for ($i = 1; $i < 2; $i++) { $url = 'http://www.ebay.com.my/sch/Consoles-/139971/i.html?LH_ItemCondition=1000|4000|5000|6000&_pgn=' . $i . '&_skc=200&rt=nc'; $html = file_get_contents($url); $crawler->addContent($html); //------------------filter category------------------------ $category = $crawler->filter('span.kwcat b')->text(); //print_r($category); //--------------------------------------------------------- //------------------filter condition----------------------- $condition = $crawler->filter('span.cbx')->text(); //print_r($condition); //--------------------------------------------------------- //echo "<br><br><strong>Page</strong>" . $i . " > " . $url . "<br><br>"; $crawler->filter('ul#ListViewInner')->each(function ($crawler) { global $products; global $rank; $rank = $crawler->filter('h3.lvtitle a')->each(function ($crawler, $i) use(&$products) { $products[$i]['title'] = $crawler->text(); $products[$i]['url'] = $crawler->attr('href'); }); $rank = $crawler->filter('ul.lvprices.left.space-zero')->each(function ($crawler, $i) use(&$products) { $toReplace = array('RM', ','); $with = array('', ''); $products[$i]['price'] = str_replace($toReplace, $with, $crawler->filter('li.lvprice.prc')->last()->text()); }); $rank = $crawler->filter('a.img.imgWr2 img')->each(function ($crawler, $i) use(&$products) { $products[$i]['image'] = $crawler->attr('src'); }); $rank = $crawler->filter('span.ship')->each(function ($crawler, $i) use(&$products) { $products[$i]['shipping'] = $crawler->text(); }); ++$rank; }); //dd($products); } //-------------insert data using model-------------- foreach ($products as $pro) { $product = new Products(); if ($category == 'Consoles') { $product->category_id = 6; } if ($condition == 'Brand New(selected)') { $product->condition_id = 1; } $arrProduct = explode(' ', $pro['title']); $brands = \DB::table('brand')->whereIn('brand_title', $arrProduct)->get(); if ($brands) { foreach ($brands as $brand) { $product->brand_id = $brand->id; } } else { $product->brand_id = 204; } $product->product_name = $pro['title']; $product->shopper_link = $pro['url']; $product->product_price = $pro['price']; $product->picture_link = $pro['image']; $product->product_shipping = $pro['shipping']; $product->save(); } //--------------------------------------------------- }
public function create(Request $request) { $product = new Products(); $product->save(); return redirect()->route('products.edit', [$product->id]); }
private function cycomExtractor($retailer) { $pricelist_filter = fopen(public_path() . '/file/pricelist-filter/' . $retailer . "-filter.txt", 'r') or die('Unable to open file!'); // Output one line until end-of-file $products_list = []; while (!feof($pricelist_filter)) { $line = fgets($pricelist_filter); $line = trim($line, ";"); $tokens = explode(";", $line); $replace = array("+", "/", "(", ")", "|", ",\r\n", ",", "-", "!"); $toReplace = array("\\+", "\\/", "\\(", "\\)", "\\|", "", "", "\\-", "\\!"); $product = str_replace($replace, $toReplace, $tokens); // Append the line array. $products_list[] = $product; } fclose($pricelist_filter); $products = []; $index = 1; foreach ($products_list as $product) { $pricelist_pdf = fopen(public_path() . "/file/" . $retailer . "-pricelist-pdf.txt", "r") or die("Unable to open file!"); // Output one line until end-of-file while (!feof($pricelist_pdf)) { if (preg_match('/' . $product[2] . '(.*?)([\\d]+)/', fgets($pricelist_pdf), $match)) { $replace = array('\\+', '\\/', '\\(', '\\)', '\\|', '\\-', '\\!'); $toReplace = array('+', '/', '(', ')', '|', '-', '!'); $_product = str_replace($replace, $toReplace, $product); $products[] = array($index, $_product[0], $_product[1], str_replace($_product[2], '', $match[0])); } } fclose($pricelist_pdf); $index++; } $update_pid = ""; foreach ($products as list($index, $product, $product_name, $price)) { $product_spread = explode(' ', strtolower($product)); // dd($product_spread); //filter brand from database with spread product name $brands = \DB::table('brand'); foreach ($product_spread as $spread) { $brands->orWhere('brand_title', 'LIKE', $spread); } $brands = $brands->distinct()->get(); $product_brand = ""; if ($brands) { //if filter brand match with product name..... foreach ($brands as $brand) { $product_brand = $brand->id; } } else { //if filter brand not match with product name set as brand:other..... $product_brand = 1; } //default picture $pricefilter = $this->priceFilter($product_name, $product); if ($pricefilter) { //return true, add product to database $new_product = new Products(); $new_product->product_name = $product_name . ' ' . $product; $new_product->product_price = $price; $new_product->product_price_temp = $price; $new_product->product_rating = 0; $new_product->product_reviews = 0; $new_product->condition_id = 1; $new_product->brand_id = $product_brand; $new_product->category_id = 1; $new_product->created_at = Carbon::now(); $new_product->updated_at = Carbon::now(); $new_product->save(); } else { //return false, update product price only } // $update_pid = $update_pid.$pricefilter; } echo "<div class='alert alert-success'>Successfully process pdf data</div>"; }
public function indexGames() { $crawler = new Crawler(); //-------------extract all product details------------------ global $products; $products = array(); $html = file_get_contents("http://www.mudah.my/Malaysia/Games-and-Consoles-for-sale-3120?lst=0&fs=1&cg=3120&w=3&so=1&st=s"); $crawler->addContent($html); //------------------filter category------------------------ $category = $crawler->filter('a[title="See all ads in Games & Consoles category"] span')->text(); //---------------------------------------------------------- $crawler->filter('div.listing_thumbs')->each(function ($crawler) { for ($i = 2; $i <= 5;) { $url = 'http://www.mudah.my/Malaysia/Games-and-Consoles-for-sale-3120?o=' . $i . '&q=&so=1&th=1'; $html = file_get_contents($url); $crawler->addContent($html); global $rank; global $products; $rank = $crawler->filter('h2.list_title.truncate a')->each(function ($crawler, $i) use(&$products) { $products[$i]['title'] = $crawler->text(); $products[$i]['url'] = $crawler->attr('href'); }); $rank = $crawler->filter('div.ads_price')->each(function ($crawler, $i) use(&$products) { $toReplace = array(' ', 'RM'); $with = array('', ''); $products[$i]['price'] = str_replace($toReplace, $with, $crawler->text()); }); $rank = $crawler->filter('li.listing_thumbs_image img')->each(function ($crawler, $i) use(&$products) { $products[$i]['image'] = $crawler->attr('src'); }); $rank = $crawler->filter('div.location')->each(function ($crawler, $i) use(&$products) { $products[$i]['location'] = str_replace(' ', '', $crawler->children()->siblings()->text()); }); $rank = $crawler->filter('div[title="Condition"]')->each(function ($crawler, $i) use(&$products) { $products[$i]['condition'] = $crawler->text(); }); ++$rank; $i++; //print_r($products); } }); //--------------insert data using model----------------- foreach ($products as $pro) { $product = new Products(); if ($category == 'Games & Consoles') { $product->category_id = 6; } $arrProduct = explode(' ', $pro['title']); $brands = \DB::table('brand')->whereIn('brand_title', $arrProduct)->get(); if ($brands) { foreach ($brands as $brand) { $product->brand_id = $brand->id; } } else { $product->brand_id = 1; } $product->product_name = $pro['title']; $product->shopper_link = $pro['url']; $product->product_price = $pro['price']; $product->picture_link = str_replace('thumbs', 'images', $pro['image']); $product->product_location = $pro['location']; if ($pro['condition'] == 'New') { $product->condition_id = 1; } else { $product->condition_id = 2; } $product->save(); } //-------------------------------------------------------- return "<div class='alert alert-success'>Successfully crawler site</div>"; }