function my_shipping_address_post() { $userId = $this->post('userId'); $firstName = $this->post('firstName'); $lastName = $this->post('lastName'); $countryId = $this->post('countryId'); $cityId = $this->post('cityId'); $zipId = $this->post('zipId'); $localityId = $this->post('localityId'); $phone = $this->post('phone'); $address = $this->post('address'); $productTypeId = $this->post('productTypeId'); $productTypeIdArr = explode(',', $productTypeId); $deviceType = $this->post('deviceType'); if (empty($productTypeIdArr)) { $this->response(array('error' => 'Please provide prodcut type for current user.'), 400); return FALSE; } foreach ($productTypeIdArr as $k => $v) { $newCateoryArr[] = $v; $newCateoryArr = recusive_category($newCateoryArr, $v); } //pre($newCateoryArr);die; $this->user->update_user_product_type_category(array('productTypeCateoryId' => implode(',', $newCateoryArr)), $userId); $this->user->remove_user_from_product_type($userId); foreach ($newCateoryArr as $k => $v) { $this->user->update_product_type_user($v, $userId); } $rs = $this->Country->city_details($cityId); $isAdded = $this->User_model->is_shipping_address_added(); if (empty($isAdded)) { $this->User_model->add_shipping(array('firstName' => $firstName, 'lastName' => $lastName, 'contactNo' => $phone, 'countryId' => $countryId, 'cityId' => $cityId, 'zipId' => $zipId, 'localityId' => $localityId, 'userId' => $userId, 'address' => $address, 'stateId' => $rs[0]->stateId, 'appSource' => $deviceType)); } else { $this->User_model->edit_shipping(array('firstName' => $firstName, 'lastName' => $lastName, 'contactNo' => $phone, 'countryId' => $countryId, 'cityId' => $cityId, 'zipId' => $zipId, 'localityId' => $localityId, 'address' => $address, 'stateId' => $rs[0]->stateId), $userId); } $result['message'] = "Shipping address data updated successfully."; success_response_after_post_get($result); }
function my_shipping_address_post() { $userId = $this->post('userId'); $firstName = $this->post('firstName'); $lastName = $this->post('lastName'); $countryId = $this->post('countryId'); $cityId = $this->post('cityId'); $zipId = $this->post('zipId'); $localityId = $this->post('localityId'); $phone = $this->post('phone'); $address = $this->post('address'); $productTypeId = $this->post('productTypeId'); $deviceType = $this->post('deviceType'); $latitude = $this->post('latitude'); $longitude = $this->post('longitude'); $deviceToken = $this->post('deviceToken'); $UDID = $this->post('UDID'); if ($firstName == "") { $this->response(array('error' => 'Please provide first name.'), 400); return FALSE; } if ($lastName == "") { $this->response(array('error' => 'Please provide last name.'), 400); return FALSE; } if ($countryId == "") { $this->response(array('error' => 'Please select country.'), 400); return FALSE; } if ($cityId == "") { $this->response(array('error' => 'Please select city.'), 400); return FALSE; } if ($zipId == "") { $this->response(array('error' => 'Please select zip.'), 400); return FALSE; } if ($localityId == "") { $this->response(array('error' => 'Please select location.'), 400); return FALSE; } if ($phone == "") { $this->response(array('error' => 'Please provide phone number.'), 400); return FALSE; } if ($address == "") { $this->response(array('error' => 'Please provide address.'), 400); return FALSE; } if (trim($productTypeId) == "") { $this->response(array('error' => 'Please select product type.'), 400); return FALSE; } $defaultDataArr = array('UDID' => $UDID, 'deviceType' => $deviceType, 'deviceToken' => $deviceToken, 'latitude' => $latitude, 'longitude' => $longitude); $isValideDefaultData = $this->check_default_data($defaultDataArr); if ($isValideDefaultData['type'] == 'fail') { $this->response(array('error' => $isValideDefaultData['message']), 400); return FALSE; } $user = $this->user->get_details_by_id($userId); if (empty($user)) { $this->response(array('error' => 'Please provide valid user index.'), 400); return FALSE; } $productTypeIdArr = explode(',', $productTypeId); if ($productTypeIdArr[0] == "") { unset($productTypeIdArr[0]); } if (end($productTypeIdArr) == "") { array_pop($productTypeIdArr); } if (empty($productTypeIdArr)) { $this->response(array('error' => 'Please provide prodcut type for current user.'), 400); return FALSE; } foreach ($productTypeIdArr as $k => $v) { $rs = $this->db->from('category')->where('categoryId', $v)->get()->result_array(); if (count($rs) == 0) { $this->response(array('error' => 'Invalid product type id.'), 400); return FALSE; } $newCateoryArr[] = $v; $newCateoryArr = recusive_category($newCateoryArr, $v); } //pre($newCateoryArr);die; $this->user->update_user_product_type_category(array('productTypeCateoryId' => implode(',', $newCateoryArr)), $userId); $this->user->remove_user_from_product_type($userId); foreach ($newCateoryArr as $k => $v) { $this->user->update_product_type_user($v, $userId); } $rs = $this->Country->city_details($cityId); $isAdded = $this->user->is_shipping_address_added($userId); if (empty($isAdded)) { $this->user->add_shipping(array('firstName' => $firstName, 'lastName' => $lastName, 'contactNo' => $phone, 'countryId' => $countryId, 'cityId' => $cityId, 'zipId' => $zipId, 'localityId' => $localityId, 'userId' => $userId, 'address' => $address, 'stateId' => $rs[0]->stateId, 'appSource' => $deviceType)); } else { $this->user->edit_shipping(array('firstName' => $firstName, 'lastName' => $lastName, 'contactNo' => $phone, 'countryId' => $countryId, 'cityId' => $cityId, 'zipId' => $zipId, 'localityId' => $localityId, 'address' => $address, 'stateId' => $rs[0]->stateId), $userId); } $result['message'] = "Shipping address data updated successfully."; success_response_after_post_get($result); }
function recusive_category($newCateoryArr, $categoryId) { $CI =& get_instance(); $CI->load->model('Category_model', 'category'); $chieldCateArr = $CI->category->get_subcategory_by_category_id($categoryId); if (empty($chieldCateArr)) { return $newCateoryArr; } else { foreach ($chieldCateArr as $k) { $newCateoryArr[] = $k->categoryId; $newCateoryArr = recusive_category($newCateoryArr, $k->categoryId); } return $newCateoryArr; } }