Example #1
0
 /**
  * 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');
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $product = Product::find($id);
     $product->browsed++;
     $product->save();
     return view('product.show', ['product' => $product]);
 }
 /**
  * falta por implementar, no se usa por el momento
  *
  **/
 public function show($id)
 {
     $product = Product::find($id);
     $relatedProducts = Product::where('category', '=', $product->category)->where('id', '!=', $product->id)->take(4)->get();
     //dd($relatedProducts);
     return view('pages.show')->with(['product' => $product, 'relatedProducts' => $relatedProducts]);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $order = new \App\Order($request->all());
     $cart = $request->session()->get('cart', function () {
         return null;
     });
     if ($cart == null) {
         return redirect('cart');
     }
     DB::transaction(function () use($order, $cart) {
         $order->save();
         $total = 0;
         foreach ($cart as $id => $qty) {
             if ($qty <= 0) {
                 continue;
             }
             $pro = \App\Product::find($id);
             $od = new \App\OrderDetail();
             $od->price = $pro->price;
             $od->quantity = $qty;
             $od->product()->associate($pro);
             $od->order()->associate($order);
             $od->save();
             $total += $qty * $pro->price;
         }
         if ($total > 0) {
             $order->status = 1;
             //????????????
             $order->total = $total;
             $order->update();
         }
     });
     $request->session()->forget('cart');
     return redirect('order');
 }
Example #5
0
 public function update(Request $request, $id)
 {
     $category = Category::find($id);
     $category->name = $request->name;
     $category->is_active = $request->is_active;
     if (!is_null($request->products)) {
         if (!is_null($category->Product)) {
             foreach ($category->Product as $product) {
                 $product->category = NULL;
                 $product->save();
             }
         }
         foreach ($request->products as $id) {
             $obj = Product::find($id);
             $obj->category = $category->id;
             $obj->save();
         }
     }
     if (!empty($request->image)) {
         File::delete(public_path($category->path));
         $img = $request->image;
         $imgName = $img->getClientOriginalName();
         $path = "/catalog/img/brand/" . $category->id . "/";
         $category->path = $path . $imgName;
         $img->move(public_path($path), $imgName);
         $category->save();
     }
     $category->save();
     return redirect('admin/category');
 }
Example #6
0
 public function getSetDone($id)
 {
     $product = Product::find($id);
     $product->status = 'done';
     $product->save();
     return response()->json(true);
 }
 public function showProduct($id)
 {
     $product = Product::find($id);
     // Get all reviews that are not spam for the product and paginate them
     $reviews = $product->reviews()->with('user')->approved()->notSpam()->orderBy('created_at', 'desc')->paginate(10);
     return \View::make('products.show', array('product' => $product, 'reviews' => $reviews));
 }
 /**
  * Create a new product.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required|max:255', 'store_id' => 'required', 'location_id' => 'required', 'source_id' => 'required']);
     if (!$request->id) {
         $request->quantity = $request->quantity ? $request->quantity : 1;
         Product::create(['name' => $request->name, 'store_id' => $request->store_id, 'location_id' => $request->location_id, 'source_id' => $request->source_id, 'purchase_price' => $request->purchase_price, 'sale_price' => $request->sale_price, 'shipping_paid' => $request->shipping_paid, 'actual_shipping' => $request->actual_shipping, 'seller_fee' => $request->seller_fee, 'shipping_fee' => $request->shipping_fee, 'product_status' => $request->product_status, 'quantity' => $request->quantity, 'quantity_sold' => $request->quantity_sold, 'improvement_hours' => $request->improvement_hours, 'improvement_dollars' => $request->improvement_dollars]);
     } else {
         $product = Product::find($request->id);
         $product->name = $request->name;
         $product->store_id = $request->store_id;
         $product->location_id = $request->location_id;
         $product->source_id = $request->source_id;
         $product->purchase_price = $request->purchase_price;
         $product->sale_price = $request->sale_price;
         $product->shipping_paid = $request->shipping_paid;
         $product->actual_shipping = $request->actual_shipping;
         $product->seller_fee = $request->seller_fee;
         $product->shipping_fee = $request->shipping_fee;
         $product->product_status = $request->product_status;
         $product->quantity = $request->quantity;
         $product->quantity_sold = $request->quantity_sold;
         $product->improvement_hours = $request->improvement_hours;
         $product->improvement_dollars = $request->improvement_dollars;
         $product->save();
     }
     if ($request->submit == 'Save') {
         return redirect('/product');
     } else {
         return redirect('/product/create?source=' . $request->source_id . '&store=' . $request->store_id . '&location_id=' . $request->location_id);
     }
     return redirect('/product');
 }
 /**
  *	delete key registered (Only this seller)
  *	@param	$id 	int|string 	id the virtual product
  *	@param	$res 	Request 	object to validate the type of request, action
  *	@return	json
  */
 public function deleteKey($id, Request $res)
 {
     if (!$res->wantsJson()) {
         return redirect()->back();
     }
     $VirtualProduct = VirtualProduct::find($id);
     if (!count($VirtualProduct->toArray())) {
         return json_encode(['message' => trans('globals.error_not_available')]);
     }
     $product = Product::find($VirtualProduct->product_id);
     if (!count($product->toArray())) {
         return json_encode(['message' => trans('globals.error_not_available')]);
     }
     if ($product->user_id != \Auth::id()) {
         return json_encode(['message' => trans('globals.not_access')]);
     }
     $VirtualProductOrder = VirtualProductOrder::where('virtual_product_id', $VirtualProduct->id)->get();
     if (count($VirtualProductOrder->toArray()) > 0) {
         return json_encode(['message' => trans('product.virtualProductsController_controller.key_been_sold')]);
     }
     $VirtualProduct->status = 'cancelled';
     $VirtualProduct->save();
     $stock = count(VirtualProduct::where('product_id', $product->id)->where('status', 'open')->get()->toArray());
     $product->stock = $stock;
     if ($stock == 0) {
         $product->status = 0;
     }
     $product->save();
     return json_encode(['success' => trans('product.controller.saved_successfully')]);
 }
Example #10
0
 public function cart()
 {
     if (Request::isMethod('post')) {
         $product_id = Request::get('product_id');
         $product = Product::find($product_id);
         Cart::add(array('id' => $product_id, 'name' => $product->name, 'qty' => 1, 'price' => $product->price));
     }
     if (Request::get('product_id')) {
         $rowId = Cart::search(array('id' => Request::get('product_id')));
         $item = Cart::get($rowId[0]);
         if (Request::get('increment') == 1) {
             Cart::update($rowId[0], $item->qty + 1);
         } else {
             if (Request::get('decrement') == 1) {
                 Cart::update($rowId[0], $item->qty - 1);
             } else {
                 if (Request::get('delete') == 1) {
                     Cart::remove($rowId[0]);
                 }
             }
         }
     } else {
         if (Request::get('clear_cart') == 1) {
             Cart::destroy();
         }
     }
     $cart = Cart::content();
     return view('cart', array('cart' => $cart, 'title' => 'Welcome', 'description' => '', 'page' => 'home'));
 }
Example #11
0
 public function show_for_other_user($user_id)
 {
     $list = Lists::where('user_id', '=', $user_id)->get();
     $user_list = [];
     foreach ($list as $pro) {
         $product_id = $pro->product_id;
         $product = Product::find($product_id);
         if ($product != null) {
             $created_by = $product['created_by'];
             $category = Category::find($product['category_id']);
             $category = $category['category'];
             $user = User::find($created_by);
             array_add($product, 'category', $category);
             array_add($product, 'created_by_name', $user['name']);
             $initial = explode(".", $product['image_url']);
             $thumbFirst = "";
             for ($i = 0; $i < sizeof($initial) - 1; $i++) {
                 $thumbFirst = $thumbFirst . $initial[$i];
             }
             $thumbnail = $thumbFirst . '-130x90.' . $initial[sizeof($initial) - 1];
             //thumb size changed
             array_add($product, 'thumbnail', $thumbnail);
             array_push($user_list, $product);
         }
     }
     return response()->json(['list' => $user_list]);
 }
 public function showByUser($user_id)
 {
     //directly copied pasted from list controller.
     $list = Vote::where('user_id', '=', $user_id)->get();
     $user_list = [];
     foreach ($list as $pro) {
         $product_id = $pro->product_id;
         $product = Product::find($product_id);
         if ($product != null) {
             $created_by = $product['created_by'];
             $category = Category::find($product['category_id']);
             $category = $category['category'];
             $user = User::find($created_by);
             array_add($product, 'category', $category);
             array_add($product, 'created_by_name', $user['name']);
             $initial = explode(".", $product['image_url']);
             $thumbFirst = "";
             for ($i = 0; $i < sizeof($initial) - 1; $i++) {
                 $thumbFirst = $thumbFirst . $initial[$i];
             }
             $thumbnail = $thumbFirst . '-200x200.' . $initial[sizeof($initial) - 1];
             array_add($product, 'thumbnail', $thumbnail);
             array_push($user_list, $product);
         }
     }
     return $user_list;
     //        return response()->json([
     //                'upvotted'=>$user_list]
     //        );
 }
Example #13
0
 public function addItem(Request $request, $productId)
 {
     #check service
     $product = Product::find($productId);
     if (!$product) {
         return redirect()->route("home")->with("error", "No product select");
     }
     $qty = $request->get("qty", 0);
     $user = Sentinel::getUser();
     $cart = $this->_createCart();
     $this->billing($cart, $request);
     $cartItem = new Cartitem();
     $cartItem->product_id = $productId;
     $cartItem->cart_id = $cart->id;
     $cartItem->quantity = $qty;
     $cartItem->track_num = $request->get('track_num', '');
     $cartItem->carrier = $request->get('carrier', '');
     $cartItem->unit_price = $product->price;
     $cartItem->save();
     for ($i = 0; $i < $qty; $i++) {
         if (!$request->has("passenger_id-" . $i)) {
             $birthdate = $request->get("year-dob-" . $i) . '-' . $request->get("month-dob-" . $i) . '-' . $request->get("day-dob-" . $i);
             $passport_expirate = $request->get("year-passportExp-" . $i) . '-' . $request->get("month-passportExp-" . $i) . '-' . $request->get("day-passportExp-" . $i);
             $passenger = Passenger::create(['first_name' => $request->get("fname-" . $i), 'last_name' => $request->get("lname-" . $i), 'gender' => $request->get("gender-" . $i), 'birthdate' => $birthdate, 'passport_num' => $request->get("passport-" . $i), 'passport_expirate' => $passport_expirate]);
         }
         $passenger->cartitem()->attach($cartItem);
     }
     return redirect('/cart');
 }
Example #14
0
 public function saveOptions($id, Request $request)
 {
     $product = \App\Product::find($id);
     $options = $request->get('options');
     $product->update(['options' => $options]);
     return $product->options;
 }
Example #15
0
 public function product($id)
 {
     // Product Detail
     $product = Product::find($id);
     $producer = Producer::find($product->producer);
     $producerItem = "<a href='" . URL::to('/') . "/producer/" . $producer->id . "/" . strtolower($producer->producer) . ".html'>" . $producer->producer . "</a>";
     // Category
     $productCategoryID = Product::find($id)->category_id;
     // breadcrumb
     $breadcrumb = $this->breadcrumb($productCategoryID, $id);
     // Best Seller
     $bestSeller = $this->bestSeller();
     $image = Images::where('productID', $product['id'])->first();
     $thumbnail = $image['imageSrc'];
     $thumbnailImage = '<a class="preView" rel="' . URL::to('/') . '/' . $thumbnail . '"><img src="' . URL::to('/') . '/' . $thumbnail . '" alt="" class="img-responsive"></a>';
     $images = Images::where('productID', $id)->get();
     $listImages = "";
     foreach ($images as $image) {
         $img = $image['imageSrc'];
         $listImages .= '<a href="' . URL::to('/') . '/' . $img . '" class="fancybox-button" rel="photos-lib"><img alt="Berry Lace Dress" src="' . URL::to('/') . '/' . $img . '"></a>';
     }
     $review = '<div class="fb-comments" data-href="' . URL::to('/') . '/product/' . $id . '"
             data-num-posts="10" data-width="700px"></div>';
     return view('home.product.detail')->with(['breadcrumb' => $breadcrumb, 'product' => $product, 'producer' => $producerItem, 'bestSeller' => $bestSeller, 'thumbnailImage' => $thumbnailImage, 'listImages' => $listImages, 'review' => $review]);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postAdd(Request $request, $product_id)
 {
     $deal = Deal::firstOrCreate(['user_id' => $request->user()->id, 'product_id' => $product_id]);
     $product = \App\Product::find($product_id);
     $request->session()->put("deals.{$product_id}", $product);
     return response()->json(['id' => $product_id, 'mobile' => trans('products.mobile', ['mobile' => $request->user()->mobile]), 'text' => trans_choice('products.deal', $product->deals_count)]);
 }
Example #17
0
 public function add(Request $request)
 {
     $user = \Session::get('user');
     if (!$user->can('产品参数管理')) {
         abort(401);
     }
     $param = new Param();
     $param->name = $request->input('name');
     $param->description = $request->input('description');
     $param->code = $request->input('code');
     $param->value = $request->input('value');
     $product = Product::find($request->input('product_id'));
     $param->product()->associate($product);
     $param->save();
     \Log::notice(strtr('产品参数增加: 用户 (%name[%id]) 增加了产品 (%product_name[%product_id] 参数(%param_name[%param_id]) : %value', ['%name' => $user->name, '%id' => $user->id, '%product_name' => $product->name, '%product_id' => $product->id, '%param_name' => $param->name, '%param_id' => $param->id, '%value' => $param->value]));
     //新增加的参数, 同步到所有的子产品中
     foreach ($product->sub_products as $sub) {
         //同步到所有的子产品中
         $sub->params()->save($param, ['value' => $param->value]);
         \Log::notice(strtr('子产品参数增加: 用户 (%name[%id]) 增加了子产品 (%product_name[%product_id] 参数(%param_name[%param_id]) : %value', ['%name' => $user->name, '%id' => $user->id, '%product_name' => $sub->name, '%product_id' => $sub->id, '%param_name' => $param->name, '%param_id' => $param->id, '%value' => $param->value]));
         //同步到所有的子产品签约的项目中
         foreach ($sub->projects as $project) {
             $project->params()->save($param, ['value' => $param->value]);
             \Log::notice(strtr('项目参数增加: 用户 (%name[%id]) 增加了项目 (%project_name[%project_id] 参数(%param_name[%param_id]) : %value', ['%name' => $user->name, '%id' => $user->id, '%project_name' => $project->name, '%project_id' => $project->id, '%param_name' => $param->name, '%param_id' => $param->id, '%value' => $param->value]));
         }
     }
     return redirect()->back()->with('message_content', '添加成功!')->with('message_type', 'info');
 }
Example #18
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $data = $request->all();
     $product = Product::find($data['product_id']);
     if (!$product) {
         return redirect()->back();
     }
     //exc.: no exist product
     if (!$product->price && !array_key_exists('size_id', $data)) {
         return redirect()->back();
     }
     //exc. no size selected
     if ($product->price && count($product->colors) && !array_key_exists('color_id', $data)) {
         return redirect()->back();
     }
     //exc. no color selected
     $options = ['discount' => 0, 'product' => $product];
     if (count($product->colors)) {
         $color = ProductColor::find($data['color_id']);
         if (!$color) {
             return redirect()->back();
         }
         //exc. no exist color echo 'error no exist color'; //
         $options['color'] = $color;
     }
     if (count($product->sizes)) {
         $size = ProductSize::find($data['size_id']);
         if (!$size) {
             return redirect()->back();
         }
         //exc. no exist size echo 'error no exist size'; //
         $options['size'] = $size;
         if (count($size->colors)) {
             if (!array_key_exists('color_id', $data)) {
                 return redirect()->back();
             }
             //exc. no color selected
             $color = ProductColor::find($data['color_id']);
             if (!$color) {
                 return redirect()->back();
             }
             //exc. no exist color echo 'error no exist color in size'; //
             $options['color'] = $color;
         }
     }
     if (isset($size)) {
         $options['size'] = $size;
     }
     if (isset($color)) {
         $options['color'] = $color;
     }
     if ($product->promoPrice() + 0) {
         $options['discount'] = $product->promo;
         $options['discount_type'] = $product->promo_type;
     }
     $price = $product->currentPrice(0);
     Cart::instance('shopping')->add($product->id, $product->name, array_key_exists('qty', $data) ? $data['qty'] : 1, $price, $options);
     return redirect()->back();
 }
Example #19
0
 public function show($id)
 {
     if ($product = Product::find($id)) {
         return view('shop.show')->with(compact('product'));
     } else {
         return view('errors.noProduct');
     }
 }
Example #20
0
 public function update(Request $request, $id)
 {
     $product = Product::find($id);
     $product->name = $request->name;
     $product->price = $request->price;
     $product->save();
     return redirect()->route('product.index');
 }
 public function addToCart($id)
 {
     $product = Product::find($id);
     Cart::add(['id' => $id, 'name' => $product->product_name, 'qty' => 1, 'price' => $product->price, 'options' => array('image' => $product->image1)]);
     $items = Cart::content();
     $total = Cart::total();
     return view('cart/mycart', compact('items', 'total'));
 }
Example #22
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function getIndex()
 {
     $product = Product::find(1);
     $comment = new Comment();
     $comment->body = 'Good Product';
     $product->comments()->save($comment);
     return;
 }
 /**
  * Display the specified resource.
  *
  * @param $id
  * @return Response
  * @internal param int $id
  */
 public function show($id)
 {
     $product = Product::find($id);
     if (!$product) {
         return $this->respondNotFound('Product does not exist');
     }
     return $this->respond(['data' => $this->productTransformer->transform($product)]);
 }
 public function likes($domain, $productId)
 {
     $product = Product::find($productId);
     $likes = $product->likes;
     return $this->respond(['likers' => $likes->map(function ($like) {
         return ['name' => $like->liker->name, 'username' => $like->liker->username, 'avatar_url' => $like->liker->avatar_url ? $like->liker->avatar_url : "http://d1j8r0kxyu9tj8.cloudfront.net/webs/user.png"];
     })]);
 }
Example #25
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $order = Order::where('id', $id)->with('user', 'products')->firstOrFail();
     foreach ($order->products as $product) {
         $productQt = Product::find($product->id)->join('order_product', 'products.id', '=', 'order_product.product_id')->where('order_product.order_id', '=', $id)->get();
     }
     return view('admin.order.details', compact('order', 'productQt'));
 }
 public function store(Request $request)
 {
     $token = Session('_token');
     $product_id = $request->get('product_id');
     $quantity = $request->get('quantity');
     $price = Product::find($product_id)->price;
     Cart::create(['product_id' => $product_id, 'quantity' => $quantity, '_token' => $token, 'price' => $price]);
     return redirect('cart')->with(['message' => 'Le produit a été ajouté dans votre panier']);
 }
 public function productInfo($id)
 {
     $product = Product::find($id);
     $user = User::find($product->FK_user);
     $related = Product::getRelated($id);
     $arBag = self::getBag();
     $arHeartbag = self::getHeartBag();
     return view('clothes.view')->withProduct($product)->withUser($user)->withBag($arBag)->withWishlist($arHeartbag)->withRelated($related);
 }
Example #28
0
 private function createTags()
 {
     $product = Product::select(['id', 'name'])->get();
     foreach ($product as $value) {
         $prod = Product::find($value->id);
         $prod->tags = str_replace(' ', ',', $value->name);
         $prod->save();
     }
 }
Example #29
0
 public function addToCart(Request $request)
 {
     $product_id = $request->get('product_id');
     $product = \App\Product::find($product_id);
     $product_options = $request->get('product_options');
     $options = $product->optionsArray($product_options);
     \Cart::add($product->id, $product->title, 1, $product->price, $options);
     return response()->json('success', 200);
 }
 public function show($id)
 {
     $product = Product::find($id);
     Auth::loginUsingId(1);
     // Auth::logout();
     $this->authorize('show-product', $product);
     // $this->authorize('update', $product);
     return view('product.show', compact('product'));
 }