コード例 #1
1
 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 !');
     }
 }
コード例 #2
0
 public function deleteOrder(Request $request)
 {
     $order_id = \StringHelper::filterString($request->input('order_id'));
     $deletedRows = Order::where('id', $order_id)->delete();
     $catRow = OrderDetail::where('order_id', $order_id)->delete();
     return Redirect::back()->with('message', 'Success');
 }
コード例 #3
0
 public function showOrderdetails()
 {
     $page = 'partials.admin-orderdetailsManagement';
     $users = User::all();
     $orderdetails = OrderDetail::simplePaginate(8);
     //
     return view('quantri/admin', compact('page', 'users', 'orderdetails'));
 }
コード例 #4
0
 public function detail($id)
 {
     if (Gate::denies('report.pertanggal.penjualan.detail')) {
         return view(config('app.template') . '.error.403');
     }
     $order = Order::find($id);
     if ($order->state == 'Closed') {
         $order->load('tax', 'bayarBank', 'bayar', 'place.place.kategori');
         $orderDetail = OrderDetail::join('produks', 'order_details.produk_id', '=', 'produks.id')->leftJoin('order_detail_returns', 'order_details.id', '=', 'order_detail_returns.order_detail_id')->join('orders', 'order_details.order_id', '=', 'orders.id')->where('orders.id', $id)->select(['produks.nama', 'order_details.harga_jual', DB::raw("(order_details.qty - ifnull(order_detail_returns.qty, 0)) as qty"), DB::raw("(order_details.harga_jual * (order_details.qty - ifnull(order_detail_returns.qty, 0))) as subtotal")])->groupBy('produks.id')->get();
         $orderPlaces = $order->place;
     } else {
         $order->load('merge.orderRef');
     }
     $data = ['order' => $order, 'orderDetail' => isset($orderDetail) ? $orderDetail : [], 'orderPlaces' => isset($orderPlaces) ? $orderPlaces : []];
     return view(config('app.template') . '.report.pertanggal-detail', $data);
 }
コード例 #5
0
ファイル: OrdersTableSeeder.php プロジェクト: ant-vel/Web
 public function run()
 {
     $faker = Faker::create();
     $users = User::get();
     $products = Product::get();
     for ($i = 0; $i < 10; $i++) {
         $user = $users->random(1);
         $status = $faker->randomElement(['open', 'paid', 'pending', 'installed', 'cancelled']);
         $order = Order::create(['user_id' => $user->id, 'status' => $status, 'end_date' => $status == 'installed' || $status == 'cancelled' ? $faker->dateTime() : null]);
         $random = $faker->numberBetween(1, 2);
         for ($y = 0; $y < $random; $y++) {
             $product = $products->random(1);
             OrderDetail::create(['order_id' => $order->id, 'product_id' => $product->id, 'price' => $product->price, 'quantity' => 1]);
         }
     }
 }
コード例 #6
0
 public function run()
 {
     $faker = Faker::create();
     $users = Address::get();
     $status_list = array_keys(trans('globals.order_status'));
     for ($i = 0; $i < 20; $i++) {
         $user = $users->random(1);
         $products = Product::get();
         $type = $faker->randomElement(['cart', 'wishlist', 'order']);
         $status = 'open';
         switch ($type) {
             case 'order':
                 $status = $faker->randomElement($status_list);
                 break;
         }
         $stock = $faker->numberBetween(1, 20);
         $order = Order::create(['user_id' => $user->user_id, 'seller_id' => '3', 'address_id' => $user->id, 'status' => $status, 'type' => $type, 'description' => $type == 'wishlist' ? $faker->companySuffix : '', 'end_date' => $status == 'closed' || $status == 'cancelled' ? $faker->dateTime() : null]);
         $num = $faker->numberBetween(2, 5);
         $list = [];
         if ($num > 1 && count($products) - 1 < $num) {
             $num = count($products) - 1;
         }
         for ($j = 0; $j < $num; $j++) {
             do {
                 $a = true;
                 $product = $products->random(1);
                 if (in_array($product->id, $list)) {
                     $a = false;
                 } else {
                     $list[] = $product->id;
                 }
             } while ($a == false);
             if ($status == 'closed') {
                 $delivery = $faker->dateTime();
             } else {
                 $delivery = $faker->numberBetween(0, 1) ? $faker->dateTime() : null;
             }
             OrderDetail::create(['order_id' => $order->id, 'product_id' => $product->id, 'price' => $product->price, 'quantity' => $stock, 'delivery_date' => $delivery]);
         }
         $order->sendNotice();
     }
 }
コード例 #7
0
 public function order($id, OrderFormRequest $request)
 {
     $receiver_name = $request->input('receiver_name');
     $address = $request->input('address');
     $phone = $request->input('phone');
     $email = $request->input('email');
     $received_date = $request->input('received_date');
     //
     $result = Order::create(['user_id' => $id, 'receiver_name' => $receiver_name, 'received_date' => $received_date, 'address' => $address, 'phone' => $phone, 'email' => $email]);
     if (count($result) > 0) {
         $items = Cart::content();
         $ordered_id = Order::select('id')->orderBy('id', 'desc')->first();
         foreach ($items as $item) {
             OrderDetail::create(['ordered_id' => $ordered_id->id, 'user_id' => $id, 'product_id' => $item->id, 'quantity' => $item->qty, 'price' => $item->price]);
             $update_quantity = Product::find($item->id);
             $update_quantity->update(['quantity' => $update_quantity->quantity - $item->qty]);
         }
     }
     Cart::destroy();
     return redirect()->route('completed');
 }
コード例 #8
0
ファイル: OrdersController.php プロジェクト: rolka/antVel
 public function rateProduct(Request $request)
 {
     $detail_id = $request->get('detail_id');
     $product_rate = $request->get('product_rate');
     $product_comment = $request->get('product_comment');
     $user = \Auth::user();
     if ($user) {
         $detail = OrderDetail::find($detail_id);
         if ($detail) {
             //Checks if the order exists and belongs to the current user
             $order = Order::where('id', $detail->order_id)->where('user_id', $user->id)->first();
             if ($order && $order->rate == '') {
                 $product = Product::find($detail->product_id);
                 $product_old_rate = $product->rate_val ? $product->rate_val : 0;
                 $product_old_rate_count = $product->rate_count ? $product->rate_count : 0;
                 //Checks if it is the first time the product is rated
                 if ($product_old_rate_count == 0) {
                     $product->rate_val = $product_rate;
                     $product->rate_count = 1;
                 } else {
                     //Checks if the user has rated this product on this order before
                     if ($detail->rate) {
                         if ($product_old_rate > $product_rate) {
                             $product->rate_val = $product->rate_val - ($product_old_rate - $product_rate) / $product_old_rate_count;
                         }
                         if ($product_old_rate < $product_rate) {
                             $product->rate_val = $product->rate_val + ($product_rate - $product_old_rate) / $product_old_rate_count;
                         }
                     } else {
                         if ($product_old_rate > $product_rate) {
                             $product->rate_val = $product->rate_val - ($product_old_rate - $product_rate) / ($product_old_rate_count + 1);
                         }
                         if ($product_old_rate < $product_rate) {
                             $product->rate_val = $product->rate_val + ($product_rate - $product_old_rate) / ($product_old_rate_count + 1);
                         }
                         $product->rate_count = $product_old_rate_count + 1;
                     }
                 }
                 $seller_user = User::find($order->seller_id);
                 $email = $seller_user->email;
                 $mail_subject = trans('email.product_rated.subject');
                 $data = ['product_id' => $product->id, 'subject' => $mail_subject, 'email_message' => $mail_subject, 'email' => $email];
                 Mail::queue('emails.product_rated', $data, function ($message) use($user, $data) {
                     $message->to($data['email'])->subject($data['subject']);
                 });
                 $product->save();
                 $detail->rate = $product_rate;
                 $detail->rate_comment = $product_comment;
                 $detail->save();
                 Notice::create(['user_id' => $seller_user->id, 'sender_id' => $user->id, 'action_type_id' => 14, 'source_id' => $order->id, 'status' => 'new']);
                 return \Response::json(array('success' => true, 'message' => trans('store.order_rate_view.http_messages.success'), 'detail_id' => $detail_id, 'product_rate' => $product_rate), 200);
             } else {
                 return \Response::json(array('success' => false, 'message' => trans('store.order_rate_view.http_messages.no_order'), 'detail_id' => $detail_id, 'product_rate' => $product_rate), 200);
             }
         } else {
             return \Response::json(array('success' => false, 'message' => trans('store.order_rate_view.http_messages.no_user'), 'detail_id' => $detail_id, 'product_rate' => $product_rate), 200);
         }
     } else {
         return \Response::json(array('success' => false, 'message' => trans('store.order_rate_view.http_messages.no_user'), 'detail_id' => $detail_id, 'product_rate' => $product_rate), 200);
     }
 }
コード例 #9
0
 public function run()
 {
     $faker = Faker::create();
     $users = UserAddress::get();
     $status_list = array_keys(trans('globals.order_status'));
     for ($i = 0; $i < 40; $i++) {
         $user = $users->random(1);
         $products = Product::where('id', '!=', $user->user_id)->where('type', '!=', 'freeproduct')->get();
         $type = 'freeproduct';
         $status = 'paid';
         $order = Order::create(['user_id' => $user->user_id, 'seller_id' => '3', 'address_id' => $user->address_id, 'status' => 'paid', 'type' => $type, 'description' => '', 'end_date' => null]);
         //Productos a insertar a la orden. Se haran copias de los productos que esten en las ordenes y se le asignara el tipo freeproduct
         $num = $faker->numberBetween(2, 5);
         $list = [];
         if ($num > 1 && count($products) - 1 < $num) {
             $num = count($products) - 1;
         }
         for ($j = 0; $j < $num; $j++) {
             do {
                 $a = true;
                 $product = $products->random(1);
                 $quantity = $faker->numberBetween(1, 5);
                 if (in_array($product->id, $list)) {
                     $a = false;
                 } else {
                     //duplico el producto
                     $productactual = $product->toArray();
                     unset($productactual['id']);
                     unset($productactual['num_of_reviews']);
                     $productactual['user_id'] = '3';
                     //$user->user_id;
                     $productactual['type'] = 'freeproduct';
                     $productactual['parent_id'] = $product->id;
                     $newproduct = Product::create($productactual);
                     $list[] = $product->id;
                 }
             } while ($a == false);
             //el nuevo producto lo asocio al detalle de la orden
             OrderDetail::create(['order_id' => $order->id, 'product_id' => $newproduct->id, 'price' => $product->price, 'quantity' => $quantity, 'delivery_date' => null]);
             //Actualizo el stock
             $product->stock = $product->stock - $quantity;
             $product->save();
         }
         $order->sendNotice();
     }
     $orders = Order::where('type', '=', 'freeproduct')->get();
     $users = User::where('type', 'trusted')->get();
     $list_orders = [];
     for ($i = 0; $i < 15; $i++) {
         //Se crea el free product y se asocia las ordenes
         $user = $users->random(1);
         $end_date = \Carbon\Carbon::now()->addDays($faker->numberBetween(5, 30));
         $freeproduct = FreeProduct::create(['user_id' => '3', 'description' => $faker->unique()->catchPhrase, 'start_date' => \Carbon\Carbon::now(), 'end_date' => $end_date, 'participation_cost' => $faker->numberBetween(10000, 50000), 'min_participants' => $min_participants = $faker->numberBetween(1, 15), 'max_participants' => $faker->numberBetween($min_participants, $min_participants * 2), 'max_participations_per_user' => $faker->numberBetween(1, 5), 'draw_number' => $faker->numberBetween(1, 3), 'draw_date' => $end_date->addDays($faker->numberBetween(1, 5)), 'status' => $faker->randomElement([0, 1])]);
         //asocio una o mas ordenes a un free product
         $num = $faker->numberBetween(1, 3);
         if ($num > 1 && count($orders) - 1 < $num) {
             $num = count($orders) - 1;
         }
         for ($j = 0; $j < $num; $j++) {
             do {
                 $a = true;
                 $order = $orders->random(1);
                 if (in_array($order->id, $list_orders)) {
                     $a = false;
                 } else {
                     $list_orders[] = $order->id;
                 }
             } while ($a == false);
             FreeProductOrder::create(['order_id' => $order->id, 'freeproduct_id' => $freeproduct->id]);
         }
     }
 }
コード例 #10
0
ファイル: OrderController.php プロジェクト: dhduc/shopui
 public function invoice($id)
 {
     // Order
     $order = Order::find($id);
     $orderID = $id;
     $customerID = $order->customerID;
     // Customer
     $customer = Customer::find($customerID);
     // Product list
     $product = OrderDetail::where('orderID', $orderID)->get();
     $productView = "";
     $totalOrder = 0;
     foreach ($product as $index => $item) {
         $cost = Product::find($item['productID'])->cost;
         $productView .= '<tr>
                     <td> ' . ($index + 1) . ' </td>
                     <td>
                     <a href="#">
                         ' . $item['pName'] . '</a>
                 </td>
                 <td>
                     ' . $item['pPrice'] . '
                 </td>
                 <td>
                     ' . $item['pQty'] . '
                 </td>
                 <td>
                     ' . $item['total'] . '
                 </td>
             </tr>';
         $totalOrder += $item['pQty'] * $item['pPrice'];
     }
     // Payment
     $totalPaid = $totalOrder + $totalOrder * ($this->tax / 100) + $this->ship;
     $payment = array('total' => $totalOrder, 'tax' => $this->tax, 'tax_value' => $totalOrder * ($this->tax / 100), 'ship' => $this->ship, 'paid' => $totalPaid);
     return view('admin.order.invoice')->with(['orderInfo' => $order, 'customerInfo' => $customer, 'productView' => $productView, 'payment' => $payment]);
 }
コード例 #11
0
 public function pertanggalDetailReturn(Request $request)
 {
     if ($request->get('id')) {
         $id = $request->get('id');
         $orderDetail = OrderDetail::with('order', 'detailReturn')->find($id);
         $data = ['orderDetail' => $orderDetail];
         return view(config('app.template') . '.order.pertanggal-detail-return', $data);
     } else {
         return view(config('app.template') . '.error.404');
     }
 }
コード例 #12
0
 /**
  * Update the specified resource in storage.
  *
  * @param int $id
  *
  * @return Response
  */
 public function update($id, Request $request)
 {
     if (!$request->input('type')) {
         return redirect()->back()->withErrors(['induced_error' => [trans('globals.error') . ' ' . trans('globals.induced_error')]])->withInput();
     }
     $rules = $this->rulesByTypes($request, true);
     $order = OrderDetail::where('product_id', $id)->join('orders', 'order_details.order_id', '=', 'orders.id')->first();
     if ($order) {
         unset($rules['name']);
         unset($rules['category_id']);
         unset($rules['condition']);
     }
     $v = Validator::make($request->all(), $rules);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors())->withInput();
     }
     $features = $this->validateFeatures($request->all());
     if (!is_string($features)) {
         return redirect()->back()->withErrors($features)->withInput();
     }
     $product = Product::find($id);
     if (\Auth::id() != $product->user_id) {
         return redirect('products/' . $product->user_id)->withErrors(['feature_images' => [trans('globals.not_access')]]);
     }
     if (!$order) {
         $product->name = $request->input('name');
         $product->category_id = $request->input('category_id');
         $product->condition = $request->input('condition');
     }
     $product->status = $request->input('status');
     $product->description = $request->input('description');
     $product->bar_code = $request->input('bar_code');
     $product->brand = $request->input('brand');
     $product->price = $request->input('price');
     $product->features = $features;
     if ($request->input('type') == 'item') {
         $product->stock = $request->input('stock');
         $product->low_stock = $request->input('low_stock');
         if ($request->input('stock') > 0) {
             $product->status = $request->input('status');
         } else {
             $product->status = 0;
         }
     } else {
         $product->status = $request->input('status');
     }
     $product->save();
     $message = '';
     if ($request->input('type') != 'item') {
         switch ($request->input('type')) {
             case 'key':
                 if ($request->input('key') != '' && Storage::disk('local')->exists('key_code' . $request->input('key'))) {
                     $contents = Storage::disk('local')->get('key_code' . $request->input('key'));
                     $contents = explode("\n", rtrim($contents));
                     $warning = false;
                     $len = 0;
                     foreach ($contents as $row) {
                         $virtualProduct = new virtualProduct();
                         $virtualProduct->product_id = $product->id;
                         $virtualProduct->key = $row;
                         $virtualProduct->status = 'open';
                         $virtualProduct->save();
                         if ($len == 0) {
                             $len = strlen(rtrim($row));
                         } elseif (strlen(rtrim($row)) != $len) {
                             $warning = true;
                         }
                     }
                     $stock = count(VirtualProduct::where('product_id', $product->id)->where('status', 'open')->get()->toArray());
                     $product->stock = $stock;
                     if ($stock == 0) {
                         $product->status = 0;
                     }
                     $product->save();
                     $message = ' ' . trans('product.controller.review_keys');
                     if ($warning) {
                         $message .= ' ' . trans('product.controller.may_invalid_keys');
                     }
                     Storage::disk('local')->deleteDirectory('key_code/' . \Auth::id());
                 }
                 break;
             case 'software':
                 break;
             case 'software_key':
                 break;
             case 'gift_card':
                 break;
         }
     }
     Session::flash('message', trans('product.controller.saved_successfully') . $message);
     return redirect('products/' . $product->id);
 }
コード例 #13
0
ファイル: OrderController.php プロジェクト: ramant15/ektimo
 public function saveClientOrder(Request $request)
 {
     $input = $request->all();
     if (!empty($input['qty'])) {
         $mainArr = array();
         $hbody = '';
         $loc_info = DB::table('test_locations')->where('id', '=', $input['test_location_id'])->first();
         $orderData = array('user_id' => $input['user_id'], 'customer_id' => $input['customer_id'], 'site_id' => $input['site_id'], 'test_location_id' => $input['test_location_id'], 'interval' => $input['interval']);
         $order = new Order();
         $order->create($orderData);
         $order_id = DB::getPdo()->lastInsertId();
         $total = 0;
         foreach ($input['qty'] as $test_id => $qty) {
             $data = DB::table('tests')->where('tests.id', '=', $test_id)->join('parameters', 'tests.parameter_id', '=', 'parameters.id')->join('states', 'tests.state_id', '=', 'states.id')->join('methods', 'tests.method_id', '=', 'methods.id')->join('test_methods', 'tests.test_method_id', '=', 'test_methods.id')->select('tests.id', 'tests.price', 'parameters.name as parameter', 'states.name as state', 'methods.name as method', 'states.name as state', 'test_methods.name as test_method')->first();
             $orderArr = array();
             $orderArr['order_id'] = $order_id;
             $orderArr['test_id'] = $test_id;
             $orderArr['location_id'] = $loc_info->location_id;
             $orderArr['location_type'] = $loc_info->type;
             $orderArr['location_name'] = $loc_info->name;
             $orderArr['location_description'] = $loc_info->description;
             $orderArr['quantity'] = $qty;
             $orderArr['price'] = round($qty * $data->price, 2);
             $orderArr['parameter'] = $data->parameter;
             $orderArr['state'] = $data->state;
             $orderArr['method'] = $data->method . '-' . $data->test_method;
             $orderArr['test_method'] = $data->test_method;
             $orderArr['total'] = $orderArr['price'] * $orderArr['quantity'];
             $hbody .= "<tr>\n\t\t\t\t\t<td width='300px'>" . $orderArr['location_id'] . "</td>\n\t\t\t\t\t<td width='300px'>" . $orderArr['location_type'] . "</td>\n\t\t\t\t\t<td width='300px'>" . $orderArr['location_description'] . "</td>\n\t\t\t\t\t<td width='300px'>" . $orderArr['parameter'] . "</td>\n\t\t\t\t\t<td width='30px'>" . $orderArr['state'] . "</td>\n\t\t\t\t\t<td width='50px'>" . $orderArr['method'] . "</td>\n\t\t\t\t\t<td width='200px'>" . $orderArr['test_method'] . "</td>\n\t\t\t\t\t<td width='20px'>" . $orderArr['quantity'] . "</td>\n\t\t\t\t\t<td width='50px'>\$" . $orderArr['price'] . "</td></tr>";
             $orderDetails = new OrderDetail();
             $orderDetails->create($orderArr);
             $total += $orderArr['total'];
         }
         $order = Order::find($order_id);
         $order->update(array('total' => $total));
         $html = "<p>Hi Admin,</p>";
         $html .= "<p>There is order requested by Customer Id: " . $input['customer_id'] . "</p>";
         $html .= "<table style='border:1px solid #ccc'>\n\t\t\t\t\t<thead style='border-bottom:1px solid #ccc'>\n\t\t\t\t\t<td width='300px'><strong>Location ID</strong></td>\n\t\t\t\t\t<td width='30px'><strong>Location type</strong></td>\n\t\t\t\t\t<td width='50px'><strong>Location Description</strong></td>\n\t\t\t\t\t<td width='300px'><strong>Parameter</strong></td>\n\t\t\t\t\t<td width='30px'><strong>State</strong></td>\n\t\t\t\t\t<td width='50px'><strong>Method</strong></td>\n\t\t\t\t\t<td width='200px'><strong>Test Method</strong></td>\n\t\t\t\t\t<td width='20px'><strong>Qty</strong></td>\n\t\t\t\t\t<td width='50px'><strong>Price</strong></td>\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>";
         $hend = "</tbody></table><p>Thanks</p>";
         $allhtml = $html . $hbody . $hend;
         //mail('*****@*****.**', 'Order Request', $allhtml);
         $headers = "MIME-Version: 1.0" . "\r\n";
         $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
         // More headers
         $headers .= 'From: <*****@*****.**>' . "\r\n";
         $to = "*****@*****.**";
         $subject = "Order Request";
         mail($to, $subject, $allhtml, $headers);
     }
     if ($order_id) {
         Session::flash('flash_message', 'Request Submitted Successfully.');
         Session::flash('flash_type', 'alert-success');
     }
     return redirect('order');
 }
コード例 #14
0
 public function postCheckOut(CheckOutRequest $request)
 {
     try {
         if (Auth::check()) {
             $customer = Customer::find(Auth::user()->userable_id);
             if ($customer->name != $request->name) {
                 $customer = new Customer();
                 $customer->name = $request->name;
                 $customer->address = $request->address;
                 $customer->phone = $request->phone;
                 $customer->save();
             }
         } else {
             $customer = Customer::where('phone', '=', $request->phone)->first();
             if ($customer->count() == 0) {
                 $customer = new Customer();
                 $customer->name = $request->name;
                 $customer->address = $request->address;
                 $customer->phone = $request->phone;
                 $customer->save();
             }
         }
         $_token = csrf_token();
         $carts = Cart::where(function ($query) use($_token) {
             $query->where('user_id', '=', Auth::check() ? Auth::user()->id : 0)->orWhere('remember_token', '=', $_token);
         });
         if ($carts->count() > 0) {
             $order = new Order();
             $order->customer_id = $customer->id;
             $order->note = $request->note;
             $order->ship_time = $request->ship_time;
             $order->save();
             foreach ($carts->get() as $cart) {
                 $order_detail = new OrderDetail();
                 $order_detail->order_id = $order->id;
                 $order_detail->book_id = $cart->book_id;
                 $order_detail->quantity = $cart->quantity;
                 $order_detail->save();
             }
             $carts->delete();
             return redirect('/')->with('message', 'Đặt hàng thành công. Chúng tôi sẽ sớm liên lạc với bạn!')->with('alert-class', 'alert-success')->with('fa-class', 'fa-check');
         } else {
             return redirect('/checkout')->with('message', 'Không có hàng trong giỏ.')->with('alert-class', 'alert-warning')->with('fa-class', 'fa-warning');
         }
     } catch (ValidationException $e) {
         return redirect('/checkout')->with('message', 'Xảy ra lỗi khi lưu đơn hàng, vui lòng thử lại!!!')->with('alert-class', 'alert-danger')->with('fa-class', 'fa-ban');
     }
 }
コード例 #15
0
 /**
  *	edit the number of key registered for email.
  *
  *	@param 	string|int 	id product
  *	@param 	Request 	object to validate the type of request|action to ejecute
  *
  *	@return json
  */
 public function editKey($id, Request $request)
 {
     if (!$request->wantsJson()) {
         return ['message' => trans('globals.error_not_available')];
     }
     if (!$request->has('email')) {
         return ['message' => trans('globals.error_not_available')];
     }
     $cart = Order::ofType('cart')->select('id', 'status')->where('user_id', \Auth::id())->first();
     if (!$cart) {
         return ['message' => trans('globals.error_not_available')];
     }
     $product = Product::select('id', 'stock')->find($id);
     if (!$product) {
         return ['message' => trans('globals.error_not_available')];
     }
     $order = OrderDetail::where('order_id', $cart->id)->where('product_id', $product->id)->first();
     if (!$order) {
         return ['message' => trans('globals.error_not_available')];
     }
     $virtual = VirtualProduct::select('id')->where('product_id', $product->id)->first();
     if ($request->has('delete')) {
         $virtualOrder = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->delete();
         $num2 = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('status', 1)->get()->toArray();
         if (!count($num2)) {
             $order->delete();
         } else {
             $order->quantity = count($num2);
             $order->save();
         }
         return ['all' => true];
     } elseif ($request->has('decrement')) {
         $virtualOrder = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->where('status', 1)->first();
         $virtualOrder->delete();
         $num2 = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('status', 1)->get()->toArray();
         if (!count($num2)) {
             $order->delete();
         } else {
             $order->quantity = count($num2);
             $order->save();
         }
         $num = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->where('status', 1)->get()->toArray();
         if (count($num)) {
             return ['delete' => true, 'num' => count($num)];
         }
         return ['all' => true];
     } elseif ($request->has('increment')) {
         $num2 = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('status', 1)->get()->toArray();
         if (count($num2) + 1 > $product->stock) {
             return ['message' => trans('product.virtualProductOrdersController_controller.no_stock')];
         }
         $virtualOrder = new VirtualProductOrder();
         $virtualOrder->order_id = $order->order_id;
         $virtualOrder->status = 1;
         $virtualOrder->email = $request->input('email');
         $virtualOrder->virtual_product_id = $virtual->id;
         $virtualOrder->save();
         $order->quantity = count($num2) + 1;
         $order->save();
         $num = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->where('status', 1)->get()->toArray();
         return ['insert' => true, 'num' => count($num)];
     }
     return ['message' => trans('globals.error_not_available')];
 }
コード例 #16
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!");
         }
     }
 }
コード例 #17
0
ファイル: HomeController.php プロジェクト: ramant15/ektimo
 function update_order(Request $request, $id)
 {
     $input = $request->all();
     if ($id) {
         $total = 0;
         $order = Order::find($id);
         foreach ($input['parameter'] as $key => $parameter) {
             $orderArr = array();
             $orderArr['parameter'] = $parameter;
             $orderArr['state'] = $input['state'][$key];
             $orderArr['method'] = $input['method'][$key];
             $orderArr['test_method'] = $input['test_method'][$key];
             $orderArr['quantity'] = $input['quantity'][$key];
             $orderArr['price'] = $input['price'][$key];
             $orderArr['total'] = $orderArr['price'] * $orderArr['quantity'];
             if (isset($input['test_id'][$key])) {
                 $orderArr['test_id'] = $input['test_id'][$key];
             }
             $total += $orderArr['price'] * $orderArr['quantity'];
             $orderDetails = OrderDetail::find($key);
             $orderDetails->update($orderArr);
         }
         if ($total) {
             $order->update(array('total' => $total));
         }
         Session::flash('flash_message', 'Order has been updated successfully.');
         Session::flash('flash_type', 'alert-success');
     }
     return redirect('home');
 }
コード例 #18
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     OrderDetail::find($id)->delete();
     return redirect('orderDetails');
 }
コード例 #19
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     try {
         //Find all freeproducts that can be processed; that is, they are in the correct date range and are active.
         $this->info('----- STARTING THE PROCESS FOR SELECTION OF WINNERS -----');
         $dateactual = date('Y-m-d');
         $freeproducts = FreeProduct::where('status', 1)->where('draw_date', $dateactual)->get();
         if ($freeproducts) {
             $this->info('Free Products to be processed: ' . $freeproducts->count());
             foreach ($freeproducts as $freeproduct) {
                 //Check the total participants. Depending on this the freeproduct be processed. Remember that there is a minimum of participation to select the winners. Still it not defined to do if the minimum is not met.
                 $participants = FreeProductParticipant::where('freeproduct_id', $freeproduct->id)->where('status', 'registered')->get();
                 if ($freeproduct->min_participants <= $participants->count()) {
                     //Select the winners, as defined in the product free draw_number field.
                     $list_winners = [];
                     for ($i = 0; $i < $freeproduct->draw_number; $i++) {
                         $user_winner = $participants->random(1);
                         $list_winners[] = $user_winner->user_id;
                         $user_winner->status = 'winner';
                         $user_winner->save();
                     }
                     $this->info('Total winners -> ' . count($list_winners));
                     //We mail to notify the winners and create an order for you to communicate with the seller of the product. The first is to list all the products contained in the orders associated with that freeproduct
                     //Collection Orders with Products in details
                     $orders = FreeProduct::find($freeproduct->id)->orders()->with('products')->get();
                     //Collection Products
                     $list_products_orders = Collection::make();
                     foreach ($orders as $order) {
                         $list_products_orders = $list_products_orders->merge($order->products);
                     }
                     $this->info('Total Products to prize: ' . count($list_products_orders));
                     $list_awards = [];
                     foreach ($list_winners as $user_id) {
                         $winner = User::find($user_id);
                         $this->info("Processing user -> ID={$winner->id} ");
                         //In this part of the process, we should when creating the freeproduct, indicate how the prizes will be distributed, something like for position, and indicate that many products will be delivered by position. For now, a product be taken at random.
                         do {
                             $product_award = $list_products_orders->random(1);
                             $in_product_award_list = true;
                             if (in_array($product_award->id, $list_awards)) {
                                 $in_product_award_list = false;
                             } else {
                                 $list_awards[] = $product_award->id;
                                 $this->info("Product selected-> ID={$product_award->id} ");
                             }
                         } while (!$in_product_award_list);
                         //Creating the order with the product won user
                         $winner_address = UserAddress::where('user_id', $winner->id)->orderBy('default', 'DESC')->first();
                         $newOrder = new Order();
                         $newOrder->user_id = $winner->id;
                         $newOrder->address_id = $winner_address->id;
                         $newOrder->status = 'pending';
                         $newOrder->type = 'freeproduct';
                         $newOrder->seller_id = $freeproduct->user_id;
                         $newOrder->save();
                         $newOrder->sendNotice();
                         $this->info("Creating order: Result -> ID {$newOrder->id}");
                         //Order detail. Just take the product won
                         $newOrderDetail = new OrderDetail();
                         $newOrderDetail->order_id = $newOrder->id;
                         $newOrderDetail->product_id = $product_award->id;
                         $newOrderDetail->price = $freeproduct->participation_cost;
                         $newOrderDetail->quantity = 1;
                         $newOrderDetail->status = 1;
                         $newOrderDetail->save();
                         //Off product will deliver a prize
                         $product_award->status = 0;
                         $product_award->save();
                         //Notify the user that was selected as winner of that freeproduct
                         $data = ['product' => $product_award];
                         Mail::queue('emails.freeproducts.winner', $data, function ($message) use($winner) {
                             $message->to($winner->email)->subject(trans('email.free_products_winner.subject'));
                         });
                         $this->info('email sent notice that won');
                         //He also sent an email indicating that a new order was created.(tracking)
                         $data = ['orderId' => $newOrder->id];
                         Mail::queue('emails.neworder', $data, function ($message) use($winner) {
                             $message->to($winner->email)->subject(trans('email.new_order_for_user.subject'));
                         });
                         $this->info('email I sent notice that an order for the product won');
                     }
                     //Freeproduct inactive, so they do not take into account again for next draw
                     $freeproduct->status = 0;
                     $freeproduct->save();
                     //Se le notifica al dueno del freeproduct que se seleccionaron a los ganadores
                     $this->info("FreeProduct -> ID={$freeproduct->id} PROCESSED");
                 } else {
                     $this->info("FreeProduct -> ID={$freeproduct->id} The minimum participation condition for the free product does not comply.");
                 }
             }
         }
         $this->info('----- FINISHED THE PROCESS FOR SELECTION OF WINNERS -----');
     } catch (ModelNotFoundException $e) {
         Log::error($e);
         $this->error('They received errors when running the process. View Log File.');
     }
 }
コード例 #20
0
 public function bayar(Request $request)
 {
     if ($request->get('id')) {
         $id = $request->get('id');
         $order = Order::with(['karyawan', 'bayar.karyawan', 'tax.tax', 'bayarBank.bank', 'place.place', 'customer'])->find($id);
         $total = $orderDetails = OrderDetail::with('order')->leftJoin('order_detail_returns', 'order_details.id', '=', 'order_detail_returns.order_detail_id')->join('produks', 'order_details.produk_id', '=', 'produks.id')->where('order_details.order_id', $id)->select(['order_details.id', 'order_details.produk_id', 'produks.nama', 'order_details.harga_jual', 'order_details.qty as qty_ori', DB::raw('ifnull(order_detail_returns.qty, 0) as qty_return'), DB::raw('(order_details.qty - ifnull(order_detail_returns.qty, 0))qty'), DB::raw('(order_details.harga_jual * (order_details.qty - ifnull(order_detail_returns.qty, 0)))subtotal')])->get()->sum('subtotal');
         foreach ($order->place as $op) {
             if ($op->harga > 0) {
                 $total += $op->harga;
             }
         }
         $total += $order->bayar->service_cost;
         $tax_procentage = round($order->tax->procentage);
         $tax = round($total * ($tax_procentage / 100));
         $tax_bayar_procentage = $order->bayarBank != null ? round($order->bayarBank->tax_procentage) : 0;
         $tax_bayar = round(($total + $tax) * ($tax_bayar_procentage / 100));
         $jumlah = round($total + $tax + $tax_bayar);
         $sisa = round($jumlah - $order->bayar->diskon);
         $kembali = round($order->bayar->bayar - $sisa);
         return ['kasir' => $order->bayar->karyawan->nama, 'waiters' => $order->karyawan->nama, 'customer' => $order->customer != null ? $order->customer->nama : null, 'total' => number_format($total, 0, ",", "."), 'tax_pro' => $order->tax->procentage, 'tax' => number_format($tax, 0, ",", "."), 'tax_bayar_pro' => $tax_bayar_procentage, 'tax_bayar' => number_format($tax_bayar, 0, ",", "."), 'jumlah' => number_format($jumlah, 0, ",", "."), 'diskon' => number_format($order->bayar->diskon, 0, ",", "."), 'sisa' => number_format($sisa, 0, ",", "."), 'bayar' => number_format($order->bayar->bayar, 0, ",", "."), 'kembali' => number_format($kembali, 0, ",", ".")];
     } else {
         abort(500);
     }
 }
コード例 #21
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     try {
         $validator = Validator::make($request->all(), $this->form_rules);
         if ($validator->fails()) {
             return redirect()->route('freeproducts.create', [$request->input('order_id')])->withErrors($validator->errors())->withInput();
         }
         //As is not defined that way is going to deliver products for every winner, I will confirm that the total winning is equal to total products in the cart
         $cart_detail = OrderDetail::where('order_id', $request->input('order_id'))->get();
         if ($request->input('draw_number') > $cart_detail->count()) {
             return redirect()->route('freeproducts.create', [$request->input('order_id')])->withErrors(trans('freeproduct.drawnumber_exceed_total_products'))->withInput();
         } else {
             //Process the order. The process is the same as with a shopping cart. The address is not requested
             //Direction is taken as the one with the user by default. Not having, it notifies the user to create a.
             $errors = Order::placeOrders('freeproduct');
             if ($errors) {
                 return redirect()->route('freeproducts.create', [$request->input('order_id')])->withErrors($errors)->withInput();
             } else {
                 $user = \Auth::user();
                 //Save Free Product
                 $freeproduct = new FreeProduct();
                 $freeproduct->user_id = $user->id;
                 $freeproduct->description = $request->input('description');
                 $freeproduct->start_date = $request->input('start_date');
                 $freeproduct->end_date = $request->input('end_date');
                 $freeproduct->participation_cost = $request->input('participation_cost');
                 $freeproduct->min_participants = $request->input('min_participants');
                 $freeproduct->max_participants = $request->input('max_participants');
                 $freeproduct->max_participations_per_user = $request->input('max_participations_per_user');
                 $freeproduct->draw_number = $request->input('draw_number');
                 $freeproduct->draw_date = $request->input('draw_date');
                 $freeproduct->save();
                 //Because the method placeOrders products generates orders for each vendor, you need to associate these orders to free product
                 $orders = Order::ofType('freeproduct')->ofStatus('paid')->where('user_id', $user->id)->get();
                 if ($orders) {
                     foreach ($orders as $order) {
                         //Each order products are searched and a duplicate of the same is made, marking them as a free product. This will allow the product goes on the results of the advanced search
                         $order_detail = OrderDetail::where('order_id', $order->id)->get();
                         if ($order_detail) {
                             foreach ($order_detail as $detail) {
                                 $product = Product::find($detail->product_id);
                                 $productactual = $product->toArray();
                                 unset($productactual['id']);
                                 unset($productactual['num_of_reviews']);
                                 $productactual['user_id'] = $user->id;
                                 $productactual['stock'] = $detail->quantity;
                                 $productactual['type'] = 'freeproduct';
                                 $productactual['parent_id'] = $product->id;
                                 $newproduct = Product::create($productactual);
                             }
                         }
                         if (!FreeProductOrder::where('order_id', $order->id)->first()) {
                             //order registration as a free product
                             $order_to_fp = new FreeProductOrder();
                             $order_to_fp->freeproduct_id = $freeproduct->id;
                             $order_to_fp->order_id = $order->id;
                             $order_to_fp->save();
                         }
                     }
                 }
                 //Send message process Ok and redirect
                 Session::flash('message', trans('freeproduct.saved_successfully'));
                 return redirect()->route('freeproducts.show', [$freeproduct->id]);
             }
         }
     } catch (ModelNotFoundException $e) {
         Log::error($e);
         return redirect()->back()->withErrors(['induced_error' => [trans('freeproduct.error_exception')]])->withInput();
     }
 }
コード例 #22
0
 protected static function _penjualan($tanggal1, $tanggal2)
 {
     return \App\OrderDetail::join(DB::raw("(SELECT produks.`id`, produks.`nama`\n                FROM produks LEFT JOIN produk_details ON produks.`id` = produk_details.`produk_id`\n                WHERE produk_details.`id` IS NULL GROUP BY produks.`id`)temp_produk"), 'order_details.produk_id', '=', 'temp_produk.id')->leftJoin('order_detail_returns', 'order_details.id', '=', 'order_detail_returns.order_detail_id')->join('orders', 'order_details.order_id', '=', 'orders.id')->whereBetween('orders.tanggal', [$tanggal1, $tanggal2])->groupBy('temp_produk.id')->select(['temp_produk.id', 'temp_produk.nama', DB::raw('SUM(order_details.qty - ifnull(order_detail_returns.qty, 0))qty')])->get()->toArray();
 }
コード例 #23
0
 public function is_disabled($id)
 {
     $product = Product::find($id);
     $orderdetail = OrderDetail::where('product_id', '=', $product->id)->first();
     if (count($orderdetail)) {
         $order = Order::find($orderdetail->ordered_id);
         if ($order->status == 0) {
             echo "<script>\n                        alert('This product is in an Order that HAS NOT paid yet!');\n                        window.history.back();\n                    </script>";
         } else {
             if ($product->is_disabled == 0) {
                 $product->is_disabled = 1;
             } else {
                 $product->is_disabled = 0;
             }
             $product->save();
             return redirect()->route('admin.productManagement');
         }
     } else {
         if ($product->is_disabled == 0) {
             $product->is_disabled = 1;
         } else {
             $product->is_disabled = 0;
         }
         $product->save();
         return redirect()->route('admin.productManagement');
     }
 }
コード例 #24
0
ファイル: Order.php プロジェクト: WebtoolsWendland/antVel
 /**
  * Start the checkout process for any type of order
  *
  * @param  int  $type_order Type of order to be processed
  * @return Response
  */
 public static function placeOrders($type_order)
 {
     $cart = Order::ofType($type_order)->auth()->whereStatus('open')->orderBy('id', 'desc')->first();
     $show_order_route = $type_order == 'freeproduct' ? 'freeproducts.show' : 'orders.show_cart';
     $cartDetail = OrderDetail::where('order_id', $cart->id)->get();
     $address_id = 0;
     //When address is invalid, it is because it comes from the creation of a free product. You must have a user direction (Default)
     if (is_null($cart->address_id)) {
         $useraddress = UserAddress::auth()->orderBy('default', 'DESC')->first();
         if ($useraddress) {
             $address_id = $useraddress->address_id;
         } else {
             return trans('address.no_registered');
         }
     } else {
         $address_id = $cart->address_id;
     }
     $address = Address::where('id', $address_id)->first();
     //Checks if the user has points for the cart price and the store has stock
     //and set the order prices to the current ones if different
     //Creates the lists or sellers to send mail to
     $total_points = 0;
     $seller_email = array();
     foreach ($cartDetail as $orderDetail) {
         $product = Product::find($orderDetail->product_id);
         $seller = User::find($product->user_id);
         if (!in_array($seller->email, $seller_email)) {
             $seller_email[] = $seller->email;
         }
         $total_points += $orderDetail->quantity * $product->price;
         if ($orderDetail->price != $product->price) {
             $orderDetail->price = $product->price;
             $orderDetail->save();
         }
         if ($product->type != 'item') {
             $virtual = VirtualProduct::where('product_id', $orderDetail->product_id)->get();
             $first = $virtual->first();
             //$first=null;
             //foreach ($virtual as $row){
             //$first=$row;
             //break;
             //}
             switch ($product->type) {
                 case 'key':
                 case 'software_key':
                     $virtualOrder = VirtualProductOrder::where('virtual_product_id', $first->id)->where('order_id', $orderDetail->order_id)->where('status', 1)->get();
                     if (count($virtual) - 1 < count($virtualOrder)) {
                         return trans('store.insufficientStock');
                     }
                     break;
                 default:
                     break;
             }
         } elseif ($product->stock < $orderDetail->quantity) {
             return trans('store.insufficientStock');
         }
     }
     //Checks if the user has points for the cart price
     $user = \Auth::user();
     if ($user->current_points < $total_points && config('app.payment_method') == 'Points') {
         return trans('store.cart_view.insufficient_funds');
     }
     if (config('app.payment_method') == 'Points') {
         $negativeTotal = -1 * $total_points;
         //7 is the action type id for order checkout
         $pointsModified = $user->modifyPoints($negativeTotal, 7, $cart->id);
     } else {
         $pointsModified = true;
     }
     if ($pointsModified) {
         //Separate the order for each seller
         //Looks for all the different sellers in the cart
         $sellers = [];
         foreach ($cartDetail as $orderDetail) {
             if (!in_array($orderDetail->product->user_id, $sellers)) {
                 $sellers[] = $orderDetail->product->user_id;
             }
         }
         foreach ($sellers as $seller) {
             //Creates a new order and address for each seller
             $newOrder = new Order();
             $newOrder->user_id = $user->id;
             $newOrder->address_id = $address->id;
             $newOrder->status = $type_order == 'freeproduct' ? 'paid' : 'open';
             $newOrder->type = $type_order == 'freeproduct' ? 'freeproduct' : 'order';
             $newOrder->seller_id = $seller;
             $newOrder->save();
             $newOrder->sendNotice();
             //moves the details to the new orders
             foreach ($cartDetail as $orderDetail) {
                 if ($orderDetail->product->user_id == $seller) {
                     $orderDetail->order_id = $newOrder->id;
                     $orderDetail->save();
                 }
                 //Increasing product counters.
                 ProductsController::setCounters($orderDetail->product, ['sale_counts' => trans('globals.product_value_counters.sale')], 'orders');
                 //saving tags in users preferences
                 if (trim($orderDetail->product->tags) != '') {
                     UserController::setPreferences('product_purchased', explode(',', $orderDetail->product->tags));
                 }
             }
         }
         //virtual products
         //Changes the stock of each product in the order
         foreach ($cartDetail as $orderDetail) {
             $product = Product::find($orderDetail->product_id);
             $product->stock = $product->stock - $orderDetail->quantity;
             $product->save();
             if ($product->type != 'item') {
                 $virtual = VirtualProduct::where('product_id', $orderDetail->product_id)->where('status', 'open')->get();
                 switch ($product->type) {
                     case 'key':
                         $first = VirtualProduct::where('product_id', $orderDetail->product_id)->where('status', 'cancelled')->first();
                         foreach ($virtual as $row) {
                             $virtualOrder = VirtualProductOrder::where('order_id', $cart->id)->where('virtual_product_id', $first->id)->where('status', 1)->first();
                             if ($virtualOrder) {
                                 $virtualOrder->virtual_product_id = $row->id;
                                 $virtualOrder->order_id = $orderDetail->order_id;
                                 $virtualOrder->status = 2;
                                 $virtualOrder->save();
                                 $row->status = 'paid';
                                 $row->save();
                             } else {
                                 break;
                             }
                         }
                         break;
                     default:
                         break;
                 }
             }
         }
         foreach ($seller_email as $email) {
             $mailed_order = Order::where('id', $newOrder->id)->with('details')->get()->first();
             //Send a mail to the user: Order has been placed
             $data = ['orderId' => $newOrder->id, 'order' => $mailed_order];
             //dd($data['order']->details,$newOrder->id);
             $title = trans('email.new_order_for_user.subject') . " (#{$newOrder->id})";
             Mail::queue('emails.neworder', compact('data', 'title'), function ($message) use($user) {
                 $message->to($user->email)->subject(trans('email.new_order_for_user.subject'));
             });
             //Send a mail to the seller: Order has been placed
             $title = trans('email.new_order_for_seller.subject') . " (#{$newOrder->id})";
             Mail::queue('emails.sellerorder', compact('data', 'title'), function ($message) use($email) {
                 $message->to($email)->subject(trans('email.new_order_for_seller.subject'));
             });
         }
         return;
     } else {
         return trans('store.insufficientFunds');
     }
 }