Ejemplo n.º 1
0
 /**
  * Get the storefront page that displays products
  *
  * If the user doesn't have a cart yet, create one
  *
  * @return \Illuminate\View\View
  */
 function getStorefront()
 {
     $cart_id = Session::get('carty.cart_id', false);
     $in_cart = array();
     if (!$cart_id) {
         $cart_id = $this->initCart();
     } else {
         $cart = Cart::find(Session::get('carty.cart_id'));
         if ($cart == null) {
             $cart_id = $this->initCart();
         }
     }
     $item_count = DB::table('cart_contents')->where('cart_id', '=', $cart_id)->sum('quantity');
     $products = DB::table('cart_contents')->select('product_id')->where('cart_id', '=', $cart_id)->get();
     foreach ($products as $p) {
         $in_cart[] = $p->product_id;
     }
     return View::make('carty::shop', array('title' => 'Shopping Demo', 'products' => Product::all(), 'item_count' => $item_count, 'in_cart' => $in_cart));
 }