public bool TryGet(RouteRequestLookupInfo routeRequestLookupInfo, out string redirectUrl)
        {
            string resultUrl = null;

            if (_pageByFieldType.TryFindPage(page =>
            {
                var url = _urlService.GetUrl(page, new PageUrlArgs(routeRequestLookupInfo.Channel.SystemId));
                if (url == null)
                {
                    return(false);
                }
                resultUrl = string.Concat(url, url.Contains("?") ? "&" : "?", "RedirectUrl=", HttpUtility.UrlEncode(routeRequestLookupInfo.RawUrl));
                var statusCode = HttpContext.Current?.Response.StatusCode;
                if (Thread.CurrentPrincipal.Identity.IsAuthenticated || statusCode == (int)HttpStatusCode.Unauthorized)
                {
                    resultUrl += $"&code={statusCode}";
                }
                return(true);
            }))
            {
                redirectUrl = resultUrl;
                return(true);
            }

            return(_parentResolver.TryGet(routeRequestLookupInfo, out redirectUrl));
        }
Пример #2
0
        public bool TryGet(RouteRequestLookupInfo routeRequestLookupInfo, out string redirectUrl)
        {
            if (_signInUrlResolver.TryGet(routeRequestLookupInfo, out redirectUrl))
            {
                redirectUrl += $"&code=403";
                return(true);
            }

            return(_parent.TryGet(routeRequestLookupInfo, out redirectUrl));
        }
        public virtual CheckoutViewModel Build()
        {
            var requestModel       = _requestModelAccessor.RequestModel;
            var orderCarrier       = requestModel.Cart.OrderCarrier;
            var deliveryMethods    = _deliveryMethodViewModelBuilder.Build();
            var paymentMethods     = _paymentMethodViewModelBuilder.Build();
            var checkoutPage       = requestModel.WebsiteModel.Fields.GetValue <PointerPageItem>(AcceleratorWebsiteFieldNameConstants.CheckouPage);
            var checkoutPageEntity = checkoutPage.EntitySystemId.MapTo <PageModel>();

            _signInUrlResolver.TryGet(_routeRequestLookupInfoAccessor.RouteRequestLookupInfo, out var loginPageUrl);
            var termsAndConditionPageUrl = checkoutPageEntity.GetValue <PointerPageItem>(CheckoutPageFieldNameConstants.TermsAndConditionsPage)?.MapTo <LinkModel>()?.Href;
            var checkoutModeInt          = requestModel.WebsiteModel.Fields.GetValue <int>(AcceleratorWebsiteFieldNameConstants.CheckoutMode);
            var checkoutMode             = checkoutModeInt == 0 ? CheckoutMode.Both : (CheckoutMode)checkoutModeInt;
            var model = new CheckoutViewModel()
            {
                Authenticated          = _securityContextService.GetIdentityUserSystemId().HasValue,
                CheckoutMode           = (int)checkoutMode,
                DeliveryMethods        = deliveryMethods,
                PaymentMethods         = paymentMethods,
                IsBusinessCustomer     = _personStorage.CurrentSelectedOrganization != null,
                CompanyName            = _personStorage.CurrentSelectedOrganization?.Name,
                SelectedDeliveryMethod = orderCarrier?.Deliveries?.FirstOrDefault()?.DeliveryMethodID ?? deliveryMethods?.FirstOrDefault()?.Id,
                SelectedPaymentMethod  = (orderCarrier?.PaymentInfo?.FirstOrDefault() != null)
                                        ? string.Concat(orderCarrier?.PaymentInfo?.FirstOrDefault().PaymentProvider, ":", orderCarrier?.PaymentInfo?.FirstOrDefault().PaymentMethod)
                                        : paymentMethods?.FirstOrDefault()?.Id,
                CheckoutUrl = checkoutPage?.MapTo <LinkModel>()?.Href,
                TermsUrl    = termsAndConditionPageUrl,
                LoginUrl    = loginPageUrl,
                SignUp      = _checkoutState.NeedToRegister,
            };

            model = GetCustomerDetails(model);

            //Connected country to the channel must be selected
            if (model.IsBusinessCustomer)
            {
                var countries        = _countryService.GetAll().Where(x => _requestModelAccessor.RequestModel.ChannelModel.Channel.CountryLinks.Any(y => y.CountrySystemId == x.SystemId));
                var companyAddresses = _personStorage.CurrentSelectedOrganization?.Addresses?.Where(x => countries.Any(y => y.Id == x.Country))
                                       .Select(address => address.MapTo <AddressViewModel>())?.Where(address => address != null)?.ToList();
                model.CompanyAddresses         = companyAddresses;
                model.SelectedCompanyAddressId = companyAddresses?.FirstOrDefault(x => x.Country == requestModel.CountryModel.Country.Id)?.SystemId;
            }
            else
            {
                model.CustomerDetails.Country = requestModel.CountryModel.Country.Id;
            }

            return(model);
        }
        public virtual CheckoutViewModel Build(CartContext cartContext)
        {
            var requestModel = _requestModelAccessor.RequestModel;
            var orderDetails = cartContext?.Cart.Order;
            var countryCode  = orderDetails?.CountryCode ?? requestModel.CountryModel.Country.Id;
            var currencyCode = orderDetails?.CurrencyCode ?? _currencyService.Get(requestModel.CountryModel.Country.CurrencySystemId)?.Id;

            var deliveryMethods = _deliveryMethodViewModelBuilder.Build(countryCode, currencyCode);
            var paymentOptions  = _paymentOptionViewModelBuilder.Build(cartContext);

            _signInUrlResolver.TryGet(_routeRequestLookupInfoAccessor.RouteRequestLookupInfo, out var loginPageUrl);
            var checkoutModeInt = requestModel.WebsiteModel.GetValue <int>(AcceleratorWebsiteFieldNameConstants.CheckoutMode);
            var checkoutMode    = checkoutModeInt == 0 ? CheckoutMode.Both : (CheckoutMode)checkoutModeInt;
            var model           = new CheckoutViewModel()
            {
                Authenticated      = _securityContextService.GetIdentityUserSystemId().HasValue,
                CheckoutMode       = (int)checkoutMode,
                DeliveryMethods    = deliveryMethods,
                PaymentMethods     = paymentOptions,
                IsBusinessCustomer = _personStorage.CurrentSelectedOrganization != null,
                CompanyName        = _personStorage.CurrentSelectedOrganization?.Name,
                CheckoutUrl        = cartContext?.CheckoutFlowInfo.CheckoutPageUrl,
                TermsUrl           = cartContext?.CheckoutFlowInfo.TermsUrl,
                LoginUrl           = loginPageUrl,
            };

            GetSelectedShippingOptionId(model, orderDetails);
            GetSelectedPaymentOptionId(model, orderDetails);
            GetCustomerDetails(model);

            //Connected country to the channel must be selected
            if (model.IsBusinessCustomer)
            {
                var countries        = _countryService.GetAll().Where(x => _requestModelAccessor.RequestModel.ChannelModel.Channel.CountryLinks.Any(y => y.CountrySystemId == x.SystemId));
                var companyAddresses = _personStorage.CurrentSelectedOrganization?.Addresses?.Where(x => countries.Any(y => y.Id == x.Country))
                                       .Select(address => address.MapTo <AddressViewModel>())?.Where(address => address != null)?.ToList();
                model.CompanyAddresses         = companyAddresses;
                model.SelectedCompanyAddressId = companyAddresses?.FirstOrDefault(x => x.Country == countryCode)?.SystemId;
            }
            else
            {
                model.CustomerDetails.Country = countryCode;
            }

            return(model);
        }
        public bool TryGet(RouteRequestLookupInfo routeRequestLookupInfo, out string redirectUrl)
        {
            string resultUrl = null;

            if (_pageByFieldType.TryFindPage(page =>
            {
                var url = _urlService.GetUrl(page, new PageUrlArgs(routeRequestLookupInfo.Channel.SystemId));
                if (url == null)
                {
                    return(false);
                }
                resultUrl = string.Concat(url, url.Contains("?") ? "&" : "?", "RedirectUrl=", HttpUtility.UrlEncode(routeRequestLookupInfo.RawUrl));
                return(true);
            }))
            {
                redirectUrl = resultUrl;
                return(true);
            }

            return(_parentResolver.TryGet(routeRequestLookupInfo, out redirectUrl));
        }