/**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $product = Product::find($id);
     $product->delete();
     Session::flash('message', 'successfully deleted the product!');
     return Redirect::to('products');
 }
Example #2
0
 public function post_delete()
 {
     $product = Product::find(Input::get('id'));
     $product->categories()->delete();
     $product->delete();
     return Redirect::back()->with('flash', true)->with('flash_type', 'success')->with('flash_msg', 'Product deleted successfully.');
 }
 public function indexAction()
 {
     $this->view->products = Product::find();
     if ($this->session->get("auth")) {
         $this->view->user = User::findFirst($this->session->get("auth")['id']);
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function show($id)
 {
     // get the nerd
     $item = Product::find($id);
     // show the view and pass the nerd to it
     return View::make('product.show')->with('item', $item);
 }
Example #5
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     //
     $product = Product::find($id);
     $res = array();
     return Response::json($product);
 }
Example #6
0
 public static function getSearch($input = array())
 {
     $result = Product::where(function ($query) use($input) {
         if (!empty($input['category_id'])) {
             $query = $query->where('category_id', $input['category_id']);
         }
         if (!empty($input['type_id'])) {
             $query = $query->where('type_id', $input['type_id']);
         }
         if (!empty($input['price_id'])) {
             $query = $query->where('price_id', $input['price_id']);
         }
         if (!empty($input['time_id'])) {
             $inputDate = getTime($input['time_id']);
             $query = $query->where('start_time', '>=', $inputDate);
         }
         if (!empty($input['city_id'])) {
             $query = $query->where('city_id', $input['city_id']);
         }
         if (!empty($input['city'])) {
             $query = $query->where('city', $input['city']);
         }
         if (!empty($input['name'])) {
             $query = $query->where('name', 'like', '%' . $input['name'] . '%');
         }
         //lat long
         $query = $query->where('status', ACTIVE);
     })->select(listFieldProduct())->get();
     foreach ($result as $key => $value) {
         $value->avatar = url(PRODUCT_UPLOAD . '/' . $value->user_id . '/' . Product::find($value->id)->avatar);
         $value->block = Common::checkBlackList(Input::get('user_id'), $value->user_id);
     }
     return $result;
 }
 public function addCart($id)
 {
     $product = Product::find($id);
     $quantity = Input::get('qt');
     $name = $product->name;
     if (intval($quantity) > $product->stock) {
         return Redirect::to('product/' . $id)->with('message', 'La quantité du stock est insufisante pour votre commande');
     }
     if (Session::has('cart')) {
         $carts = Session::get('cart', []);
         foreach ($carts as &$item) {
             if ($item['name'] == $name) {
                 $item["quantity"] += intval($quantity);
                 Session::set('cart', $carts);
                 return Redirect::to('product/' . $id)->with('message', 'Votre panier a été mis à jour');
             }
         }
     }
     $new_item = array();
     $new_item['name'] = $name;
     $new_item['price'] = $product->price;
     $new_item['quantity'] = intval($quantity);
     $new_item['description'] = $product->description;
     $new_item['picture'] = $product->picture;
     Session::push('cart', $new_item);
     return Redirect::to('product/' . $id)->with('message', 'Le produit a été ajouté à votre panier');
 }
Example #8
0
 public function postAddtocart()
 {
     $product = Product::find(Input::get('id'));
     $quantity = Input::get('quantity');
     Cart::insert(array('id' => $product->id, 'name' => $product->title, 'price' => $product->price, 'quantity' => $quantity, 'image' => $product->image));
     return Redirect::to('store/cart');
 }
 public function showCart()
 {
     $session_items = $cart_items = [];
     if (Session::has('cart') && !empty(Session::get('cart'))) {
         $session_items = Session::get('cart');
         foreach ($session_items as $item) {
             $unserialized_item = unserialize($item);
             $product = Product::find($unserialized_item->productId);
             $cart_item = new StdClass();
             $cart_item->p_id = $product->id;
             $cart_item->name = $product->name;
             $cart_item->image = $product->image;
             $cart_item->price = $product->price;
             $cart_item->qtt = $unserialized_item->qtt;
             $cart_item->total = $cart_item->price * $cart_item->qtt;
             $counter = 0;
             $found = false;
             $index = null;
             foreach ($cart_items as $it) {
                 if ($it->p_id == $product->id) {
                     $index = $counter;
                     $found = true;
                 }
                 $counter++;
             }
             if ($found) {
                 $cart_items[$index]->qtt = $cart_items[$index]->qtt + $cart_item->qtt;
                 $cart_items[$index]->total = $cart_items[$index]->qtt * $cart_item->price;
             } else {
                 $cart_items[] = $cart_item;
             }
         }
     }
     return View::make('cart', compact('cart_items'));
 }
 /**
  * Find a model by its primary key.
  *
  * @param  mixed  $id
  * @param  array  $columns
  * @return \Illuminate\Support\Collection|static
  */
 public function find($id)
 {
     $model = Product::find($id);
     if ($model) {
         return $model;
     }
     throw new ResourceNotFoundException('Product was not found.');
 }
Example #11
0
 public function postAddtocart()
 {
     $product = Product::find(Input::get('id'));
     $quantity = Input::get('quantity');
     $member_id = Auth::user()->id;
     Cart::create(array('product_id' => $product->id, 'name' => $product->title, 'price' => $product->price, 'quantity' => $quantity, 'image' => $product->image, 'member_id' => $member_id));
     return Redirect::to('store/cart');
 }
Example #12
0
 public function show()
 {
     if (!isset($_GET['id'])) {
         return call('pages', 'error');
     }
     $product = Product::find($_GET['id']);
     require_once 'views/products/show.php';
 }
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 50) as $index) {
         $number = rand(1, 5);
         $product = Product::find($number);
         Record::create(["name" => $product->name, "action" => "trials", "status" => "comes_in", "authorization" => $faker->firstNameFemale, "amount" => 5 + $index * 5, "product_id" => $number]);
     }
 }
 public function indexAction()
 {
     // set title page
     Tag::setTitle("Home");
     $behandeling = Behandeling::find();
     $product = Product::find();
     $this->view->setVar('behandeling', $behandeling);
     $this->view->setVar('product', $product);
 }
Example #15
0
 /** @test */
 public function it_should_upload_single_media()
 {
     config()->set('medias.models', ['products' => ['model' => 'Product', 'fields' => ['cover']]]);
     $product = new Product();
     $product->id = 1;
     $product->uploadSingleMedia($this->getPicture(), 'cover');
     $product->save();
     $this->assertNotNull(Product::find(1)->cover);
 }
 public function getDelete($id)
 {
     $product = Product::find($id);
     if (is_object($product)) {
         File::delete('uploads/' . $product->photo);
         $product->delete();
     }
     return Redirect::to('admin/product')->with('message', 'Delete Completed');
 }
 public function update($id)
 {
     $product = Product::find($id);
     $product->name = Input::get('name');
     $product->description = Input::get('description');
     $product->price = Input::get('price');
     $product->save();
     return Redirect::to('/products');
 }
 public function storeReviewForProduct($productID, $comment, $rating)
 {
     $product = Product::find($productID);
     //$this->user_id = Auth::user()->id;
     $this->comment = $comment;
     $this->rating = $rating;
     $product->reviews()->save($this);
     // recalculate ratings for the specified product
     $product->recalculateRating($rating);
 }
 public function postToggleAvailability()
 {
     $product = Product::find(Input::get('id'));
     if ($product) {
         $product->availability = Input::get('availability');
         $product->save();
         return Redirect::to('admin/products/index')->with('notice', 'Product Updated');
     }
     return Redirect::to('admin/products/index')->with('notice', 'Invalid Product');
 }
 public function getView($id)
 {
     $product = Product::find($id);
     if ($product) {
         $random = Product::all()->random(4);
         return View::make('store.view')->with('product', $product)->with('random', $random);
     } else {
         return View::make('404');
     }
 }
 public function detailFavorite($userFavoriteId)
 {
     $input = Input::all();
     $sessionId = Common::checkSessionLogin($input);
     $listProducts = Product::where('user_id', $userFavoriteId)->get();
     foreach ($listProducts as $key => $value) {
         $value->avatar = url(PRODUCT_UPLOAD . '/' . $value->user_id . '/' . Product::find($value->id)->avatar);
     }
     return Common::returnData(200, SUCCESS, $input['user_id'], $sessionId, $listProducts);
 }
 public function postToggleAvailability()
 {
     $product = Product::find(Input::get('id'));
     if ($product) {
         $product->availability = Input::get('availability');
         $product->save();
         return Redirect::to('admin/products/index')->with('message', 'Produto actualizado');
     }
     return Redirect::to('admin/products/index')->with('message', 'Produto inválido');
 }
Example #23
0
 protected function actByProduct($method, $id)
 {
     if ($id = static::idFrom($id) and $model = Product::find($id) and $model->group) {
         $group = Group::find($model->group);
         if ($group and $group = $group->root()) {
             $this->layout = '.' . substr(strrchr($method, '_'), 1);
             return $this->{$method}($group);
         }
     }
 }
 public function postDelete()
 {
     $id = Input::get('id');
     $product = Product::find($id);
     if ($product) {
         $product->delete();
         return Redirect::to('/admin/products/')->with('message', 'Product Successfully Deleted.');
     }
     return Redirect::to('admin/products/')->with('message', 'Error Deleting This Product.Please Try again later.');
 }
 public function postToggleAvailability()
 {
     $product = Product::find(Input::get('id'));
     if ($product) {
         $product->availability = Input::get('availability');
         $product->save();
         return Redirect::to('admin/product/index')->with('message', '產品更新成功');
     }
     return Redirect::to('admin/product/index')->with('message', '產品更新失敗');
 }
Example #26
0
 /**
  * Return values of database with pagination
  *	
  * @return mixed
  */
 static function paginate_all($limit, $page)
 {
     $offset = $limit * ($page - 1);
     $result = Product::find('all', array('limit' => $limit, 'offset' => $offset));
     if ($result) {
         return $result;
     } else {
         return FALSE;
     }
 }
 public function postProduct()
 {
     $product = Request::json('product');
     $dbProduct = Product::find($product['id']);
     if ($dbProduct) {
         $dbProduct->set($product);
         $dbProduct->save();
     }
     return Response::json($dbProduct);
 }
 public function store()
 {
     $item = Input::get('item');
     if ($item != null) {
         $product = Product::find(Input::get('id'));
     } else {
         $product = new Product();
     }
     $product->updateFromInput();
     return Redirect::to('admin/control-panel');
 }
 public function edit($id)
 {
     if (!empty(Product::where('id', '=', $id)->first())) {
         // le produit existe
         $product = Product::find($id);
         $product->price = Input::get('price');
         $product->stock = Input::get('stock');
         $product->save();
     }
     return Redirect::to('/admin');
 }
 public function check($id)
 {
     $status = Product::find($id)->status;
     if ($status == ACTIVE) {
         $input = ['status' => INACTIVE, 'start_time' => Carbon\Carbon::now()];
     } else {
         $input = ['status' => ACTIVE, 'start_time' => Carbon\Carbon::now()];
     }
     CommonNormal::update($id, $input);
     return Redirect::action('ProductController@index');
 }