public function updateStateOrder(Request $request) { $ids = $request->input('ids'); $sync = []; foreach ($ids as $id) { $sync[$id] = ['state_order_id' => $request->input('state')]; } Order::find($request->input('order'))->products()->sync($sync, false); return ['success' => 1]; }
public function insertPayResult($inputs) { $data = []; /*foreach (Session::get('cart') as $item) { if(!$item->offers) $value = $item->price; else $value = (Carbon::now()->between(new Carbon($item->offers->offer_on), new Carbon($item->offers->offer_off))) ? $item->offers->offer_price : $item->price; $data[$item->id] = ['quantity' => $item->quantity, 'state_order_id' => 2, 'value' => $value]; }*/ $user = User::where('identification', $inputs['id_cliente'])->first(); $order = Order::create(['identification_client' => $inputs['id_cliente'], 'user_id' => $user->id, 'address_client' => $inputs['campo1'], 'zp_buy_id' => $inputs['id_pago'], 'zp_buy_token' => $inputs['ticketID'], 'zp_state' => $inputs['estado_pago']]); $user->orders()->save($order); $order->products()->attach($data); if ($inputs['estado_pago']) { Session::forget('cart'); Session::forget('valueTotal'); } }
public function showBackProvider() { $user = Auth::user(); $orders = Order::whereHas('products', function ($query) use($user) { $query->where('products.user_id', $user->id); })->with(['products' => function ($q) use($user) { $q->where('products.user_id', $user->id)->with('offers'); }, 'user'])->get(); foreach ($orders as $order) { $order->quantityProducts = count($order->products); $order->totalValueProducts = 0; foreach ($order->products as $product) { $value = 0; foreach ($order->products as $product) { $value += $product->totalValue = $product->pivot->value * $product->pivot->quantity; } $order->total = $value; } } $states = StateOrder::lists('id', 'name'); return view('back.ordersProvider', compact('orders', 'states')); }