Example #1
0
 public function generateAddressReceiveByUserId($request, $userId)
 {
     $datatables = new DataTables();
     $viewHelper = new ViewGenerateHelper();
     $columns = array(array('db' => 'address_receive.id', 'dt' => 0), array('db' => 'address_receive.name AS customer_name', 'dt' => 1), array('db' => 'address_receive.phone', 'dt' => 2), array('db' => 'address_receive.email', 'dt' => 3), array('db' => 'address_receive.street', 'dt' => 4), array('db' => 'address_city.name AS city_name', 'dt' => 5), array('db' => 'address_district.name AS district_name', 'dt' => 6), array('db' => 'address_receive.created', 'dt' => 7));
     $return = $this->_receiveModel->generateAddressReceiveByUserId($request, $columns, $userId);
     $return['data'] = $datatables::data_output($columns, $return['data']);
     return $return;
 }
 /**
  * @param $inputs
  * @return bool
  */
 public function updateAddress($inputs)
 {
     $id = isset($inputs['id']) ? $inputs['id'] : '';
     if ($id != '') {
         $add_receive = addressReceiveModel::find($id);
         $add_receive->street = $inputs['street'];
         $add_receive->city_id = $inputs['city_id'];
         $add_receive->ward_id = $inputs['ward_id'];
         if ($add_receive->save()) {
             return true;
         }
     }
     return false;
 }
Example #3
0
 /**
  * @param CartRequest $request
  */
 public function processCart(CartRequest $request)
 {
     $re = array();
     if (Request::isMethod('post') && $request->all()) {
         //save user
         $user = new User();
         $uid = 0;
         $username = "";
         $email = "";
         $existUser = $user->getUserByEmail($request->get('email'));
         if (!empty($existUser)) {
             $uid = $existUser->id;
             $username = $existUser->name;
             $email = $existUser->email;
         } else {
             $item = array('name' => $request->get('name'), 'email' => $request->get('email'), 'phone' => $request->get('phone'), 'role' => BUYER);
             $createdUser = $user->createItem($item);
             $uid = $createdUser->id;
             $username = $createdUser->name;
             $email = $createdUser->email;
         }
         //save address receive
         $userReceive = new addressReceiveModel();
         $item2 = array('name' => $request->get('name_2'), 'phone' => $request->get('phone_2'), 'street' => $request->get('street'), 'city_id' => $request->get('city_id'), 'ward_id' => $request->get('ward_id'));
         $address = $userReceive->createItem($item2);
         if ($uid != 0 && $address) {
             //create user address
             $userAddress = new UserAddress();
             $option = array('user_id' => $uid, 'address_id' => $address->id);
             $userAddress->createItem($option);
             //create order and order detail
             $order = new Order();
             $orderAtt = array('user_id' => $uid, 'address_id' => $address->id, 'total' => Cart::total(), 'ship' => 0, 'address' => $address->street . ", " . addressWardModel::showName($address->ward_id) . ", " . addressCityModel::showName($address->city_id));
             $createdOrder = $order->createItem($orderAtt);
             $orderDetail = new OrderDetail();
             if ($orderDetail->createItems($createdOrder->id, Cart::content())) {
                 //send email
                 $data = array('username' => $username, 'linkWebsite' => SITE_LINK, 'receiveName' => $address->name, 'receiveAddress' => $createdOrder->address, 'receivePhone' => $address->phone, 'carts' => Cart::content(), 'total' => Cart::total());
                 Cart::destroy();
                 if ($this->sendEmailOrder($email, $username, $data)) {
                     $re = array('status' => 'ok', 'id' => $createdOrder->id);
                 } else {
                     $re = array('status' => 'error', 'message' => 'Bị lỗi trong quá trình gửi mail');
                 }
             }
         }
         echo json_encode($re);
     }
 }
Example #4
0
 public function editUserAddress(addressReceiveModelRequest $request)
 {
     $id = $request->get('id');
     $address = addressReceiveModel::find($id);
     $result = $address->updateItem($id, $request->all());
     echo json_encode($result);
 }