Exemple #1
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));
        }
Exemple #2
0
        public virtual async Task <IHttpActionResult> GetCart()
        {
            var homepageUrl = GetHomepageUrl();

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

            SetHomepageUrl(cartViewModel, homepageUrl);
            SetEditCartUrl(cartViewModel);

            if (cartViewModel.OrderSummary != null)
            {
                var checkoutUrlTarget = GetCheckoutUrl();
                var checkoutStepInfos = CartUrlProvider.GetCheckoutStepPageInfos(new BaseUrlParameter
                {
                    CultureInfo = ComposerContext.CultureInfo
                });
                //Build redirect url in case of the customer try to access an unauthorized step.
                var stepNumber = cartViewModel.OrderSummary.CheckoutRedirectAction.LastCheckoutStep;
                if (!checkoutStepInfos.ContainsKey(stepNumber))
                {
                    return(BadRequest("StepNumber is invalid"));
                }

                var checkoutStepInfo = checkoutStepInfos[stepNumber];

                //If the cart contains recurring items and user is not authenticated, redirect to sign in
                if (RecurringOrdersSettings.Enabled && cartViewModel.HasRecurringLineitems && !ComposerContext.IsAuthenticated)
                {
                    cartViewModel.OrderSummary.CheckoutRedirectAction.RedirectUrl = checkoutUrlTarget;
                }
                else
                {
                    cartViewModel.OrderSummary.CheckoutRedirectAction.RedirectUrl = checkoutStepInfo.Url;
                }
                cartViewModel.OrderSummary.CheckoutStepUrls  = checkoutStepInfos.Values.Select(x => x.Url).ToList();
                cartViewModel.OrderSummary.CheckoutUrlTarget = checkoutUrlTarget;
            }

            return(Ok(cartViewModel));
        }
Exemple #3
0
        protected virtual string GetCheckoutUrl()
        {
            var getCartUrlParam = new BaseUrlParameter
            {
                CultureInfo = ComposerContext.CultureInfo
            };

            var checkoutStepInfos = CartUrlProvider.GetCheckoutStepPageInfos(getCartUrlParam);

            var checkoutSignInUrl = CartUrlProvider.GetCheckoutSignInUrl(new BaseUrlParameter
            {
                CultureInfo = ComposerContext.CultureInfo,
                ReturnUrl   = ComposerContext.IsAuthenticated ? null : checkoutStepInfos[1].Url
            });

            var checkoutUrlTarget = ComposerContext.IsAuthenticated ? checkoutStepInfos[1].Url : checkoutSignInUrl;

            return(checkoutUrlTarget);
        }