public function saveProduct(Request $request) { $result = array('success' => 0); $image = $request->session()->get('image'); if (!empty($image)) { $a = explode('-', basename($image)); $id = array_shift($a); if (intval($id) > 0) { $prods_dir = 'uploads/product'; $image_noid = implode('-', $a); $prod = new Product(); $prod->image = $image_noid; $prod->left = floatval($request->input('left')); $prod->top = floatval($request->input('top')); $prod->width = floatval($request->input('width')); if ($prod->save()) { if (rename($image, $prods_dir . '/' . $prod->id . '-' . $image_noid) && rename(dirname($image) . '/thumbs/' . basename($image), $prods_dir . '/thumbs/' . $prod->id . '-' . $image_noid)) { $request->session()->forget('image'); $result['success'] = 1; } } } } return response()->json($result); }
/** * Display a listing of the resource. * * @return Response */ public function index(Request $request, $id) { //总销售金额 $order = new Order(); $_data['sell_total_money'] = $order->newQuery()->whereRaw('`status`>?', array(1))->sum('total_money'); //总订单数 $_data['order_total_cnt'] = $order->newQuery()->count(); //总商品数 $product = new Product(); $_data['product_total_cnt'] = $product->newQuery()->count(); //总用户数 $user = new User(); $_data['user_total_cnt'] = $user->newQuery()->count(); $this->_week_start = $week_start = date("Y-m-d 00:00:00", strtotime("-" . (date("w") - 1) . " days")); //本周销售 $_data['sell_week_money'] = $order->newQuery()->whereRaw('created_at>= ? and `status`>?', array($week_start, 1))->sum('total_money'); //本周订单 $_data['order_week_cnt'] = $order->newQuery()->whereRaw('created_at>= ?', array($week_start))->count(); //本周商品 $_data['product_week_cnt'] = $product->newQuery()->whereRaw('created_at>= ?', array($week_start))->count(); //本周用户 $_data['user_week_cnt'] = $user->newQuery()->whereRaw('created_at>= ?', array($week_start))->count(); $this->_data = $_data; return $this->view('admin.dashboard'); }
/** * Run the database seeds. * * @return void */ public function run() { $ratatouille = new App\Product(); $ratatouille->week_no = date('W'); $ratatouille->year = date('Y'); $ratatouille->name = 'Ratatouille'; $ratatouille->description = 'Ratatouille is een Frans gerecht van gestoofde groenten, dat vooral in de Provence veel wordt bereid.'; $ratatouille->city_id = 1; $ratatouille->save(); $spaghetti = new App\Product(); $spaghetti->week_no = date('W'); $spaghetti->year = date('Y'); $spaghetti->name = 'Spaghetti'; $spaghetti->description = 'Lorem ipsum.'; $spaghetti->city_id = 1; $spaghetti->save(); $visgerecht = new App\Product(); $visgerecht->week_no = date('W'); $visgerecht->year = date('Y'); $visgerecht->name = 'Visgerecht'; $visgerecht->description = 'Lorem ipsum.'; $visgerecht->city_id = 2; $visgerecht->save(); $testgerecht = new App\Product(); $testgerecht->week_no = date('W'); $testgerecht->year = date('Y'); $testgerecht->name = 'Test gerecht'; $testgerecht->description = 'Lorem ipsum.'; $testgerecht->city_id = 2; $testgerecht->save(); }
/** * */ public function loadFeed() { $xml = $this->reader->load($this->feedUrl); $content = $xml->getContent(); $this->content = $xml->getContent(); foreach ($content as $product) { $item = Product::where('externalUrl', '=', $product->productUrl)->first(); if (!$item) { $item = new Product(); } if (strlen($product->brand) > 1) { $brand = Brand::where('name', '=', $product->brand)->first(); if (!$brand) { $brand = new Brand(); $brand->name = $product->brand; $brand->save(); } if ($brand->id) { $item->brand = $brand->id; } } $item->name = $product->name; $item->description = $product->description; $item->price = $product->price; $item->regularPrice = $product->regularPrice; $item->shippingPrice = $product->shippingPrice; $item->externalUrl = $product->productUrl; $item->imageUrl = $product->graphicUrl; $item->save(); } }
public function store(Request $request) { // validate // read more on validation at http://laravel.com/docs/validation $rules = array('name' => 'required', 'brand' => 'required', 'price' => 'required|numeric'); $messages = ['required' => 'The :attribute field is required.', 'numeric' => 'The :attribute field must be numeric.']; $validator = Validator::make(Input::all(), $rules, $messages); if ($validator->fails()) { return response()->json(['error' => ['status' => ['code' => 400, 'statusText' => 'Bad Request'], 'errors' => $validator->errors()->all(), 'message' => 'Invalid request body. Ensure all fields are specified and in JSON format.']]); } else { $product = new Product(); $product->name = Input::get('name'); $product->brand = Input::get('brand'); $product->price = Input::get('price'); $product->created_at = new DateTime(); $product->updated_at = new DateTime(); if (Input::get('description') != null) { $product->description = Input::get('description'); } else { $product->description = '<small>No Descriptions</small>'; } if (Input::get('imageUrl') == null) { $product->imageUrl = 'https://cdn.filestackcontent.com/CwyooxXdTcWtwufoKgOf'; } else { $product->imageUrl = Input::get('imageUrl'); } if ($product->save()) { return response()->json(['success' => true, 'product' => $product]); } else { return response()->json(['error' => ['status' => ['code' => 500, 'statusText' => 'Internal Server Error'], 'message' => 'Failed to create new product.']]); } } }
/** * Register a product via barcode and uid (user id) * * @return \Illuminate\Http\JsonResponse */ public function scan() { header("Access-Control-Allow-Origin: *"); $response = new YYResponse(FALSE, 'Something went wrong.'); $validator = Validator::make(Request::all(), ['barcode' => 'required|integer', 'uid' => 'required|integer']); if ($validator->fails()) { $response->errors = $validator->errors(); return response()->json($response); } $product = Product::where(['barcode' => Request::get('barcode')])->get(); $product = empty($product[0]) ? NULL : $product[0]; if (empty($product)) { $product = new Product(); $product->barcode = Request::get('barcode'); $product->uid = Request::get('uid'); $product->save(); } if (!empty($product)) { $response->state = TRUE; $response->message = NULL; $response->data = $product; $response->data->reviews = Product::getReviewsById($product->id); $response->data->rating = Product::getRatingById($product->id); $response->data->rating->average = $response->data->rating->count > 0 ? $response->data->rating->total / $response->data->rating->count : 0; $response->data->review = Product::getReviewsById($product->id, $product->uid); } return response()->json($response); }
public function import(Request $request) { $file = $request->file('arquivo'); $extension = $file->getClientOriginalExtension(); $import = new Import(); $import->user_id = 1; $import->save(); Storage::disk('local')->put($import->id . '.' . $extension, File::get($file)); $handle = fopen($file, "r"); $firstTime = true; while (($line = fgetcsv($handle, 1000, "\t")) !== false) { if ($firstTime) { $firstTime = false; } else { $produto = new Product(); $produto->import_id = $import->id; $produto->purchaser_name = $line[0]; $produto->item_description = $line[1]; $produto->item_price = floatval($line[2]); $produto->purchase_count = intval($line[3]); $produto->merchant_address = $line[4]; $produto->merchant_name = $line[5]; $produto->save(); } } return view('index', ['imports' => Import::all()]); }
public function special(Request $request, $activity_id = 0) { $stores_ids = $this->user->stores->pluck('id'); $this->_brands = Brand::join('store_brand as s', 's.bid', '=', 'brands.id')->whereIn('s.sid', $stores_ids)->get(['brands.*']); $pagesize = $request->input('pagesize') ?: $this->site['pagesize']['m']; $this->_input = $request->all(); $product = new Product(); //查找猴子捞月所有在线,有效活动id $now = date("Y-m-d H:i:s"); if (!empty($activity_id)) { $activity = Activity::find($activity_id); } elseif (!empty($request->get('type_id'))) { $fids = $product->newQuery()->whereIn('bid', $this->_brands->pluck('id'))->pluck('fid'); if (!empty($fids)) { $fids = array_unique((array) $fids); } $builder = Activity::whereIn('fid', $fids)->where('type_id', $request->get('type_id')); $activity = $builder->first(); $activity_id = $builder->pluck('id'); } else { return $this->failure(NULL); } if (empty($activity)) { return $this->failure('activity::activity.no_activity'); } elseif ($activity->start_date > $now || $activity->end_date < $now || $activity->status != 1) { return $this->failure('activity::activity.failure_activity'); } //查看当前以以和店铺 猴子捞月 活动所有商品 $builder = $product->newQuery()->with(['sizes', 'covers']); $this->_activity = $activity; $this->_table_data = $builder->whereIn('activity_type', (array) $activity_id)->whereIn('bid', $this->_brands->pluck('id'))->paginate($pagesize); return $this->view('activity::m.special'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $product = new Product(); $product->name = Input::get('name'); $product->description = Input::get('description'); $product->save(); return view('products.index', ['products' => Product::all()]); }
public function store(Request $request) { $this->validate($request, ['name' => 'required', 'category' => 'required', 'price' => 'required|numeric', 'image' => 'required|image', 'detail' => 'required']); $imageName = $this->saveImage($request); $product = new Product(['name' => $request->input('name'), 'image' => 'images/products/' . $imageName, 'price' => $request->input('price'), 'detail' => $request->input('detail')]); $product->addCategory($request->input('category')); return redirect()->back(); }
/** * Add item to the cart. * * @param $id * @return \Illuminate\Http\RedirectResponse */ public function add($id) { $cart = $this->getCart(); $product = $this->product->find($id); $cart->add($id, $product->name, $product->price); $this->session->set('cart', $cart); return redirect()->route('cart'); }
public function product(Shop $shop, Product $product, Request $request) { $user = Auth::user(); $product->comments()->create(['user_id' => $user->id, 'body' => $request->input('body')]); $product->update(['num_comment' => $product->comments()->count()]); Flash::success('comment Added'); return redirect()->back(); }
/** * Creates, updates or deletes the attributes. * * @param Product $product */ protected function saveAttributes(Product $product) { $ids = []; foreach (array_filter($this->attributes) as $attribute_id => $value) { $ids[$attribute_id] = compact('value'); } $product->attributes()->sync($ids); }
protected function transfer(\App\Product $product) { $pData = unserialize($product->data); $pData->setCategory(5); $product->data = serialize($pData); $product->cat_id = 5; $product->save(); }
public function clear() { $product = new Product(); $cart = Session::get("cart"); foreach ($cart as $id => $quantity) { $product->restIncrement($id, $quantity); } Session::forget("cart"); }
/** * Add not existent product to bill. * * @param int $billId * @param AddNotExistentProductRequest $request * @return mixed */ public function addNotExistentProduct($billId, AddNotExistentProductRequest $request) { $product = new Product(); $product->user_id = Auth::user()->id; $product->code = $request->get('product_code'); $product->name = $request->get('product_name'); $product->save(); return Products::insertProduct($billId, $request->all()); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $product = new Product(); $product->name = Input::get('name'); $product->email = Input::get('email'); $product->subject = Input::get('subject'); $product->message = Input::get('message'); $product->save(); }
public function add() { $product = new Product(); $product->name = Request::input('name'); $product->description = Request::input('description'); $product->price = Request::input('price'); $product->save(); return redirect('/admin/products'); }
public function index(Slider $slider, Blog $blog, Product $shop, Section $section) { $slides = $slider->getActive(); $posts = $blog->getActive(); $products = $shop->getPopular(); // dd($products); $sections = $section->getSection(); // var_dump(\Session::get('product8')); return view('pages.index', ['slides' => $slides, 'posts' => $posts, 'products' => $products, 'sections' => $sections]); }
public function getEdit($id) { $stockRequisition = StockRequisition::find($id); $products = new Product(); $productAll = $products->getProductsWithCategories(); $parties = new Party(); $partyAll = $parties->getPartiesDropDown(); $branches = new Branch(); $branchAll = $branches->getBranchesDropDown(); return view('StockRequisition.edit', compact('stockRequisition'))->with('partyAll', $partyAll)->with('productAll', $productAll)->with('branchAll', $branchAll); }
private function storeVariant(Product $product, $data) { $data = $this->mapVariantData($data); $variant = $product->variants()->updateOrCreate(['sku' => $data['sku']], $data); // add link to channel via pivot table // inefficient should refactor if (!$variant->channels->contains($this->channel->id)) { $variant->channels()->attach($this->channel->id); } return $variant; }
/** * Asynchronously add a new product * * @param Illuminate\Http\Request $request * @return Response */ public function postAddProduct(Request $request) { $product = new Product($request->all()); $product->user_id = Auth::user()->id; $product->save(); $product->savePhotos($request); if ($request->get('publish', false)) { // deal with publising } return response()->json(['status' => 'ok'], 201); }
/** * Run the database seeds. * * @return void */ public function run() { $user = new User(); $user->name = 'mugekural'; $user->surname = str_random(10); $user->email = $user->name . '@gmail.com'; $user->is_active = true; $user->password = bcrypt('12345'); $user->type = 'App\\Supplier'; $user->save(); $supplier = new Supplier(); $supplier->phone = '023123'; $supplier->id = $user->id; $supplier->save(); $user2 = new User(); $user2->name = str_random(10); $user2->surname = str_random(10); $user2->email = $user2->name . '@gmail.com'; $user2->is_active = true; $user2->type = 'App\\Customer'; $user2->save(); $customer = new Customer(); $customer->phone = "053247557437"; $customer->id = $user2->id; $customer->save(); $instagram = new InstagramAccount(); $instagram->instagram_id = "1231231"; $instagram->access_token = "asdaddads"; $instagram->username = "******"; $instagram->full_name = "omer faruk"; $instagram->bio = "fdsfasfdsf"; $instagram->website = "string"; $instagram->profile_picture = ""; $supplier->instagramAccount()->save($instagram); $product = new Product(); $product->supplier_id = $supplier->id; $product->id = "235"; $product->is_active = true; $product->title = "kitap"; $product->description = "martı"; $product->price = "340"; $product->save(); $instagram2 = new InstagramAccount(); $instagram2->instagram_id = "700797"; $instagram2->access_token = "fjfjjfjfjf"; $instagram2->username = "******"; $instagram2->full_name = "muge kural"; $instagram2->bio = "comp stud"; $instagram2->website = "some string"; $instagram2->profile_picture = ""; $customer->instagramAccount()->save($instagram2); }
public function changeStatus(Request $request, Order $order, Product $product, $id) { $input = $request->order_status; if ($input == 4) { $content = $order->find($id)->content; foreach ($content as $item) { $product->restIncrement($item->product_id, $item->quantity); } } $order->changeStatus($id, $input); $status = $order->find($id)->status->title; return redirect()->back()->with('message', "Статус заказа изменен на '{$status}'"); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $params = $request->input(); $product = new Product(); $product->name = $params['name']; $product->company = $params['company']; $product->brand = $params['brand']; $product->description = $params['description']; $product->price = $params['price']; $product->rating = $params['rating']; $product->save(); return redirect()->action('ProductsController@index'); }
public function getProduct($slug, Product $product, Section $section) { $oneProduct = $product->getProduct($slug); // dd($oneProduct); $payment = $oneProduct->payment_system; $images = $oneProduct->galleries; // dd($images); $sections = $section->getSection(); if ($payment === 0) { return view('pages.shop.productWithPayment', ['product' => $oneProduct, 'images' => $images, 'sections' => $sections]); } return view('pages.shop.product', ['product' => $oneProduct, 'images' => $images, 'sections' => $sections]); }
/** * Shows create new pricecheck form. * * @return Response, a view for showing the form. */ public function postNew(Request $request) { $product = new Product(); $product->name = $request->input('name'); $product->description = $request->input('description'); $product->save(); $pricecheck = new PriceCheck(); $pricecheck->product = $product->id; $pricecheck->responsibleperson = $request->input('responsibleperson'); $pricecheck->responsiblepersonemail = $request->input('responsiblepersonemail'); $pricecheck->save(); return redirect('pricecheck/new')->with('success', 'Du får ett mejl till ' . $request->input('responsiblepersonemail') . ' när vi checkat vad det kostar. Skriv in en ny vara om du vill!'); }
public function index($slug, Product $product, Category $category) { if ($data['product'] = $product->getProductBySlug($slug)) { $id = $data['product']->id; //Получаем категорию продукта $category_id = $product->getCategoryByProduct($id)->id; //Получаем коллекцию предков для заданной категории $data['route'] = $category->getRouteCategories($category_id); return view('product_page', $data); } else { abort(404); } }
public function getFavourite(Request $request) { if (Auth::user()->role == 'admin') { return redirect('/dashboard'); } $page = 1; if ($request->has('page')) { $page = $request->input('page'); } $product = new Product(); $productIdlist = Preference::where('user_id', Auth::user()->id)->lists('product_id')->toArray(); $products = $product->recommend($page, $productIdlist); return view('favourite')->with(['products' => $products[0], 'paginate' => $products[1]]); }
public function add() { $file = Request::file('file'); $entry = new \App\File(); $entry->save(); $product = new Product(); $product->file_id = $entry->id; $product->name = Request::input('name'); $product->description = Request::input('description'); $product->price = Request::input('price'); $product->imageurl = Request::input('imageurl'); $product->save(); return redirect('/admin/products'); }