public function userbookToOrder($userbook, $_save = true) { $getBook = !is_object($userbook) ? \Veer\Models\UserBook::find($userbook) : $userbook; if (is_object($getBook)) { $this->order->userbook_id = $getBook->id; $this->order->country = $getBook->country; $this->order->city = $getBook->city; $this->order->address = trim($getBook->postcode . ' ' . $getBook->address); if ($_save) { $this->order->save(); } } return $this; }
/** * update or create new user book (or office address) * @param type $book */ public function updateOrNewBook($book, $pretend = false) { if ($pretend == false) { \Event::fire('router.filter: csrf'); } \Eloquent::unguard(); if (isset(app('veer')->administrator_credentials)) { $usersId = array_get($book, 'fill.users_id', \Auth::id()); if (empty($usersId)) { $usersId = \Auth::id(); } } else { $usersId = \Auth::id(); } $book['fill']['users_id'] = $usersId; $b = empty($book['bookId']) ? new \Veer\Models\UserBook() : \Veer\Models\UserBook::firstOrNew(['id' => $book['bookId']]); if (empty($book['fill']['address'])) { return false; } if (isset($book['fill'])) { $b->fill($book['fill']); } $b->primary = array_get($book, 'checkboxes.primary', false) ? true : false; $b->office_address = array_get($book, 'checkboxes.office_address', false) ? true : false; if ($pretend == false) { $b->save(); } return $b; }
/** * delete Book * @param int $id * @todo relations */ protected function deleteUserBook($id) { \Veer\Models\UserBook::where('id', '=', $id)->delete(); return true; }
/** * make Order */ protected function makeOrder() { $cart = $this->showUser->getUserCart(app('veer')->siteId, \Auth::id(), app('session')->getId()); // rules if (\Auth::id() <= 0 && \Input::get('email') == null || $cart->count() <= 0) { \Session::flash('errorMessage', \Lang::get('veershop.order.error')); return \Redirect::route('user.cart.show'); } $grouped = app('veershop')->regroupShoppingCart($cart); $book = null; if (\Input::get('userbook_id') != null) { $book = \Veer\Models\UserBook::find(\Input::get('userbook_id')); } if (\Input::get('book.address') != null) { $book = app('veershop')->updateOrNewBook(\Input::get('book')); } list($order, $checkDiscount, $calculations) = app('veershop')->prepareOrder($grouped, $book, \Input::get('shipping_id'), \Input::get('payment_id'), false); $statusName = \Veer\Models\OrderStatus::where('id', '=', $order->status_id)->pluck('name'); \Veer\Models\OrderHistory::create(array("orders_id" => $order->id, "status_id" => $order->status_id, "name" => !empty($statusName) ? $statusName : '', "comments" => "")); $order->save(); if (isset($checkDiscount) && is_object($checkDiscount)) { app('veershop')->changeUserDiscountStatus($checkDiscount); } //app('veershop')->sendEmailOrderNew($order); // clear cart $this->showUser->getUserLists(app('veer')->siteId, \Auth::id(), app('session')->getId(), '[basket]', false)->delete(); \Session::put('successfulOrder', $order->id); return \Redirect::route('order.success'); }