Example #1
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
     }
 }
Example #2
0
 /**
  *  edit product
  *
  * @param $domain
  * @param $id
  * @param Request $request
  * @return \BladeView|bool|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
  */
 public function editProduct($domain, $id, Request $request)
 {
     $productService = new productService();
     $addressService = new addressService();
     $productGalleryModel = new productGalleryModel();
     $tagService = new tagService();
     $results = [];
     try {
         if ($request->isMethod('post')) {
             $productService->updateProduct($request->all(), $id);
             return redirect('/product/editProduct/' . $id)->with('success', 'Cập nhật sản phẩm thành công!');
         }
         $results['product'] = $productService->getProductById($id, 0, false);
         $results['tagColor'] = $tagService->getColorTag();
         $results['groupTag'] = $tagService->getTagGroup();
         $results['tagSize'] = $tagService->getSizeTag();
         $results['tagStyle'] = $tagService->getStyleTag();
         $results['countries'] = $addressService->getListCountry();
         $results['images'] = $productGalleryModel->getImagesProductByProductId($id);
         return view('admin.product.edit-product', $results);
     } catch (\Exception $e) {
         if ($request->ajax()) {
             $result['error'] = $e->getMessage();
             return $result;
         } else {
             return view('errors.404', ['error_message' => $e->getMessage()]);
         }
     }
 }
Example #3
0
 /**
  *
  * create new order
  *
  * @param $userId
  * @param $addressId
  * @param $total
  * @param $discount
  * @param $originTotal
  * @param $quantity
  * @param int $status
  * @return orderModel
  */
 public function createOrder($userId, $addressId, $total = 0, $quantity = 0, $originTotal = 0, $discount = 0, $status = KACANA_ORDER_STATUS_NEW)
 {
     $address = $this->_addressService->getAddressReceiveById($addressId);
     $addressStr = $address->street;
     $orderData = new \stdClass();
     $orderData->user_id = $userId;
     $orderData->address_id = $addressId;
     $orderData->total = $total;
     $orderData->quantity = $quantity;
     $orderData->discount = $discount;
     $orderData->origin_total = $originTotal;
     $orderData->status = $status;
     $orderData->address = $addressStr . ', ' . $address->district->name . ', ' . $address->city->name;
     $order = $this->_orderModel->createItem($orderData);
     $this->_orderModel->updateItem($order->id, ['order_code' => crc32($order->id)]);
     $order->order_code = crc32($order->id);
     return $order;
 }
Example #4
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 #5
0
 public function getWardByDistrictId(Request $request)
 {
     $addressService = new addressService();
     $districtId = $request->input('districtId');
     $result['ok'] = 0;
     try {
         $result['data'] = $addressService->getListWardByDistrictId($districtId);
         $result['ok'] = 1;
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $result['error'] = $e->getMessage();
         // @codeCoverageIgnoreEnd
     }
     return response()->json($result);
 }
Example #6
0
 public function processCart($order)
 {
     $addressService = new addressService();
     $userService = new userService();
     $orderService = new orderService();
     $cart = $this->cartInformation();
     if (!$cart) {
         throw new \Exception('bad Cart items');
     }
     if (!$order['email']) {
         throw new \Exception('bad email');
     }
     if (!$order['name']) {
         throw new \Exception('bad user name');
     }
     if (!$order['street']) {
         throw new \Exception('bad street');
     }
     if (!$order['city_id']) {
         throw new \Exception('bad cityId');
     }
     if (!$order['district_id']) {
         throw new \Exception('bad districtId');
     }
     if (!$order['ward_id']) {
         throw new \Exception('bad ward_id');
     }
     if (!$order['phone']) {
         throw new \Exception('bad phone number');
     }
     // check user if exists - we not create new user
     $user = $userService->getUserByEmail($order['email']);
     if (!$user) {
         $order['role'] = KACANA_USER_ROLE_BUYER;
         $order['status'] = KACANA_USER_STATUS_CREATE_BY_SYSTEM;
         $user = $userService->createUser($order);
     }
     $addressDefault = 1;
     if (count($user->userAddress)) {
         $addressDefault = 0;
     }
     // create new address for user
     $addressReceive = $addressService->createUserAddress($user->id, $order, $addressDefault);
     // create new order for user
     $order = $orderService->createOrder($user->id, $addressReceive->id, $cart->total, $cart->quantity, $cart->originTotal, $cart->discount);
     $items = $cart->items;
     foreach ($items as $item) {
         $orderService->createOrderDetail($order->id, $item);
     }
     // destroy CART
     Cart::destroy();
     //send email for user
     $mailService = new mailService();
     if ($mailService->sendEmailOrder($user->email, $order->id)) {
         return $order;
     } else {
         throw new \Exception('Bị lỗi trong quá trình gửi mail');
     }
     // send zalo message for user
     return $order;
 }
Example #7
0
 /**
  *generate city and district for database
  *
  *
  */
 public function createAddressFromApi()
 {
     $results = $this->GetDistrictProvinceData();
     $adressService = new addressService();
     $arrayCity = [];
     $arrayCitys = [];
     foreach ($results as $result) {
         if (!in_array($result->ProvinceCode, $arrayCity)) {
             $city = $adressService->createCity($result->ProvinceName, KACANA_SHIP_TYPE_SERVICE_GHN, $result->ProvinceCode);
             array_push($arrayCity, $result->ProvinceCode);
             $arrayCitys[$result->ProvinceCode] = $city->id;
         }
         $adressService->createDistrict($result->DistrictName, $arrayCitys[$result->ProvinceCode], $result->DistrictCode, KACANA_SHIP_TYPE_SERVICE_GHN);
     }
 }
Example #8
0
 public function generateAddressReceiveByUserId($domain, $userId, Request $request)
 {
     $addressService = new addressService();
     $params = $request->all();
     try {
         $return = $addressService->generateAddressReceiveByUserId($params, $userId);
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $return['error'] = $e->getMessage();
         $return['errorMsg'] = $e->getMessage();
         // @codeCoverageIgnoreEnd
     }
     return response()->json($return);
 }
Example #9
0
 public function deleteMyAddress($domain, $id, Request $request)
 {
     $userService = new userService();
     $addressService = new addressService();
     try {
         $user = $userService->getUserByEmail($this->_user->email);
         $address = $addressService->getAddressReceiveById($id);
         if (!$address || $address->user_id != $user->id || $address->default) {
             return redirect('/khach-hang/so-dia-chi');
         }
         $addressService->deleteMyAddress($user->id, $id);
         return redirect('/khach-hang/so-dia-chi');
     } catch (\Exception $e) {
         return view('errors.404', ['error_message' => $e->getMessage()]);
     }
 }
Example #10
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);
 }