diff --git a/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart b/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart index e64ab20c..e9c32f2b 100644 --- a/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart +++ b/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart @@ -31,6 +31,11 @@ class OrderPreviewViewModel extends BaseViewModel { PaymentCheckoutData paymentCheckoutData = PaymentCheckoutData(); double totalAdditionalShippingCharge = 0; + setShoppingCartResponse(ShoppingCartResponse cart){ + cartResponse = cart; + notifyListeners(); + } + Future getOrderPreviewData() async { setState(ViewState.Busy); await _orderService.getAddresses(); diff --git a/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart b/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart index 828aa8e4..24f846b0 100644 --- a/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart +++ b/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart @@ -1,5 +1,6 @@ import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart'; import 'package:diplomaticquarterapp/models/pharmacy/Wishlist.dart'; import 'package:diplomaticquarterapp/models/pharmacy/locationModel.dart'; import 'package:diplomaticquarterapp/models/pharmacy/productDetailModel.dart'; @@ -8,6 +9,10 @@ import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/navigation_service.dart'; import 'package:diplomaticquarterapp/services/pharmacy_services/product_detail_service.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCartResponse.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import '../../../locator.dart'; @@ -61,12 +66,39 @@ class ProductDetailViewModel extends BaseViewModel{ Future addToCartData(quantity, itemID) async { hasError = false; setState(ViewState.BusyLocal); - await _productDetailService.addToCart(quantity, itemID); + var resp = await _productDetailService.addToCart(quantity, itemID); + ShoppingCartResponse object = _handleGetShoppingCartResponse(resp); if (_productDetailService.hasError) { error = _productDetailService.error; setState(ViewState.ErrorLocal); - } else + } else { setState(ViewState.Idle); + Provider.of(locator().navigatorKey.currentContext, listen: false) + .setShoppingCartResponse( object); + } + } + + ShoppingCartResponse _handleGetShoppingCartResponse(Map res) { + ShoppingCartResponse cartResponse = ShoppingCartResponse(); + + if (res == null) { + error = "response is null"; + setState(ViewState.Error); + return null; + } + print(res); + cartResponse.itemCount = res["item_count"]; + cartResponse.quantityCount = res["quantity_count"]; + cartResponse.subtotal = res["subtotal"]; + cartResponse.subtotalWithVat = res["subtotal_with_vat"]; + cartResponse.subtotalVatAmount = res["subtotal_vat_amount"]; + cartResponse.subtotalVatRate = res["subtotal_vat_rate"]; + cartResponse.shoppingCarts = List(); + res["shopping_carts"].forEach((item) { + ShoppingCart shoppingCart = ShoppingCart.fromJson(item); + cartResponse.shoppingCarts.add(shoppingCart); + }); + return cartResponse; } Future addToWishlistData(itemID) async { diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index 38e180e2..0eb36ef1 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -64,10 +64,11 @@ class _Login extends State { if (BASE_URL.contains("uat.")) { nationalIDorFile.text = "2001273"; mobileNumberController.text = mobileNo = "0555416043"; - }/* else { + } else { nationalIDorFile.text = "3376044"; mobileNumberController.text = mobileNo = "0555416575"; - }*/ + } + } getDeviceToken() async { diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index cb38ca4f..7e95292b 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -3,7 +3,7 @@ import 'package:diplomaticquarterapp/config/size_config.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; -import 'package:diplomaticquarterapp/pages/pharmacies/compare-list.dart'; +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-page/cart-order-page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-name-and-price.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/recommended_products.dart'; @@ -338,6 +338,10 @@ class __ProductDetailPageState extends State { ), )); } + addToShoppingCartFunction({quantity,itemID,ProductDetailViewModel model})async{ + await model.addToCartData(quantity,itemID); + + } addToWishlistFunction({itemID, ProductDetailViewModel model}) async { isInWishList = true; @@ -353,22 +357,11 @@ class __ProductDetailPageState extends State { addToCartFunction( {quantity, itemID, - ProductDetailViewModel model}) async { - GifLoaderDialogUtils.showMyDialog(context); - await model.addToCartData(quantity, itemID); - GifLoaderDialogUtils.hideDialog(context); - } - - addToShoppingCartFunction( - {quantity, - itemID, - ProductDetailViewModel model}) async { + ProductDetailViewModel model, + }) async { GifLoaderDialogUtils.showMyDialog(context); await model.addToCartData(quantity, itemID); GifLoaderDialogUtils.hideDialog(context); - Navigator.push( - context, - FadePage(page: CartOrderPage())); } } diff --git a/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart index 25be1775..d44283bf 100644 --- a/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart +++ b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart @@ -25,7 +25,8 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { final bool isInWishList; final Function addToCartFunction; - ProductAppBar({Key key, this.product, this.model, this.addToWishlistFunction, this.quantity, this.deleteFromWishlistFunction, this.isInWishList, this.addToCartFunction}) : super(key: key); + ProductAppBar({Key key, this.product, this.model, this.addToWishlistFunction, this.quantity, this.deleteFromWishlistFunction, this.isInWishList, + this.addToCartFunction}) : super(key: key); AuthenticatedUserObject authenticatedUserObject = locator(); @@ -130,7 +131,8 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { onTap: () async { if (quantity > 0) { { - await addToCartFunction(quantity: quantity, itemID: itemID, model: model); + await addToCartFunction(quantity: quantity, itemID: itemID, model: model, + context: context); Navigator.of(context).pop(); } diff --git a/lib/services/pharmacy_services/product_detail_service.dart b/lib/services/pharmacy_services/product_detail_service.dart index 31a06fea..d1732841 100644 --- a/lib/services/pharmacy_services/product_detail_service.dart +++ b/lib/services/pharmacy_services/product_detail_service.dart @@ -7,6 +7,7 @@ import 'package:diplomaticquarterapp/models/pharmacy/productDetailModel.dart'; import 'package:diplomaticquarterapp/models/pharmacy/specification.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart'; class ProductDetailService extends BaseService { bool isLogin = false; @@ -27,7 +28,6 @@ class ProductDetailService extends BaseService { List get productSpecification => _productSpecification; - Future getProductReviews(productID) async { hasError = false; await baseAppClient.getPharmacy(GET_PRODUCT_DETAIL+productID+"?fields=reviews", @@ -73,7 +73,7 @@ class ProductDetailService extends BaseService { }, body: request); } - Future addToCart(quantity, itemID) async { + Future addToCart(quantity, itemID) async { var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); hasError = false; Map request; @@ -88,9 +88,7 @@ class ProductDetailService extends BaseService { "language_id": 1 } }; - - - + dynamic localRes; await baseAppClient.pharmacyPost(GET_SHOPPING_CART, isExternal: false, onSuccess: (dynamic response, int statusCode) { _addToCartModel.clear(); @@ -98,11 +96,14 @@ class ProductDetailService extends BaseService { _addToCartModel.add(Wishlist.fromJson(item)); }); AppToast.showSuccessToast(message: 'You have added a product to the cart'); + localRes = response; }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage()); }, body: request); + + return Future.value(localRes); } Future notifyMe(customerId, itemID) async { diff --git a/lib/widgets/pharmacy/product_tile.dart b/lib/widgets/pharmacy/product_tile.dart index af1e75ec..3b89c49c 100644 --- a/lib/widgets/pharmacy/product_tile.dart +++ b/lib/widgets/pharmacy/product_tile.dart @@ -163,7 +163,7 @@ class productTile extends StatelessWidget { ), onPressed: () async { GifLoaderDialogUtils.showMyDialog(context); - await addToCartFunction(1, productID); + await addToCartFunction(1, productID, context); GifLoaderDialogUtils.hideDialog(context); Navigator.push( context, @@ -292,7 +292,7 @@ class productTile extends StatelessWidget { // await x.deletWishlistData(itemID); // } - addToCartFunction(quantity, itemID) async { + addToCartFunction(quantity, itemID, BuildContext context) async { ProductDetailViewModel x = new ProductDetailViewModel(); await x.addToCartData(quantity, itemID); }