public function edit($id, UserRepository $userRepository) { $listStatus = [0 => 'Pendente', 1 => 'A Caminho', 2 => 'Entregue']; $order = $this->orderRepository->find($id); $deliveryMan = $userRepository->getDeliverymen(); return view('admin.orders.edit', compact('order', 'listStatus', 'deliveryMan')); }
public function create(array $data) { DB::beginTransaction(); try { $data['status'] = 0; if (isset($data['cupom_code'])) { $cupom = $this->cupomRepository->findByField('code', $data['cupom_code'])->first(); $data['cupom'] = $cupom->id; $cupom->used = 1; $cupom->save(); unset($data['cupom_code']); } $items = $data['items']; unset($data['items']); $order = $this->orderRepository->create($data); $total = 0; foreach ($items as $item) { $item['price'] = $this->productRepository->find($item['product_id'])->price; $order->items()->create($item); $total += $item['price'] * $item['qtd']; } $order->total = $total; if (isset($cupom)) { $order->total = $total - $cupom->value; } $order->save(); \DB::commit(); } catch (\Exception $e) { \DB::rollback(); throw $e; } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $order = $this->orderRepository->with(['client', 'items', 'cupom'])->find($id); $order->items->each(function ($item) { $item->product; }); return $order; }
public function index() { $clientId = $this->userRepository->find(Auth::user()->id)->client->id; $orders = $this->repository->scopeQuery(function ($query) use($clientId) { return $query->where('client_id', '=', $clientId); })->paginate(); return view('customer.order.index', compact('orders')); }
public function show($id) { // $o = $this->orderRepository->with(['client', 'items', 'cupom'])->find($id); // $o = $this->orderRepository->skipPresenter()->with(['client', 'items', 'cupom'])->find($id); /* $o->items->each(function($item){ $item->product; }); */ return $this->orderRepository->skipPresenter(false)->with($this->with)->find($id); }
public function store(CheckoutRequest $request) { $data = $request->all(); $id = Authorizer::getResourceOwnerId(); $clientId = $this->userRepository->find($id)->client->id; $data['client_id'] = $clientId; $order = $this->orderService->create($data); return $this->orderRepository->skipPresenter(false)->find($order->id); }
public function updateStatus(Request $request, $id) { $idDeliveryman = Authorizer::getResourceOwnerId(); $order = $this->service->updateStatus($id, $idDeliveryman, $request->get('status')); if ($order) { return $this->orderRepository->find($id); } abort(400, "Order não encontrada!"); }
public function geo(Request $request, Geo $geo, $id) { $idDeliveryman = Authorizer::getResourceOwnerId(); $order = $this->orderRepository->getByIdAndDeliveryman($id, $idDeliveryman); $geo->lat = $request->get('lat'); $geo->long = $request->get('long'); event(new GetLocationDeliveryMan($geo, $order)); return $geo; }
public function updateStatus(Request $request, $order_id) { $deliveryman_id = Authorizer::getResourceOwnerId(); $order = $this->service->updateStatus($order_id, $deliveryman_id, $request->get('status')); if ($order) { return $this->repository->find($order->id); } abort(400, 'Order não encontrada'); }
public function show($id) { #$order = $this->repository->with(['items', 'client', 'cupom'])->find($id); /*$order->items->each(function($item){ $item->product; });*/ #comentado devido a utilização do presenter #return $order; return $this->repository->skipPresenter(false)->with($this->with)->find($id); }
public function updateStatus($id, $idDeliveryman, $status) { $order = $this->orderRepository->getByIdAndDeliveryman($id, $idDeliveryman); if ($order instanceof Order) { $order->status = $status; $order->save(); return $order; } return false; }
public function show($id) { /* Sem o Presenter e Transformer $o = $this->repository->with(['client','items','cupom'])->find($id); $o->items->each(function($item){ $item->product; }); */ return $this->repository->skipPresenter(false)->with($this->with)->find($id); }
public function updateStatus($id, $idDeliveryman, $status) { $order = $this->orderRepository->getByIdAndDeliveryman($id, $idDeliveryman); $order->status = $status; if ((int) $order->status == 1 && !$order->hash) { $order->hash = md5((new \DateTime())->getTimestamp()); } $order->save(); return $order; }
public function create(array $data) { //inicia todas as transções //isso é para não utilizar a conexão com o banco a todo o momento //porém dessa maneira cria um acoplamento, mas pode ser utilizado no construct //passando a instacia do BD \DB::beginTransaction(); try { //forçamos o pedido para sempre ter o status 0 quando criado $data['status'] = 0; //checagem para verificar se existe cupom de desconto if (isset($data['cupom_code'])) { // ?? $cupom = $this->cupomRepository->findByField('code', $data['cupom_code'])->first(); //determinamos que o cupom_id é igual ao o id do cupom $data['cupom_id'] = $cupom->id; $cupom->used = 1; //para salvar no banco de dados $cupom->save(); //para não tentar persistir os dados quando colocar o data no array unset($data['cupom_code']); } //prepara os dados do item para isenrir no banco $items = $data['items']; // unset($data['items']); $order = $this->orderRepository->create($data); $total = 0; foreach ($items as $item) { //buscamos o product_id do formulario e consulta no banco o preço $item['price'] = $this->productRepository->find($item['product_id'])->price; //adiciona o item na ordem de serviço $order->items()->create($item); //gravamos o valor final $total += $item['price'] * $item['qtd']; } $order->total = $total; //se utilizar um cupom de desconto if (isset($cupom)) { //pegamos o total e subrtraiomos o valor de desconto do cupom $order->total = $total - $cupom->value; } //salva os dados $order->save(); //comita para gravar \DB::commit(); //caso não deu certo } catch (\Exception $e) { //não grava os dados \DB::rollback(); throw $e; } }
public function show($id) { /* Método 1 $order = $this->orderRepository ->with(['client','items.product','cupom']) - Método 1 ->find($id); Método alternativo de fazer a mesma coisa (exibir os produtos) - Método 2 $order->items->each(function($item){ $item->product; }); */ // Método com presenters return $this->orderRepository->skipPresenter(false)->with($this->with)->find($id); }
public function updateStatus($orderId, $deliverymanId, $status) { $order = $this->orderRepository->getByIdAndDeliveryman($orderId, $deliverymanId); $order->status = $status; switch ((int) $status) { case 1: if (!$order->hash) { $order->hash = md5((new \DateTime())->getTimestamp()); } $order->save(); break; case 2: $user = $order->client->user; $this->pushProcessor->notify([$user->device_token], ['alert' => "Seu pedido #{$order->id} acabou de ser entregue."]); $order->save(); break; } return $order; }
public function updateStatus(Request $request, $id) { $idDeliveryman = \Authorizer::getResourceOwnerId(); $order = $this->service->updateStatus($id, $idDeliveryman, $request->get('status')); return $order ? $this->repository->find($order->id) : abort(400, 'Order not found!'); }
public function show($id) { $idUser = Authorizer::getResourceOwnerId(); return $this->orderRepository->skipPresenter(false)->with($this->whith)->find($id); }
public function show($id) { $order = $this->repository->skipPresenter(false)->with($this->with)->find($id); return $order; }
public function view($id) { $order = $this->repository->find($id); $items = $this->orderItemRepository->with('product')->findWhere(['order_id' => $id]); return view('admin.orders.view', compact('order', 'items')); }
public function show($orderId) { return $this->orderRepository->skipPresenter(false)->with($this->with)->find($orderId); }
public function update(Request $request, $id) { $all = $request->all(); $this->repository->update($all, $id); return redirect()->route('admin.orders.index'); }
public function show($id) { $idClient = Authorizer::getResourceOwnerId(); return $this->repository->skipPresenter(false)->getByIdAndClient($id, $idClient); }