public function store(Order $order, OrderRequest $request) { if (!$order->isAuthorized()) { return redirect(route('orders.show', [$order->id]))->with('error', 'You cant add products to that order'); } DB::transaction(function () use($order, $request) { $id = $request->get('product_id'); $quantity = $request->get('quantity'); $order->products()->attach([$id => ['quantity' => $quantity]]); //todo increase same if ($order->status != 1) { $product = Product::find($id); $product->update(['quantity' => $product->quantity - $quantity]); } }); return redirect(route('orders.edit', [$order->id]))->with('success', 'Product successfully added'); }
public function handle(Requests\OrderRequest $request, Product $product, $id) { $product = $product->where('id', $id)->first(); if ($product !== null) { $quantity = 1; if ($product->countable == true) { $quantity = $request->get('quantity'); } // TODO вынести обработку steam id в отдельный класс или в Request // Нужно полученый STEAM ID проверить в зависимости от игры $steam_id = $request->get('steam_id'); $server = Server::where('id', $product->server_id)->first(); switch ($server->engine) { case 1: if (preg_match("/\\[U:1:(\\d+)\\]/", $steam_id)) { $steam_id = preg_replace("/\\[U:1:(\\d+)\\]/", "\$1", $steam_id); $A = $steam_id % 2; $B = intval($steam_id / 2); $steam_id = "STEAM_0:" . $A . ":" . $B; } break; } //======= $order = new Order(); $order->product_id = $product->id; $order->quantity = $quantity; $order->sum = intval($product->discount_price * $quantity); $order->email = $request->get('email'); $order->steam_id = $steam_id; $order->status = 0; $order->save(); $payment = new Payment(config('robokassa.login'), config('robokassa.paymentPassword'), config('robokassa.validationPassword')); $payment->setInvoiceId($order->id)->setSum($order->sum)->setDescription('Покупка ' . $product->title); return redirect($payment->getPaymentUrl()); } return redirect()->route('shop.index'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(OrderRequest $request, $id) { //status_order if ($request->get('status_order') == true) { $status_order = 1; } else { $status_order = 0; } //amount_order $product = Product::find($request->get('product_id')); // $amount_order =$request->get('qty')*$product->price; $data = ['transaction_id' => $request->get('transaction_id'), 'product_id' => $request->get('product_id'), 'qty' => $request->get('qty'), 'note' => $request->get('note'), 'price_order' => $product->price, 'discount_order' => $product->discount, 'status_order' => $status_order]; $order = Order::find($id); $order->update($data); $this->update_transaction($data['transaction_id']); //update amount transaction. return redirect()->route('order.index'); }