Пример #1
0
        public virtual async Task <IHttpActionResult> CompleteCheckout(CompleteCheckoutRequest request)
        {
            if (request == null)
            {
                return(BadRequest("No request body found."));
            }

            var nextStepUrl = CartUrlProvider.GetCheckoutStepUrl(new GetCheckoutStepUrlParam
            {
                CultureInfo = ComposerContext.CultureInfo,
                StepNumber  = request.CurrentStep + 1
            });

            var checkoutViewModel = await CheckoutService.CompleteCheckoutAsync(new CompleteCheckoutParam
            {
                CartName    = CartConfiguration.ShoppingCartName,
                CustomerId  = ComposerContext.CustomerId,
                CultureInfo = ComposerContext.CultureInfo,
                Scope       = ComposerContext.Scope,
                BaseUrl     = RequestUtils.GetBaseUrl(Request).ToString(),
            });

            checkoutViewModel.NextStepUrl = nextStepUrl;

            return(Ok(checkoutViewModel));
        }
        //TODO: Change the method name for GetAdressListAsync or something similar because it confuse people
        public virtual async Task <IHttpActionResult> GetShippingAddressAsync()
        {
            var checkoutAddressStepUrl = CartUrlProvider.GetCheckoutStepUrl(new GetCheckoutStepUrlParam
            {
                CultureInfo = ComposerContext.CultureInfo,
                StepNumber  = 1,
            });


            var urlParam = new BaseUrlParameter {
                CultureInfo = ComposerContext.CultureInfo,
                ReturnUrl   = checkoutAddressStepUrl
            };
            var addressListUrl     = MyAccountUrlProvider.GetAddressListUrl(urlParam);
            var addAddressUrl      = CartUrlProvider.GetCheckoutAddAddressUrl(urlParam);
            var editAddressBaseUrl = CartUrlProvider.GetCheckoutUpdateAddressBaseUrl(urlParam);

            var viewModel = await CustomerAddressViewService.GetAddressListViewModelAsync(new GetAddressListViewModelParam
            {
                CustomerId         = ComposerContext.CustomerId,
                CultureInfo        = ComposerContext.CultureInfo,
                Scope              = ComposerContext.Scope,
                AddAddressUrl      = addAddressUrl,
                EditAddressBaseUrl = editAddressBaseUrl,
                CountryCode        = ComposerContext.CountryCode
            });

            return(Ok(viewModel));
        }
Пример #3
0
        public virtual async Task <IHttpActionResult> UpdateCart(UpdateCartRequest updateCartRequest)
        {
            if (updateCartRequest == null)
            {
                return(BadRequest("updateCartRequest is required"));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var getCartUrlParam = new BaseUrlParameter
            {
                CultureInfo = ComposerContext.CultureInfo
            };

            var checkoutStepInfos = CartUrlProvider.GetCheckoutStepPageInfos(getCartUrlParam);

            var nextStepUrl = CartUrlProvider.GetCheckoutStepUrl(new GetCheckoutStepUrlParam
            {
                CultureInfo = ComposerContext.CultureInfo,
                StepNumber  = updateCartRequest.CurrentStep.GetValueOrDefault() + 1
            });

            var getCartParam = new GetCartParam
            {
                Scope       = ComposerContext.Scope,
                CultureInfo = ComposerContext.CultureInfo,
                CustomerId  = ComposerContext.CustomerId,
                CartName    = CartConfiguration.ShoppingCartName,
                BaseUrl     = RequestUtils.GetBaseUrl(Request).ToString(),
            };

            var updateCheckoutCartParam = new UpdateCheckoutCartParam
            {
                GetCartParam = getCartParam,
                CurrentStep  = updateCartRequest.CurrentStep.GetValueOrDefault(),
                IsGuest      = ComposerContext.IsGuest,
                UpdateValues = updateCartRequest.UpdatedCart
            };

            var homepageUrl = GetHomepageUrl();

            var updateCartResultViewModel = await CheckoutService.UpdateCheckoutCartAsync(updateCheckoutCartParam);

            SetHomepageUrl(updateCartResultViewModel.Cart, homepageUrl);
            SetEditCartUrl(updateCartResultViewModel.Cart);

            if (updateCartResultViewModel.Cart.OrderSummary != null)
            {
                updateCartResultViewModel.Cart.OrderSummary.CheckoutStepUrls = checkoutStepInfos.Values.Select(x => x.Url).ToList();
            }

            if (!updateCartResultViewModel.HasErrors)
            {
                updateCartResultViewModel.NextStepUrl = nextStepUrl;
            }

            return(Ok(updateCartResultViewModel));
        }