- Completed Apply Coupon Functionality
- Made a selection for the coupon selected, also added no coupon found when coupon is not there - Added Masila view in more section - Added Play trailer from Manila in more section - Gave other connectivity
This commit is contained in:
@@ -15,6 +15,7 @@ class CartPaymentOptionsVM{
|
||||
var couponData = [CouponListDM.ResultData]()
|
||||
var isExpanded = false
|
||||
var cartTotalPrice = 0.0
|
||||
var couponCodeSelected = ""
|
||||
|
||||
func initView(){
|
||||
vc.couponCodeTF.roundCorner()
|
||||
@@ -23,6 +24,8 @@ class CartPaymentOptionsVM{
|
||||
setupCell()
|
||||
updateCart()
|
||||
getCouponAndOffers()
|
||||
|
||||
self.vc.totalCartPrice.text = K.ConstantString.rupeeSign + " " + cartTotalPrice.toString()
|
||||
}
|
||||
|
||||
func setupCell(){
|
||||
@@ -44,12 +47,11 @@ class CartPaymentOptionsVM{
|
||||
}
|
||||
|
||||
func updateCart(){
|
||||
self.vc.cartTableView.reloadData()
|
||||
self.vc.cartTableHeight.constant = self.vc.cartTableView.contentSize.height + 100
|
||||
self.vc.cartTableView.layoutIfNeeded()
|
||||
self.vc.cartTableHeight.constant = self.vc.cartTableView.contentSize.height
|
||||
|
||||
self.vc.totalCartPrice.text = K.ConstantString.rupeeSign + " " + self.cartTotalPrice.toString()
|
||||
guard let self = self.vc else{return}
|
||||
self.cartTableView.reloadData()
|
||||
self.cartTableHeight.constant = self.cartTableView.contentSize.height + 1000
|
||||
self.cartTableView.layoutIfNeeded()
|
||||
self.cartTableHeight.constant = self.cartTableView.contentSize.height
|
||||
}
|
||||
|
||||
// MARK: - Get SuperCategory
|
||||
@@ -70,12 +72,13 @@ class CartPaymentOptionsVM{
|
||||
Error
|
||||
*/
|
||||
Utilities.dismissProgressHUD()
|
||||
|
||||
self.vc.noCouponFound.isHidden = false
|
||||
case 1:
|
||||
Utilities.dismissProgressHUD()
|
||||
guard let data = data.data?.result else{return}
|
||||
self.couponData = data
|
||||
|
||||
self.vc.noCouponFound.isHidden = true
|
||||
|
||||
self.vc.couponTableView.reloadData()
|
||||
self.vc.couponTableHeght.constant = self.vc.couponTableView.contentSize.height + 100
|
||||
self.vc.couponTableView.layoutIfNeeded()
|
||||
@@ -100,10 +103,10 @@ class CartPaymentOptionsVM{
|
||||
}
|
||||
|
||||
func applyCoupon(code : String){
|
||||
Utilities.startProgressHUD()
|
||||
let headers : HTTPHeaders = ["access-token" : AuthFunc.shareInstance.getAccessToken()]
|
||||
let params : Parameters = ["coupon_code" : "",
|
||||
let params : Parameters = ["coupon_code" : code,
|
||||
"total_amount" : self.cartTotalPrice]
|
||||
self.vc.couponAplliedStack.isHidden = true
|
||||
|
||||
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Cart.applied_coupon_discount, method: .post,parameters: params,headers: headers) { [weak self](result : Result<BaseResponseModel<CouponApplyDM>, NetworkManager.APIError>) in
|
||||
switch result{
|
||||
@@ -118,7 +121,6 @@ class CartPaymentOptionsVM{
|
||||
Error
|
||||
*/
|
||||
Utilities.dismissProgressHUD()
|
||||
|
||||
case 1:
|
||||
Utilities.dismissProgressHUD()
|
||||
guard let data = data.data else{return}
|
||||
@@ -136,7 +138,7 @@ class CartPaymentOptionsVM{
|
||||
return
|
||||
}
|
||||
Utilities.dismissProgressHUD()
|
||||
Utilities.alertWithBtnCompletion(title: "Error", msgBody: error.localizedDescription, okBtnStr: "Retry?", vc: self.vc) { isDone in
|
||||
Utilities.alertWithBtnCancelCompletion(title: "Error", msgBody: error.localizedDescription, okBtnStr: "Retry?", vc: self.vc) { isDone in
|
||||
if isDone{
|
||||
self.applyCoupon(code: self.vc.couponCodeTF.text ?? "")
|
||||
}
|
||||
@@ -144,4 +146,49 @@ class CartPaymentOptionsVM{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func createOrder(){
|
||||
Utilities.startProgressHUD()
|
||||
let headers : HTTPHeaders = ["access-token" : AuthFunc.shareInstance.getAccessToken()]
|
||||
let params : Parameters = ["product_ids" : [],
|
||||
"addressID" : "String"]
|
||||
struct URLResp : Codable {
|
||||
var url : String?
|
||||
}
|
||||
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Cart.create_new_order, method: .post,headers: headers) { [weak self](result : Result<BaseResponseModel<URLResp>, NetworkManager.APIError>) in
|
||||
switch result{
|
||||
case .success(let data):
|
||||
guard let self else{
|
||||
Utilities.dismissProgressHUD()
|
||||
return
|
||||
}
|
||||
switch data.success{
|
||||
case 0:
|
||||
/*
|
||||
Error
|
||||
*/
|
||||
Utilities.dismissProgressHUD()
|
||||
case 1:
|
||||
Utilities.dismissProgressHUD()
|
||||
guard let data = data.data else{return}
|
||||
print(data.url)
|
||||
default:
|
||||
Utilities.dismissProgressHUD()
|
||||
break
|
||||
}
|
||||
case .failure(let error):
|
||||
guard let self else{
|
||||
Utilities.dismissProgressHUD()
|
||||
return
|
||||
}
|
||||
Utilities.dismissProgressHUD()
|
||||
Utilities.alertWithBtnCancelCompletion(title: "Error", msgBody: error.localizedDescription, okBtnStr: "Retry?", vc: self.vc) { isDone in
|
||||
if isDone{
|
||||
self.createOrder()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user