public function index()
 {
     //
     $prod = new Product();
     $products = $prod->paginate(15);
     return view('products', compact('products'));
 }
 public function index(\CodeCommerce\Category $category, \CodeCommerce\Product $product)
 {
     $categories = $category->all();
     $pFeatureds = $product->featured()->limit(3)->get();
     $pRecommends = $product->recommend()->limit(3)->get();
     return view('store.index', compact('categories', 'pFeatureds', 'pRecommends'));
 }
Ejemplo n.º 3
0
 public function productDetail(Category $category, Product $products, $id)
 {
     $categories = $category->all();
     $product = $products->find($id);
     $tags = $this->tag->all();
     //  dd($product->tags);
     return view('store.productDetail', compact('categories', 'product', 'tags'));
 }
Ejemplo n.º 4
0
 public function add($id, Product $prod)
 {
     $cart = $this->getCart();
     $product = $prod->find($id);
     $cart->add($id, $product->name, $product->price);
     Session::set('cart', $cart);
     return redirect()->route('cart');
 }
 /**
  * consultar produto
  * @param $id id do produto
  */
 public function product($id)
 {
     $categories = Category::all();
     $product = Product::find($id);
     $tags = $product->tags;
     return view('store.product', compact('categories', 'product', 'tags'));
 }
 public function show($id = null)
 {
     $products = !is_null($id) ? Product::where('id', $id)->get() : Product::all();
     foreach ($products as $product) {
         echo $product->name . ': $' . $product->price . '<br>';
     }
 }
 /**
  * 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');
 }
Ejemplo n.º 8
0
 /**
  * Add product to Cart.
  * @param $id
  * @return \Illuminate\Http\RedirectResponse
  */
 public function add($id)
 {
     $cart = $this->getCart();
     $product = Product::find($id);
     $cart->add($id, $product->name, $product->price);
     return redirect()->route('cart');
 }
 public function category($id)
 {
     $categories = Category::all();
     $category = Category::find($id);
     $products = Product::ofCategory($id)->get();
     return view('store.category', compact('categories', 'products', 'category'));
 }
 public function index()
 {
     $categories = Category::all();
     $pFeatured = Product::featured()->get();
     $pRecommend = Product::recommend()->get();
     return view('store.index', compact('categories', 'pFeatured', 'pRecommend'));
 }
Ejemplo n.º 11
0
 public function tag($name)
 {
     $tagName = $name;
     $categories = Category::Available()->get();
     $products = Product::select(['products.id as id', 'products.name as name', 'products.description as description', 'products.price as price'])->ByTagName($name)->get();
     return view('store.tag', compact('categories', 'products', 'tagName'));
 }
 public function remove($id)
 {
     $product = Product::find($id);
     $cart = $this->getCart();
     $cart->remove($product->id);
     Session::set('cart', $cart);
     return redirect()->route('cart');
 }
Ejemplo n.º 13
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('products')->truncate();
     $faker = Faker::create('pt_BR');
     foreach (range(1, 50) as $i) {
         Product::create(['name' => $faker->name(), 'description' => $faker->sentence(), 'price' => $faker->randomNumber(2), 'category_id' => $faker->numberBetween(1, 15)]);
     }
 }
 public function run()
 {
     DB::table('products')->truncate();
     $faker = Faker::create();
     foreach (range(1, 15) as $i) {
         Product::create(['name' => $faker->word(), 'description' => $faker->sentence(), 'price' => $faker->numberBetween($min = 1000, $max = 9000), 'featured' => $faker->numberBetween($min = 0, $max = 1), 'recommend' => $faker->numberBetween($min = 0, $max = 1)]);
     }
 }
 public function run()
 {
     DB::table('products')->truncate();
     $faker = Faker::create();
     foreach (range(1, 10) as $i) {
         Product::create(['name' => $faker->name, 'description' => $faker->text, 'price' => $faker->randomFloat(), 'featured' => $faker->boolean(), 'recommend' => $faker->boolean()]);
     }
 }
 public function run()
 {
     DB::table('products')->truncate();
     $faker = Faker::create();
     foreach (range(1, 40) as $i) {
         Product::create(['name' => $faker->word(), 'description' => $faker->sentence(), 'price' => $faker->randomNumber(2), 'category_id' => $faker->numberBetween(1, 15), 'featured' => $faker->boolean(), 'recommend' => $faker->boolean()]);
     }
 }
 public function add($id)
 {
     $cart = $this->getCart();
     $product = Product::find($id);
     $cart->add($product);
     Session::set('cart', $cart);
     return redirect()->route('store.cart');
 }
Ejemplo n.º 18
0
 public function add($id)
 {
     $cart = $this->getCart();
     $product = Product::find($id);
     $image = $product->images->first() ? 'uploads' . '/' . $product->images->first()->id . '.' . $product->images->first()->extension : 'images/no-img.jpg';
     $cart->add($id, $product->name, $product->price, $image);
     Session::set('cart', $cart);
     return redirect()->route('store.cart');
 }
 public function destroy($id)
 {
     $model = Product::find($id);
     foreach ($model->images()->getResults() as $image) {
         $this->destroyImage($image, $image->id);
     }
     $model->delete();
     return redirect()->route('products');
 }
 public function productCategory($id)
 {
     $pCategory = Product::ProductCategory($id)->get();
     $category = $this->category->find($id);
     $categories = Category::all();
     if ($category) {
         return view('store.category', compact('categories', 'products', 'pCategory'));
     }
     return redirect()->route('store.index')->with('category_exist', 'Category not exist!');
 }
Ejemplo n.º 21
0
 public function product($id)
 {
     $product = Product::find($id);
     if ($product) {
         $categories = Category::all();
         return view('store.details', compact('categories', 'product'));
     } else {
         return redirect()->route('store.index');
     }
 }
Ejemplo n.º 22
0
 public function add($id)
 {
     $cart = $this->getCart();
     //Adiciona os atributo no carrinho
     $product = Product::find($id);
     $cart->add($id, $product->name, $product->price);
     //Altera a sessão passando o Carrinho
     Session::set('cart', $cart);
     return redirect()->route('cart');
 }
 public function index()
 {
     $products = Product::all();
     echo '<h1>Listagem de produtos</h1>';
     echo '<br/><ul>';
     foreach ($products as $row) {
         echo '<li>' . $row->name . '</li>';
     }
     echo '</ul>';
 }
Ejemplo n.º 24
0
    public function removeItem($id)
    {
        $cart = $this->getCart();

        $product = Product::find($id);

        $cart->removeItem($id, $product->name, $product->price);

        Session::set('cart', $cart);

        return redirect()->route('store.cart');
    }
Ejemplo n.º 25
0
 public function update($id, $quantity, Request $request)
 {
     if ($request->ajax()) {
         $cart = $this->getCart();
         if ($cart->setQuantity($id, $quantity)) {
             Session::set('cart', $cart);
             $product = Product::find($id);
             return ['success' => true, 'price' => number_format($product->price * $quantity, 2, ',', '.'), 'total' => number_format($cart->getTotal(), 2, ',', '.')];
         }
         return ['success' => false];
     }
 }
Ejemplo n.º 26
0
 public function update(\CodeCommerce\Http\Requests\CartRequest $request, $id, Session $session)
 {
     $data = $request->all();
     $cart = $this->getCart($session);
     $product = Product::find($id);
     $cart->update($id, $product->name, $product->price, $data['qtd']);
     if ($data['qtd'] == 0) {
         $cart->remove($id);
     }
     $session::set('cart', $cart);
     return redirect()->route('cart');
 }
Ejemplo n.º 27
0
 public function updateItem(Requests\CartRequest $cartRequest)
 {
     $input = $cartRequest->all();
     $id = $input['id'];
     $quantity = $input['quantity'];
     $cart = $this->getCart();
     $product = Product::find($id);
     $cart->addMoreThanOneQuantity($id, $product->name, $product->price, $quantity);
     Session::set('cart', $cart);
     $subTotal = $product->price * $cart->all()[$id]['qtd'];
     $items = $cart->all();
     return response()->json(['subTotal' => $subTotal, 'total' => $cart->getTotal(), 'qtd' => $items[$id]['qtd']]);
 }
Ejemplo n.º 28
0
 private function syncTags($tagList, $id)
 {
     $syncTag = [];
     $tags = explode(',', str_replace(';', ',', $tagList));
     $tags = array_filter($tags);
     $tags = array_map('trim', $tags);
     $tags = array_map('strip_tags', $tags);
     $tags = array_map('strtolower', $tags);
     foreach ($tags as $tag) {
         $syncTag[] = $this->tag->firstOrCreate(['name' => $tag])->id;
     }
     $product = $this->product->find($id);
     $product->tags()->sync($syncTag);
 }
 public function add($id)
 {
     $cart = $this->getCart();
     $product = Product::find($id);
     $img = $product->firstImageName();
     if ($img) {
         //caminho da imagem
         $imgPath = url('uploads/' . $img);
     } else {
         $imgPath = url('build/images/no-img.jpg');
     }
     $cart->add($product->id, $product->name, $product->price, $imgPath);
     Session::set('cart', $cart);
     return redirect()->route('store.cart');
 }
Ejemplo n.º 30
0
 /**
  * Add Items to Cart.
  *
  * @param $id
  * @return \Illuminate\Http\Response
  */
 public function add(Request $request, $id)
 {
     // trago o metodo
     $cart = $this->getCart();
     // Importo e pego o meu produto
     $product = Product::find($id);
     // pego a cor
     $color = $request->get('color');
     // verifico se a cor é formato HEX
     if (preg_match('/^#[a-f0-9]{6}$/i', $color)) {
         // adiciono o produto ao carrinho
         $cart->add($id, $product->name, $product->price, $color);
         // adiciono o carrinho alterado/final a minha sessão
         Session::set('cart', $cart);
     } else {
         return redirect()->route('store.product', ['id' => $id])->withError('Por favor, selecione uma Cor para o produto!');
     }
     return redirect()->route('cart');
 }