コード例 #1
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function order()
 {
     $data = Input::all();
     $pay = Pay_method::where('pseudo_name', $data['payment'])->firstOrFail();
     $delivery = Delivery::where('pseudo_name', $data['delivery'])->firstOrFail();
     $order = new Order();
     $order->name = $data['name'];
     $order->telephone = $data['phone'];
     $order->adress = $data['address'];
     $order->email = $data['email'];
     $order->payment_method_id = $pay->id;
     $order->delivery_id = $delivery->id;
     $order->comment = $data['info'];
     $order->status = 'new';
     $order->total_cost = $data['sum'];
     $order->save();
     foreach ($data['cart'] as $name => $value) {
         $prod = Product::where('pseudo_name', $name)->firstOrFail();
         $ord_prod = new OrderProduct();
         $ord_prod->product_id = $prod->id;
         $ord_prod->count = $value;
         $ord_prod->order_id = $order->id;
         $ord_prod->save();
     }
     Mail::send('emails.order_success', ['data' => $data], function ($message) {
         $message->setEncoder(Swift_Encoding::get8BitEncoding());
         $message->to('*****@*****.**', 'John Smith')->subject('New order!');
     });
     return 1;
 }
コード例 #2
0
 public function address(Request $request)
 {
     //dd($request);
     $order = new Orders();
     $order->sity = $request->sity;
     $order->province = $request->province;
     $order->postcode = $request->postcode;
     $order->street1 = $request->street1;
     $order->street2 = $request->street2;
     $order->firstname = $request->firstname;
     $order->lastname = $request->lastname;
     $order->phone = $request->phone;
     $order->email = $request->email;
     $order->shipping_method = $request->shipping_method;
     $order->payment = $request->payment;
     $order->total_price = $request->total_order;
     //        dd($request->product);
     $order->save();
     $order_id = $order->id;
     $product_id = $request->product;
     foreach ($product_id as $id) {
         $orderproduct = new OrderProduct();
         $orderproduct->orders_id = $order_id;
         $orderproduct->product_id = $id;
         $orderproduct->save();
     }
     $request->session()->forget('cart');
     return redirect()->route('home');
 }
コード例 #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, SaleOrder::$rules);
     $serial = str_pad(SaleOrder::count(), 6, '0', STR_PAD_LEFT);
     $data = array_merge($request->all(), array('fecha_emision' => date('Y-m-d'), 'nro_orden' => $serial, 'enterprise_id' => Auth::user()->enterprise[0]->id));
     $order = SaleOrder::create($data);
     foreach ($request->input('products') as $p) {
         $producto = new OrderProduct();
         $producto->nombre = $p['nombre'];
         $producto->cantidad = $p['cantidad'];
         $producto->monto = $p['monto'];
         $producto->total = $p['total'];
         $producto->sale_order_id = $order->id;
         $producto->save();
     }
     //echo "<pre>"; print_r($request->all()); echo "</pre>";
     return redirect()->route('sale-point.orden-venta.create')->with('message', '<div class="alert alert-success" style="margin-top:15px">Orden creada con Éxito</div>');
 }
コード例 #4
0
 public function index()
 {
     $new_products = Product::orderBy('created_at', 'desc')->take(12)->get();
     $get_best_sellers = App\OrderProduct::select('product_id', \DB::raw('COUNT(product_id) as count'))->groupBy('product_id')->orderBy('count', 'desc')->take(8)->get();
     $best_sellers = [];
     foreach ($get_best_sellers as $product) {
         $best_sellers[] = $product->product;
     }
     helperFunctions::getPageInfo($sections, $cart, $total);
     return view('site.index', compact('new_products', 'best_sellers', 'sections', 'cart', 'total'));
 }
コード例 #5
0
 public function run()
 {
     $faker = Factory::create();
     $orders = Order::lists('id');
     $products = Product::sell()->lists('id');
     foreach (range(1, 45) as $index) {
         if ($index > 29) {
             $index -= 29;
         }
         OrderProduct::create(['order_id' => $orders[$index], 'product_id' => $faker->randomElement($products), 'quantity' => $faker->numberBetween(1, 3)]);
     }
 }
コード例 #6
0
 public function show($id)
 {
     $orderDetails = OrderProduct::where('order_id', $id)->get();
     $order = Order::find($id);
     $options = new Collection();
     foreach ($orderDetails as $detail) {
         if ($detail->options) {
             $values = explode(',', $detail->options);
             foreach ($values as $value) {
                 $options->add(OptionValue::find($value));
             }
         }
     }
     return view('site.showOrder', compact('orderDetails', 'order', 'options'));
 }
コード例 #7
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param $order_id
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, $order_id)
 {
     $order = Order::find($order_id);
     if (!$order) {
         return $this->respondNotFound('Order does not exist.');
     }
     if (Auth::user()->id != $order->user->id) {
         return $this->respondInsufficientPermissions('User not authorized for this request.');
     }
     $request['order_id'] = $order_id;
     $validator = Validator::make($request->all(), ['order_id' => 'required|integer', 'name' => 'required|string', 'type' => 'required|integer', 'image_path' => 'required|string', 'option_strength' => 'required|integer', 'option_milk' => 'required|integer', 'option_sugar' => 'required|integer', 'option_mug' => 'required|boolean']);
     if ($validator->fails()) {
         return $this->respondValidationError($validator->errors(), "Parameters failed validation for a product");
     }
     $orderProduct = OrderProduct::create($request->all());
     return $this->respondCreated($this->productTransformer->transform($orderProduct));
 }
コード例 #8
0
 public function admin()
 {
     $output = array();
     $i = 0;
     $orders = Order::all();
     foreach ($orders as $order) {
         $pivots = OrderProduct::where('order_id', $order->id)->get();
         foreach ($pivots as $pivot) {
             $prod = Product::findOrFail($pivot['product_id']);
             $output[$i]['order'] = $order;
             $p = ['prod' => $prod, 'count' => $pivot['count'], 'cost_all' => (int) $pivot['count'] * (int) $prod->cost];
             $output[$i]['product'][] = $p;
         }
         $i++;
     }
     return view('admin', ['data' => $output]);
 }
コード例 #9
0
 public function payment(Request $request)
 {
     $userCart = Auth::user()->cart;
     $total = 0;
     foreach ($userCart as $item) {
         $total += $item->product->price * $item->amount;
     }
     if (Session::has('coupon')) {
         $total = $total - $total * Session::get('coupon.discount') / 100;
     }
     $billing = App::make('Ecommerce\\Billing\\BillingInterface');
     $billing->charge(['email' => Auth::user()->email, 'token' => $request->stripeToken, 'amount' => $total]);
     $order = Order::create(['user_id' => Auth::user()->id, 'amount' => $total, 'status' => 'Processing', 'firstname' => Session::get('shipping.firstname'), 'lastname' => Session::get('shipping.lastname'), 'shipping_address' => Session::get('shipping.address'), 'shipping_city' => Session::get('shipping.city'), 'shipping_zipcode' => Session::get('shipping.zipcode'), 'shipping_country' => Session::get('shipping.country'), 'payment_method' => 'Credit Card', 'phone' => Session::get('shipping.phone'), 'coupon_id' => Session::get('coupon.id')]);
     Session::forget('coupon');
     foreach ($userCart as $item) {
         OrderProduct::create(['order_id' => $order->id, 'product_id' => $item->product_id, 'amount' => $item->amount, 'options' => $item->options]);
         $item->product->quantity -= $item->amount;
         $item->product->save();
     }
     $this->clear();
     return \Redirect('/dashboard')->with(['alert-success' => 'Payment success']);
 }
コード例 #10
0
 public function run()
 {
     $faker = Faker::create();
     $orderIds = Order::lists('id')->all();
     foreach (range(1, 10) as $index) {
         OrderProduct::create(['order_id' => $faker->randomElement($orderIds), 'name' => $faker->word(), 'type' => $faker->numberBetween(0, 4), 'image_path' => $faker->word(), 'option_strength' => $faker->numberBetween(0, 4), 'option_milk' => $faker->numberBetween(0, 4), 'option_sugar' => $faker->numberBetween(0, 4), 'option_mug' => $faker->boolean()]);
     }
 }
コード例 #11
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $item = OrderProduct::find($id);
     Activity::log('Deleted an item from their cart.');
     $item->delete();
     return Redirect::action('CartController@index')->with('status', 'Item was successfully removed.');
 }
コード例 #12
0
 public function getPaymentStatus(Request $request)
 {
     // Get the payment ID before session clear
     $payment_id = Session::get('paypal_payment_id');
     // clear the session payment ID
     Session::forget('paypal_payment_id');
     if (!empty($request->PayerID) || !empty($request->token)) {
         return Redirect('/')->with('error', 'Payment failed');
     }
     $payment = Payment::get($payment_id, $this->_api_context);
     // 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 = new PaymentExecution();
     $execution->setPayerId($request->PayerID);
     //Execute the payment
     $result = $payment->execute($execution, $this->_api_context);
     // echo '<pre>';print_r($result);echo '</pre>';exit; // DEBUG RESULT, remove it later
     if ($result->getState() == 'approved') {
         // payment made
         $userCart = Auth::user()->cart;
         $total = 0;
         foreach ($userCart as $item) {
             $total += $item->product->price * $item->amount;
         }
         if (Session::has('coupon')) {
             $total = $total - $total * Session::get('coupon.discount') / 100;
         }
         $order = Order::create(['user_id' => Auth::user()->id, 'amount' => $total, 'status' => 'Processing', 'firstname' => Session::get('shipping.firstname'), 'lastname' => Session::get('shipping.lastname'), 'shipping_address' => Session::get('shipping.address'), 'shipping_city' => Session::get('shipping.city'), 'shipping_zipcode' => Session::get('shipping.zipcode'), 'shipping_country' => Session::get('shipping.country'), 'payment_method' => 'Paypal', 'phone' => Session::get('shipping.phone'), 'coupon_id' => Session::get('coupon.id')]);
         Session::forget('coupon');
         foreach ($userCart as $item) {
             OrderProduct::create(['order_id' => $order->id, 'product_id' => $item->product_id, 'options' => $item->options, 'amount' => $item->amount]);
             $item->product->quantity -= $item->amount;
             $item->product->save();
         }
         Auth::user()->cart()->delete();
         return Redirect('/dashboard')->with(['alert-success' => 'Paypal Payment success']);
     }
     return Redirect()->back()->with('alert-error', 'Payment failed');
 }
コード例 #13
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $orderProduct = new OrderProduct();
     $orderProduct->order_id = 1;
     // temporary!!
     $orderProduct->product_id = $request->product_id;
     $orderProduct->quantity = $request->quantity;
     $orderProduct->save();
     return $orderProduct;
     // return view('products.index', ['products' => $products]);
 }