コード例 #1
0
 public function checkout(Request $request)
 {
     $token = $request->input('stripeToken');
     //Retriieve cart information
     $cart = Cart::where('user_id', Auth::user()->id)->first();
     $items = $cart->cartItems;
     $total = 0;
     foreach ($items as $item) {
         $total += $item->product->price;
     }
     if (Auth::user()->charge($total * 100, ['source' => $token, 'receipt_email' => Auth::user()->email])) {
         $order = new Order();
         $order->total_paid = $total;
         $order->user_id = Auth::user()->id;
         $order->save();
         foreach ($items as $item) {
             $orderItem = new OrderItem();
             $orderItem->order_id = $order->id;
             $orderItem->product_id = $item->product->id;
             $orderItem->file_id = $item->product->file->id;
             $orderItem->save();
             CartItem::destroy($item->id);
         }
         return redirect('/order/' . $order->id);
     } else {
         return redirect('/cart');
     }
 }
コード例 #2
0
 public function removeItem($id)
 {
     // deletes an item in the user basket
     CartItem::destroy($id);
     DB::table('movies')->increment('quantity', 1);
     return redirect('/cart');
     // Add a code that readds the movie quantity for that specific item.
 }
コード例 #3
0
 public function removeItem($id)
 {
     CartItem::destroy($id);
     return redirect('/cart');
 }
コード例 #4
0
ファイル: CheckoutController.php プロジェクト: KingSloff/POS
 /**
  * Remove the specified resource from storage.
  *
  * @param  CartItem  $cartItem
  * @return \Illuminate\Http\Response
  */
 public function destroy(CartItem $cartItem)
 {
     $cartItem->delete();
     return redirect()->route('checkout.index');
 }
コード例 #5
0
ファイル: Product.php プロジェクト: zangee3/avs
 public function nbCartItem()
 {
     return CartItem::where("product_id", $this->id)->count();
 }