updatePromotion method
Implementation
updatePromotion(
BuildContext context,
String cartDiscountId,
String cartId,
) async {
Helper.progressDialog(context, "Please wait..");
// printLogs(dio);
// dio
// .put(
// '${ApiConstant.posBaseUrl}pos-cart-service-svc/cart-builder/generic-carts/$cartId',
// data: {
// "cartDiscountId": cartDiscountId,
// },
// options: Options(
// headers: {
// 'X-User-Id': storage.read("XUSER_ID"),
// 'X-Roles': storage.read("XUSER_ID")
// },
// ),
// )
// .then((response) {
// Get.back();
// if (response.data != null) {
// print('updatePromotion${response.data}');
// discountId.value = cartDiscountId;
// CartModel model = CartModel();
// Map<String, dynamic> creditData = response.data;
// model = CartModel.fromJson(creditData);
// if (model.status == "POS200") {
// cart_id.value = model.data!.cartId!;
// discountList.value = model.data!.cartDiscountsList!;
// updateSellThruOrder(model);
// }
// }
// }, onError: (error) {
// print(error.toString());
// Get.back();
// Helper.messageDialog(Get.context!, "Try Again!!", error.toString());
// });
try {
var body = {"cartDiscountId": cartDiscountId};
String requestTime = "";
String responseTime = "";
await ApiClient(
baseUrl: ApiConstant.posBL,
onFetchRequestTime: (time) {
requestTime = time;
},
onFetchResponseTime: (time) {
responseTime = time;
},
screenName: "orderStock",
)
.discountCart(
cartDiscountId: body,
cartId: cartId,
xRoles: SecureStorageService.readSecureData(
SecureStorageService.xUserId,
),
xUserId: SecureStorageService.readSecureData(
SecureStorageService.xUserId,
),
)
.then((response) {
Helper.logEvent(
"RESPONSE_EVENT",
success: true,
endPoint: "${Api.addToCart}/$cartId",
responseDate: responseTime,
screenName: "orderStock",
requestDate: requestTime,
transactionId: cartId,
);
CartModel model = response;
if (model.status == "POS200") {
discountId.value = cartDiscountId;
cart_id.value = model.data!.cartId!;
discountList.value = model.data!.cartDiscountsList!;
updateSellThruOrder(model);
Get.back();
} else {
Get.back();
if (model.errors != null) {
Helper.messageDialog(
Get.context!,
model.errors![0].code ?? "Try again!!",
model.errors![0].description ?? "Something went wrong",
);
}
}
}).catchError((error) {
ConditionalLogs().customLog("$error");
Get.back();
MainController mainController = Get.put(MainController());
mainController.showErrorPopup();
});
} catch (e) {
Get.back();
}
}