Example #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]);
         }
     }
 }
Example #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
     }
 }
Example #3
0
 public function myAddressDetail($domain, $id, Request $request)
 {
     $userService = new userService();
     $addressService = new addressService();
     try {
         $user = $userService->getUserByEmail($this->_user->email);
         $address = $addressService->getAddressReceiveById($id);
         $data['listCity'] = $addressService->getListCity();
         $data['listDistrict'] = $addressService->getListDistrict();
         $data['user'] = $user;
         if (!$address || $address->user_id != $user->id) {
             $data['permission_denied'] = true;
             $data['permission_denied_message'] = 'bạn không có quyền chỉnh sữa địa chỉ này - liên hệ admin : admin@kacana.com';
             return view('client.customer.my-address-detail', $data);
         }
         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);
             $addressArray['id'] = $id;
             if ($id) {
                 $data['address'] = $addressService->updateAddressReceive($addressArray);
                 $data['ok'] = 1;
                 $data['ok_message'] = 'cập nhật địa chỉ: ' . $addressArray['name'] . ' thành công!';
             } else {
                 $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!';
             }
         } elseif ($request->isMethod('get')) {
             $data['address'] = $address;
         }
         return view('client.customer.my-address-detail', $data);
     } catch (\Exception $e) {
         return view('errors.404', ['error_message' => $e->getMessage()]);
     }
 }