import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/service/base_service.dart'; import 'package:diplomaticquarterapp/models/pharmacy/Wishlist.dart'; import 'package:diplomaticquarterapp/models/pharmacy/addToCartModel.dart'; import 'package:diplomaticquarterapp/models/pharmacy/locationModel.dart'; import 'package:diplomaticquarterapp/models/pharmacy/productDetailModel.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/models/pharmacy/specification.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; class ProductDetailService extends BaseService { bool isLogin = false; num _stockQuantity; num get stockQuantity => _stockQuantity; String _stockAvailability; String get stockAvailability => _stockAvailability; bool _isStockAvailable; bool get isStockAvailable => _isStockAvailable; List _productDetailList = List(); List get productDetailList => _productDetailList; List _productLocationList = List(); List get productLocationList => _productLocationList; List _addToCartModel = List(); List get addToCartModel => _addToCartModel; List _wishListProducts = List(); List get wishListProducts => _wishListProducts; List _productSpecification = List(); List get productSpecification => _productSpecification; Future getProductReviews(productID) async { hasError = false; await baseAppClient.getPharmacy(GET_PRODUCT_DETAIL + productID + "?fields=reviews,stock_quantity,stock_availability,IsStockAvailable", onSuccess: (dynamic response, int statusCode) { _productDetailList.clear(); response['products'].forEach((item) { _productDetailList.add(ProductDetail.fromJson(item)); print(response); }); _stockQuantity = response['products'][0]['stock_quantity']; _stockAvailability = response['products'][0]['stock_availability']; _isStockAvailable = response['products'][0]['IsStockAvailable']; }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; }); } Future getProductAvailabiltyDetail() async { hasError = false; Map request; request = { // "Channel": 3, // "DeviceTypeID": 2, // "IPAdress": "10.20.10.20", // "LanguageID": 2, // "PatientOutSA": 0, // "SKU": "6720020025", // "SessionID": null, // "VersionID": 5.6, // "generalid": "Cs2020@2016\$2958", // "isDentalAllowedBackend": false }; await baseAppClient.post(GET_LOCATION, onSuccess: (dynamic response, int statusCode) { _productLocationList.clear(); response['PharmList'].forEach((item) { _productLocationList.add(LocationModel.fromJson(item)); print(_productLocationList); print(response); }); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; }, body: request); } Future addToCart(quantity, itemID) async { var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); hasError = false; Map request; request = { "shopping_cart_item": {"quantity": quantity, "shopping_cart_type": "1", "product_id": itemID, "customer_id": customerId, "language_id": 1} }; dynamic localRes; await baseAppClient.pharmacyPost(GET_SHOPPING_CART, isExternal: false, onSuccess: (dynamic response, int statusCode) { _addToCartModel.clear(); response['shopping_carts'].forEach((item) { _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 { hasError = false; await baseAppClient.getPharmacy(SUBSCRIBE_PRODUCT + "SinceId=$customerId&ProductId=$itemID", onSuccess: (dynamic response, int statusCode) { AppToast.showSuccessToast(message: 'You will be notified when product available'); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; AppToast.showErrorToast(message: error ?? Utils.generateContactAdminMessage()); }); } Future addToWishlist(itemID) async { var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); hasError = false; Map request; request = { "shopping_cart_item": {"quantity": 1, "shopping_cart_type": "Wishlist", "product_id": itemID, "customer_id": customerId, "language_id": 1} }; await baseAppClient.pharmacyPost(GET_SHOPPING_CART, onSuccess: (dynamic response, int statusCode) { _wishListProducts.clear(); response['shopping_carts'].forEach((item) { _wishListProducts.add(Wishlist.fromJson(item)); }); AppToast.showSuccessToast(message: 'You have added a product to the Wishlist'); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; AppToast.showErrorToast(message: error ?? Utils.generateContactAdminMessage()); }, body: request); } Future getWishlistItems() async { var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); hasError = false; await baseAppClient.getPharmacy(GET_WISHLIST + customerId + "?shopping_cart_type=2", onSuccess: (dynamic response, int statusCode) { _wishListProducts.clear(); response['shopping_carts'].forEach((item) { _wishListProducts.add(Wishlist.fromJson(item)); }); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; }); } Future deleteItemFromWishlist(itemID) async { var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); hasError = false; await baseAppClient.getPharmacy(DELETE_WISHLIST + customerId + "+&product_id=" + itemID + "&cart_type=Wishlist", onSuccess: (dynamic response, int statusCode) { _wishListProducts.clear(); response['shopping_carts'].forEach((item) { _wishListProducts.add(Wishlist.fromJson(item)); }); AppToast.showSuccessToast(message: 'You have removed a product from the Wishlist'); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; AppToast.showErrorToast(message: error ?? Utils.generateContactAdminMessage()); }); } Future productSpecificationData(itemID) async { hasError = false; await baseAppClient.getPharmacy(GET_SPECIFICATION + itemID, onSuccess: (dynamic response, int statusCode) { _productSpecification.clear(); response['specification'].forEach((item) { _productSpecification.add(SpecificationModel.fromJson(item)); print(_productSpecification); }); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; }); } }