/** * Remove all items from the cart * * @return Response */ public function index(Request $request) { $post = $request->all(); $errors = []; if ($request->method() == 'POST') { $validator = Validator::make($request->all(), ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required', 'street_name' => 'required', 'city' => 'required', 'country' => 'required', 'zipcode' => 'required']); // If everything is ok if (count($validator->errors()->all()) == 0) { Order::addOrder($post, Cart::total(), Cart::discount(), Cart::content()); Cart::clearCoupons(); Cart::destroy(); return redirect()->route('checkout.order'); } $errors = $validator->errors()->all(); } return view('checkout.index', ['products' => Cart::content(), 'total' => Cart::total(), 'discount' => Cart::discount(), 'total_with_discount' => Cart::totalWithDiscount(), 'post' => $post, 'errors' => $errors]); }
/** * Removes all the coupons from the cart */ public function testClearItems() { Cart::addCoupon('TEST20', 5.5); Cart::addCoupon('TEST10', 5.5); Cart::addCoupon('TEST40', 5.5); Cart::addCoupon('TEST50', 7.5); $this->assertEquals(4, count(Cart::coupons()->all())); Cart::clearCoupons(); $this->assertEquals(0, count(Cart::coupons()->all())); }