Exemplo n.º 1
0
 public function proceedCheckOut(Request $request)
 {
     $user = Auth::user();
     $validator = Validator::make($request->all(), ['billing_address' => 'integer|exists:addresses,id', 'shipping_address' => 'required|integer|exists:addresses,id']);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator);
     } else {
         $wishedProducts = $user->userable->wishedProducts;
         if (count($wishedProducts) > 0) {
             foreach ($wishedProducts as $wishedProduct) {
                 if (CheckOut::create(['product_id' => $wishedProduct->product->id, 'customer_id' => $user->id, 'description' => $wishedProduct->product->description, 'customer_email' => $user->email, 'product_title' => $wishedProduct->product->title, 'product_price' => $wishedProduct->product->price, 'payment_id' => null, 'image' => $wishedProduct->product->image, 'current_unit' => $wishedProduct->product->currency_unit_id, 'supplier_id' => $wishedProduct->product->supplier_id, 'count' => $wishedProduct->count, 'receiver_address_id' => $request->input('shipping_address'), 'bill_address_id' => $request->has('billing_address') ? $request->input('billing_address') : null])) {
                     $wishedProduct->delete();
                 }
             }
             return redirect()->action('Dashboard\\CustomerController@showUnpaidOrders');
         } else {
             return redirect()->back()->withErrors(['messages' => ['Lütfen sepetinize ürün ekleyiniz']]);
         }
     }
 }