示例#1
1
 /**
  * @return \Illuminate\View\View
  */
 protected function renderCart()
 {
     $cartItems = Cart::content()->toArray();
     $cartTotal = Cart::total();
     $checkoutAction = 'editCart';
     return view('pages.partials.shopping.cart', compact('cartItems', 'cartTotal', 'checkoutAction'));
 }
 public function checkOut(Request $request)
 {
     $address = \StringHelper::filterString($request->input('address'));
     $name = \StringHelper::filterString($request->input('name'));
     $content = \StringHelper::filterString($request->input('comments'));
     $phone = \StringHelper::filterString($request->input('phone'));
     $count = Cart::count();
     if ($phone != "" && $name != "" && $content != "" && $count > 0) {
         $order = new Order();
         $order->order_name = $name;
         $order->status = 1;
         $order->active = 1;
         $order->order_comment = $content;
         $order->order_address = $address;
         $order->order_phone = $phone;
         $order->save();
         $cart = Cart::content();
         foreach ($cart as $item) {
             $order_detail = new OrderDetail();
             $order_detail->dish_id = $item->id;
             $order_detail->dish_number = $item->qty;
             $order_detail->order_id = $order->id;
             $order_detail->save();
         }
         Cart::destroy();
         return Redirect::to(url('menu'))->with('message', 'Order Success !. You can continue buy now !');
     } else {
         return Redirect::to(url('checkout'))->with('message', 'Order Fail !. Something Wrong !');
     }
 }
 /**
  * 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]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     return view('cart', ['products' => Cart::content(), 'discount' => Cart::discount(), 'coupons' => Cart::coupons()->toArray(), 'total' => Cart::total(), 'total_with_discount' => Cart::totalWithDiscount()]);
 }
 /**
  * Finaliza o pedido recebendo a mesa como parametro da requisicao
  * abre o pedido, salva, e salva os itens no pedido.
  * @param Request $request
  */
 public function finalizarCarrinho(Request $request)
 {
     $itens = Cart::content();
     $pedido = new Pedido();
     $pedido->mesa = $request->mesa;
     $pedido->total = Cart::total();
     if (Cart::count() != 0) {
         $pedido->save();
     } else {
         Flash::success("Por favor, adicione algum item no pedido!");
     }
     Log::info($pedido);
     //por enquanto vai ser assim, mas pense numa maneira melhor
     //de retornar o pedido criado.
     $pedidoAtual = Pedido::orderBy('id', 'desc')->first();
     $itensPedidos = array();
     foreach ($itens as $iten) {
         $itemPedido = new ItemPedido();
         $itemPedido->nome = $iten->name;
         $itemPedido->preco = $iten->price;
         $itemPedido->quantidade = $iten->qty;
         $itensPedidos[] = $itemPedido;
     }
     if (Cart::count() != 0) {
         $pedidoAtual->itens()->saveMany($itensPedidos);
         $pedidoAtual->save();
         Cart::destroy();
         Flash::success("Pedido finalizado!");
     } else {
         Flash::error("Por favor, adicione algum item no pedido!");
     }
     return redirect()->back();
 }
 public function index(Guard $auth, PedidoProduto $pedidoProduto)
 {
     if (\Auth::check()) {
         $idPagseguro = substr(md5(uniqid()), 0, 15);
         $dados = $auth->user();
         $produtosNoCarrinho = Cart::content();
         foreach ($produtosNoCarrinho as $produtoNoCarrinho) {
             $attributes = ['tb_pedidos_produto_cliente' => $dados->id, 'tb_pedidos_produto_id_pagseguro' => $idPagseguro, 'tb_pedidos_produto_quantidade' => $produtoNoCarrinho->qty, 'tb_pedidos_produto_subtotal' => $produtoNoCarrinho->subtotal, 'tb_pedidos_produto_id' => $produtoNoCarrinho->id, 'tb_pedidos_produto_data' => date('Y-m-d H:i:s')];
             $pedidoProduto->create($attributes);
         }
         $pagseguro = new Pagseguro($dados);
         $dadosPedidoPagseguro = ['id' => $idPagseguro, 'produto' => 'Vendas da Loja', 'preco' => Cart::total()];
         $pagseguro->setNome($dados->name);
         $pagseguro->setSobrenome('');
         $pagseguro->setEmail($dados->email);
         $pagseguro->setDdd('');
         $pagseguro->setTelefone('');
         $pagseguro->setIdReference($idPagseguro);
         $pagseguro->setItemAdd($dadosPedidoPagseguro);
         try {
             $url = $pagseguro->enviarPagseguro();
             echo $url;
         } catch (\Exception $e) {
             echo $e->getMessage();
         }
     } else {
         return 'logado';
     }
 }
示例#7
0
 public function doLogout()
 {
     session(['user' => null]);
     foreach (Cart::content() as $row) {
         session([$row->id => null]);
     }
     Cart::destroy();
     return redirect('/');
 }
 /**
  * Remove all items from the cart
  */
 public function testClear()
 {
     $this->call('GET', '/cart/add/1');
     $this->call('GET', '/cart/add/2');
     $this->assertEquals(2, count(Cart::content()));
     $this->call('GET', '/cart/clear');
     $this->assertRedirectedToRoute('cart.index');
     $this->assertEquals(0, count(Cart::content()));
 }
示例#9
0
 /**
  * Prepare order and customer data for database.
  * @param Request $request
  */
 public function createOrder($request)
 {
     $cart = Cart::content();
     $customer = $request->session()->all();
     $customer['user_id'] = Auth::user()->id;
     $this->customer->create($customer);
     foreach ($cart as $item) {
         $this->order->create(['user_id' => Auth::user()->id, 'order_date' => Carbon::now(), 'product_id' => $item->id, 'quantity' => $item->qty, 'amount' => $item->subtotal, 'size' => $item->options->size, 'img' => $item->options->img, 'color' => $item->options->color]);
     }
 }
 public function success(Buckaroo $buckaroo, Request $request)
 {
     $order = Order::find($buckaroo->invoice_nr(Request::all()));
     $order->payed = 1;
     $order->saveitems(Cart::content());
     $order->save();
     $event = Event::fire(new ItemsPurchasedEvent($order, Cart::content()));
     Session::forget('order');
     Cart::destroy();
     return view("shoppingcart.payment-success");
 }
示例#11
0
 private function saveOrderItems()
 {
     foreach (Cart::content() as $key => $orderItem) {
         $this->orderItems[$key]['product_id'] = $orderItem->id;
         $this->orderItems[$key]['product'] = $orderItem->name;
         $this->orderItems[$key]['quantity'] = $orderItem->qty;
         $this->orderItems[$key]['price'] = $orderItem->price;
         $this->orderItems[$key]['subtotal'] = $orderItem->subtotal;
     }
     if (!empty($this->orderItems)) {
         foreach ($this->orderItems as $orderItem) {
             $this->order->orderItems()->create($orderItem);
         }
     }
 }
 public function __construct()
 {
     View::share('pros', Product::take(8)->Where('status', 1)->orderBy('created_at', 'DESC')->get());
     View::share('customs', Product::take(8)->Where('type', 0)->orderBy('created_at', 'DESC')->get());
     View::share('products', Product::take(8)->Where('status', 1)->orderBy('created_at', 'DESC')->get());
     View::share('cus', Product::take(8)->Where('status', 1)->orderBy('created_at', 'ASC')->get());
     View::share('categories', Category::all());
     View::share('cart_content', Cart::content());
     View::share('count', Cart::count());
     View::share('total', Cart::total());
     View::share('set', Setting::find(1));
     View::share('tos', Cart::tos());
     View::share('transactions', Transaction::orderBy('created_at', 'desc')->paginate(10));
     View::share('settings', Setting::find(1));
     View::share('caty', Category::take(5)->orderBy('created_at', 'DESC')->get());
     View::share('payments', Payment::Where('status', 1)->get());
     View::share('customers', Customer::all());
     View::share('orders', Order::all());
     View::share('cat', Category::all());
     View::share('db', Product::take(6)->Where('status', 1)->orderBy('created_at', 'ASC')->get());
 }
示例#13
0
 public function doCheckout()
 {
     if (session('user') != null) {
         $user = session('user');
         foreach (Cart::content() as $row) {
             $book = \App\Books::find($row->id);
             $book->available = 0;
             $sales = new \App\SalesOrder();
             $sales->bookid = $book->bookid;
             $sales->buyerid = $user->userid;
             $sales->orderdate = Carbon::now();
             $sales->save();
             session([$book->bookid => null]);
             $book->save();
             Cart::remove($row->rowid);
         }
         \Session::flash('message', 'Your order has been placed successfully!');
         \Session::flash('type', 'success');
         return redirect('/cart');
     } else {
         return redirect('/login');
     }
 }
示例#14
0
 public function content()
 {
     return Cart::content();
 }
 /**
  *
  */
 public function ExecutePayment()
 {
     if (isset($_GET['success']) && $_GET['success'] == 'true') {
         // Get the payment Object by passing paymentId
         // payment id was previously stored in session in
         // CreatePaymentUsingPayPal.php
         $log = PayPalLog::find(Session::get('log_id'));
         $paymentId = $log->payment_id;
         //$payment = Paypalpayment::get($paymentId, $this->_apiContext);
         $payment = Payment::get($paymentId, $this->_apiContext);
         // PaymentExecution object includes information necessary
         // to execute a PayPal account payment.
         // The payer_id is added to the request query parameters
         // when the user is redirected from paypal back to your site
         $execution = Paypalpayment::PaymentExecution();
         $execution->setPayerId($_GET['PayerID']);
         //Execute the payment
         try {
             $order = $payment->execute($execution, $this->_apiContext)->toArray();
         } catch (\PPConnectionException $ex) {
             return "Exception: " . $ex->getMessage() . PHP_EOL;
             var_dump($ex->getData());
             exit(1);
         }
         $payer = $order['payer']['payer_info'];
         $log->state = $order['state'];
         $log->viewed = false;
         $log->paypal_id = $order['id'];
         $log->payer_email = $payer['email'];
         $log->payer_id = $payer['payer_id'];
         $log->payer_first_name = $payer['first_name'];
         $log->payer_last_name = $payer['last_name'];
         $log->shipping_address = json_encode($payer['shipping_address']);
         //note: you'll have to do foreach if you want multiple -v
         $log->item_list = json_encode($order['transactions'][0]);
         $log->total = $order['transactions'][0]['amount']['total'];
         $log->save();
         $cart = Cart::content();
         Cart::destroy();
         Flash::success('Payment Sucsess!');
         return view('cart.paypalReturn')->with('title', 'Payment Sucsess!')->with('address', $payer['shipping_address'])->with('cart', $cart)->with('log', $log);
     } else {
         echo "User cancelled payment.";
     }
     // Flash::success('Payment Sucsess!');
     // return redirect()->action('BooksController@show', [Session::get('bookId')]);
 }
 /**
  * Display Check Out Landing Page
  *
  * @return Response
  */
 public function index()
 {
     $cartItems = Cart::content()->toArray();
     $cartTotal = Cart::total();
     return view('checkout.index', compact('cartItems', 'cartTotal'));
 }
 public function postCheckout()
 {
     $tos = Cart::tos();
     $total = Cart::total();
     $input = array('order_date' => date('Y-m-d H:i:s'), 'total_tax' => $tos, 'total_purchase' => $total, 'order_status' => 'pending', 'name' => Input::get('name'), 'email' => Input::get('email'), 'no_tel' => Input::get('no_tel'), 'address' => Input::get('address'), 'city' => Input::get('city'), 'poskod' => Input::get('poskod'), 'state' => Input::get('state'));
     $order = Order::create($input);
     $formid = str_random();
     $cart_content = Cart::content();
     foreach ($cart_content as $cart) {
         $transaction = new Transaction();
         $transaction->product_id = $cart->id;
         $transaction->form_id = $formid;
         $transaction->qty = $cart->qty;
         $transaction->total_price = $cart->subtotal;
         $transaction->order_id = $order->id;
         $transaction->gambar_id = $cart->options->img_id;
         $transaction->color = $cart->options->color;
         $transaction->size = $cart->options->size;
         $transaction->category_id = $cart->options->cat;
         $transaction->save();
     }
     $ttr = Transaction::where('order_id', '=', $order->id);
     Cart::destroy();
     Session::forget('values');
     return redirect('store/thankyou/');
 }
示例#18
0
 public function order()
 {
     //get Session option
     $option = Session::get('option');
     //get Cart
     $cart = Cart::content();
     //get type order
     $type = $option['type'];
     //payment method
     $payMethod = Session::get('pay_med');
     if ($option['type'] == 'logged') {
         $order = new Order();
         DB::beginTransaction();
         try {
             $idUser = array_get(session('user'), 'id');
             $order->user_id = $idUser;
             $order->delivery_detail_id = 0;
             $order->comment = $payMethod['comment'];
             $order->save();
             $idOrder = Order::where('user_id', $idUser)->orderBy('id', 'desc')->first()->id;
             //add order detail and sub amount of product
             foreach ($cart as $item) {
                 $root_price = Cd::find($item['id'])->root_price;
                 $modelOrderDetail = new OrderDetail();
                 $modelOrderDetail->order_id = $idOrder;
                 $modelOrderDetail->product_id = $item['id'];
                 $modelOrderDetail->quantity = $item['qty'];
                 $modelOrderDetail->root_price = $root_price;
                 $modelOrderDetail->price = $item->price;
                 $modelOrderDetail->save();
                 //sub qty product
                 $cd = Cd::find($item['id']);
                 if ($cd->quantity - $item['qty'] <= 0) {
                     throw new QtyCDException();
                 }
                 $cd->quantity = $cd->quantity - $item['qty'];
                 $cd->buy_time = $cd->buy_time + $item['qty'];
                 $cd->save();
             }
             DB::commit();
             $this->clear();
             return redirect_success('FrontendController@index', 'Ordered, Check your email to check detail');
         } catch (QtyCDException $e) {
             DB::rollback();
             return redirect_errors($e->notify());
         } catch (\Exception $e) {
             DB::rollback();
             return redirect_errors("Sorry cannot to this deal!");
         }
     } else {
         $deliveryDetail = Session::get('shi_add');
         $order = new Order();
         $modelDeliverDetail = new DeliveryDetail();
         $modelDeliverDetail = autoAssignDataToProperty($modelDeliverDetail, $deliveryDetail);
         //            dd($modelDeliverDetail);
         DB::beginTransaction();
         try {
             $orderHuman = $modelDeliverDetail;
             $modelDeliverDetail->save();
             $newDeliverDetail = new DeliveryDetail();
             $delivery = $newDeliverDetail->getDeliveryDetail($deliveryDetail);
             $order->user_id = 0;
             $order->delivery_detail_id = $delivery->id;
             $order->comment = $payMethod['comment'];
             $order->save();
             $idOrder = Order::where('delivery_detail_id', $delivery->id)->first()->id;
             //add order detail and sub amount of product
             foreach ($cart as $item) {
                 $modelOrderDetail = new OrderDetail();
                 $modelOrderDetail->order_id = $idOrder;
                 $modelOrderDetail->product_id = $item['id'];
                 $modelOrderDetail->quantity = $item['qty'];
                 $modelOrderDetail->price = $item['price'];
                 $modelOrderDetail->save();
                 //
                 $cd = Cd::find($item['id']);
                 if ($cd->quantity - $item['qty'] <= 0) {
                     throw new QtyCDException();
                 } else {
                     $cd->quantity = $cd->quantity - $item['qty'];
                 }
             }
             DB::commit();
             $this->clear();
             //send
             //                Mail::send('auth.mail_welcome', ['last_name' => $orderHuman->lastname, 'key' => $key_active, 'password' => $pass], function ($message) use ($data) {
             //                    $message
             //                        ->to($data['email'], $data['name'])
             //                        ->from('*****@*****.**')
             //                        ->subject('Thank you for your buying!');
             //                });
             return redirect_success('FrontendController@index', 'Ordered, Check your email to check detail');
         } catch (QtyCDException $e) {
             DB::rollback();
             return redirect_errors($e->notify());
         } catch (\Exception $e) {
             DB::rollback();
             return redirect_errors("Sorry cannot to this deal!");
         }
     }
 }
示例#19
-1
 /**
  * Handle the event.
  *
  * @param  OrderWasPlaced $event
  * @return void
  */
 public function handle(OrderWasPlaced $event)
 {
     $amount = $event->amount;
     $country = $event->order['country'];
     $vatRate = 25;
     $billing_id = $event->billing_id;
     $customerName = $event->order['first_name'] . ' ' . $event->order['last_name'];
     $customerAddress = $event->order['street'];
     $customerCity = $event->order['city'];
     $customerZip = $event->order['zip'];
     $customerEmail = $event->order['email'];
     $customerPhone = $event->order['phone'];
     $sendSms = $event->order['sendSms'];
     $checkUser = Auth::check() ? Auth::user()->id : 1;
     $products = Cart::content();
     // Specific for saving an invoice
     $date = Carbon::now()->format('Y-m-d');
     $lines = [];
     foreach ($products as $product) {
         $lines[] = ['productId' => $product->options->billys_product_id, 'unitPrice' => $product->price / 100];
     }
     $billy = new BillysBilling(env('BILLYS_KEY'));
     $billyContact = $billy->makeBillyRequest('POST', '/contacts', ['contact' => ['type' => 'person', 'organizationId' => env('BILLY_ORGANIZATION'), 'name' => $customerName, 'countryId' => $country, 'street' => $customerAddress, 'cityText' => $customerCity, 'zipcodeText' => $customerZip, 'phone' => $customerPhone, 'isCustomer' => true]]);
     $billyContactId = $billyContact->body->contacts[0]->id;
     $order = Order::create(['amount' => $amount, 'vat_rate' => $vatRate, 'stripe_billing_id' => $billing_id, 'customer_name' => $customerName, 'customer_address' => $customerAddress, 'customer_city' => $customerCity, 'customer_country' => $country, 'customer_zip' => $customerZip, 'customer_email' => $customerEmail, 'customer_phone_number' => $customerPhone, 'sendSms' => $sendSms, 'user_id' => $checkUser, 'billys_contact_id' => $billyContactId]);
     $billyInvoice = $billy->makeBillyRequest('POST', '/invoices', ['invoice' => ['organizationId' => env('BILLY_ORGANIZATION'), 'contactId' => $billyContactId, 'entryDate' => $date, 'paymentTermsDays' => 5, 'state' => 'approved', 'sentState' => 'unsent', 'invoiceNo' => $order->id, 'currencyId' => 'DKK', 'lines' => $lines]]);
     $order->billys_invoice_id = $billyInvoice->body->invoices[0]->id;
     $order->save();
 }