예제 #1
0
        public async Task <List <TaxRatesModel> > GetTaxRates(TaxRatesListRequest taxRatesListRequest)
        {
            var builder     = new UriBuilder(GlobalSettings.WooCommerceTaxRatesListRequestEndpoint);
            var queryParams = taxRatesListRequest.GetQueryString();

            builder.Query = queryParams;
            var uri = builder.ToString();

            return(await _requestService.GetAsync <List <TaxRatesModel> >(uri, forcedRefresh : true));
        }
예제 #2
0
        private async Task InitData(string cartParam)
        {
            ShippingAddress = "You don't have a shipping address";
            bool hasShipppingAddress = false;
            int  customerId          = 0;

            CustomerInfo = await _wooCommerceService.GetCustomerInfo(GlobalSettings.User.Id);

            if (CustomerInfo != null && CustomerInfo.Shipping != null && !string.IsNullOrEmpty(CustomerInfo.Shipping.Address1))
            {
                ShippingAddress     = CustomerInfo.Shipping.Address1;
                hasShipppingAddress = true;
            }

            Name = GlobalSettings.User.Name;

            var taxRatesListRequest = new TaxRatesListRequest();
            await WebRequestExecuter.Execute(async() => await _wooCommerceService.GetTaxRates(taxRatesListRequest), myTaxRates =>
            {
                if (myTaxRates.Count != 0)
                {
                    TaxRates       = new ObservableCollection <TaxRatesModel>(myTaxRates);
                    DefaultTaxRate = TaxRates.FirstOrDefault();
                }
                return(Task.CompletedTask);
            });

            var carts = QueryStringHelpers.GetData <List <CartItemModel> >(cartParam);

            Carts = new ObservableCollection <CartItemModel>(carts);

            UpdateOrderSummaryUI();

            var paymentMethods = await _wooCommerceService.GetPaymentMethods();

            if (paymentMethods != null)
            {
                PaymentMethods = paymentMethods.Where(x => x.Enabled).OrderBy(x => x.Order).ToList();
                SelectedMethod = PaymentMethods.FirstOrDefault();

                UpdateSelectedPaymentMethod();
            }

            bool isGranted = await AppHelpers.RequestPermission(Permission.Location);

            if (isGranted && !hasShipppingAddress)
            {
                var myPosition = await AppHelpers.GetCurrentPosition();

                if (myPosition != null)
                {
                    try
                    {
                        var placemarks = await Geocoding.GetPlacemarksAsync(myPosition.Latitude, myPosition.Longitude);

                        var place = placemarks.FirstOrDefault();

                        ShippingAddress    = $"{place.FeatureName} {place.Thoroughfare ?? place.SubThoroughfare}, {place.SubAdminArea}, {place.AdminArea}";
                        MapCameraInitPoint = $"{place.Location.Latitude}, {place.Location.Longitude}, 13, 30, 60";

                        var pin = new Pin
                        {
                            Type     = PinType.Place,
                            Label    = place.CountryName,
                            Address  = place.FeatureName,
                            Icon     = BitmapDescriptorFactory.FromBundle(GlobalSettings.AppConst.StorePinImage),
                            Position = new Xamarin.Forms.GoogleMaps.Position(myPosition.Latitude, myPosition.Longitude)
                        };
                        MessagingCenter.Send(pin, MessagingCenterKeys.OnDrawMapsPinSelectedStore);
                    }
                    catch (FeatureNotSupportedException fnsEx)
                    {
                        // Feature not supported on device
                    }
                    catch (Exception ex)
                    {
                        // Handle exception that may have occurred in geocoding
                    }
                }
            }
        }