示例#1
0
 public function edit($domain, Request $request, $code)
 {
     $orderService = new orderService();
     $addressService = new addressService();
     $shipService = new shipService();
     try {
         $order = $orderService->getOrderByOrderCode($code);
         $id = $order->id;
         if ($order->user_id != $this->_user->id) {
             return redirect('/order');
         }
         if ($request->isMethod('PUT')) {
             if ($order->user_id == $this->_user->id && $order->status == KACANA_ORDER_PARTNER_STATUS_NEW) {
                 $addressService->updateAddressReceive($request->all());
             }
         }
         $buyer = $order->user;
         $user_address = $order->addressReceive;
         $hubInfos = $shipService->getPickHubs();
         $mainHub = $shipService->getPickHubMain($hubInfos);
         $serviceList = $shipService->getServiceList($user_address->district->code, $mainHub->DistrictCode);
         $shippingServiceInfos = $shipService->calculateServiceFee($user_address->district->code, $mainHub->DistrictCode, $serviceList);
         $cities = $addressService->getListCity()->lists('name', 'id');
         $wards = $addressService->getListWardByDistrictId($user_address->district_id);
         $districts = $addressService->getListDistrict();
         return view('partner.order.edit', compact('order', 'buyer', 'user_address', 'cities', 'districts', 'wards', 'shippingServiceInfos', 'hubInfos'));
     } catch (\Exception $e) {
         if ($request->ajax()) {
             $result['error'] = $e->getMessage();
             return $result;
         } else {
             return view('errors.404', ['error_message' => $e]);
         }
     }
 }
示例#2
0
 public function edit($domain, Request $request, $addressId)
 {
     $addressService = new addressService();
     try {
         $address = $addressService->getAddressReceiveById($addressId);
         $cities = $addressService->getListCity()->lists('name', 'id');
         $wards = $addressService->getListWardByDistrictId($address->district_id);
         $districts = $addressService->getListDistrict();
         if ($address->user_id != $this->_user->id) {
             throw new \Exception('Address is inValid!');
         }
         if ($request->isMethod('PUT')) {
             $addressService->updateAddressReceive($request->all());
         }
         return view('partner.customer.edit', ['user_address' => $address, 'cities' => $cities, 'districts' => $districts, 'wards' => $wards]);
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $return['error'] = $e->getMessage();
         $return['errorMsg'] = $e->getMessage();
         // @codeCoverageIgnoreEnd
     }
 }
示例#3
0
 public function addNewAddressReceive(Request $request)
 {
     $userService = new userService();
     $addressService = new addressService();
     try {
         $user = $userService->getUserByEmail($this->_user->email);
         $data['listCity'] = $addressService->getListCity();
         $data['listDistrict'] = $addressService->getListDistrict();
         $data['user'] = $user;
         if ($request->isMethod('post')) {
             $addressArray = array();
             $addressArray['name'] = $request->get('name', false);
             $addressArray['street'] = $request->get('street', false);
             $addressArray['city_id'] = $request->get('cityId', false);
             $addressArray['district_id'] = $request->get('districtId', false);
             $addressArray['ward_id'] = $request->get('wardId', false);
             $addressArray['phone'] = $request->get('phone', false);
             $data['address'] = $addressService->createUserAddress($user->id, $addressArray);
             $data['ok'] = 1;
             $data['ok_message'] = 'thêm mới địa chỉ: ' . $addressArray['name'] . ' thành công!';
             return redirect('/khach-hang/so-dia-chi');
         }
         return view('client.customer.my-address-detail', $data);
     } catch (\Exception $e) {
         return view('errors.404', ['error_message' => $e->getMessage()]);
     }
 }
示例#4
0
 public function printOrder(Request $request)
 {
     $orderService = new orderService();
     $addressService = new addressService();
     $shipService = new shipService();
     $shippingId = $request->input('id');
     try {
         $ship = $shipService->getShippingById($shippingId);
         $user_address = $ship->addressReceive;
         $cities = $addressService->getListCity()->lists('name', 'id');
         $districts = $addressService->getListDistrict();
         $origin_total = 0;
         $discount = 0;
         foreach ($ship->orderDetail as $orderDetail) {
             $origin_total += $orderDetail->price * $orderDetail->quantity;
             $discount += $orderDetail->discount;
         }
         $ship->origin_total = $origin_total;
         $ship->discount = $discount;
         return view('admin.shipping.print_order', compact('ship', 'user_address'));
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $return['error'] = $e->getMessage();
         $return['errorMsg'] = $e->getMessage();
         // @codeCoverageIgnoreEnd
     }
 }
示例#5
0
 public function index(Request $request)
 {
     $cartService = new cartService();
     $addressService = new addressService();
     $userService = new userService();
     $step = $request->get('step', 'login');
     $data = array();
     try {
         $key = '__kacana_user_order__';
         if (\Kacana\Util::isLoggedIn()) {
             $user = $userService->getUserByEmail($this->_user->email);
             if ($step != 'address' && count($user->userAddress)) {
                 $step = 'choose-address';
             } else {
                 $step = 'address';
             }
             \Session::set($key, ['email' => $this->_user->email]);
             $data['user'] = $user;
         }
         $data['step'] = $step;
         $cart = $cartService->cartInformation();
         if (!$cart) {
             return redirect('/thanh-toan');
         }
         $data['cart'] = $cart;
         $key = '__kacana_user_order__';
         $userOrder = \Session::get($key);
         if ($userOrder) {
             $data['userOrder'] = $userOrder;
         }
         if ($step == 'address' && ($request->isMethod('post') || isset($userOrder['email']))) {
             $data['listCity'] = $addressService->getListCity();
             $data['listDistrict'] = $addressService->getListDistrict();
             $data['listWard'] = $addressService->getListWard();
             $email = $request->input('email', false);
             if (isset($userOrder['email']) && !$email) {
                 // if refresh page - will check session userOrder
                 $email = $userOrder['email'];
             }
             $password = $request->input('password', false);
             if ($password && isEmailAdress($email)) {
                 return view('client.checkout.checkout', $data);
             } elseif ($email && isEmailAdress($email)) {
                 if (!isset($userOrder)) {
                     $userOrder = array();
                 }
                 $userOrder['email'] = $email;
                 \Session::set($key, $userOrder);
             } else {
                 $data['errorMessage'] = 'Email không đúng định dạng';
             }
         }
     } catch (\Exception $e) {
         if ($request->ajax()) {
             $result['error'] = $e->getMessage();
             return $result;
         } else {
             return view('errors.404', ['error_message' => $e]);
         }
     }
     return view('client.checkout.checkout', $data);
 }