Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kyle Eck 130 posts 280 karma points
    Aug 10, 2021 @ 19:54
    Kyle Eck
    0

    Make user create an account prior to purchasing

    Perhaps i missed this in the demo or in the documentation, however, is there a way that you can force the user to login with an account prior to purchasing? Lets say when they hit proceed to checkout from their cart?

    Basically the desired flow would be thus

    Click proceed to checkout from cart -> check if user is logged in -> if logged in go to checkout flow, if not force them to log in and redirect to checkout flow

    Thanks,

    Kyle

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Aug 11, 2021 @ 08:14
    Matt Brailsford
    0

    Hi Kyle,

    There is nothing explicitly for this in Vendr itself, but this is were we see people using the power of Umbraco.

    As Umbraco already supports members, we suggest that people use those existing features and integrate them into their checkout flow however they see fit.

    We don't do anything explicitly within Vendr as checkout flows work in many different ways and so we leave that to the implementors and just expose API's to assist along side Umbraco's own APIs.

    Hope this helps

    Matt

  • Philip Hayton 98 posts 435 karma points
    Aug 19, 2021 @ 09:40
    Philip Hayton
    0

    Hi Kyle,

    I have done this exact thing for a recent project. I implemented a RenderMvc controller for the checkout doc types and performed the check in there, along with a few other checks (for example, checking that the order has order items before taking billing info).

    Here's an example:

    The base class:

    public class CheckoutControllerBase : RenderMvcController
    {
        protected readonly ISessionManager SessionManager;
    
        public static string[] RequiredFields = 
        {
            "billingFirstName", 
            "billingLastName", 
            "billingAddressLine1", 
            "billingAddressLine2",
            "billingCountry", 
            "billingZipCode"
        };
    
        public StoreReadOnly Store => CurrentPage.GetStore();
        public OrderReadOnly Order => SessionManager.GetCurrentOrder(Store.Id);
        public IPublishedContent Product => Order
            .OrderLines
            .Select(x => UmbracoContext
                .Content.GetById(Guid.Parse(x.ProductReference)))
            .FirstOrDefault();
    
        public CheckoutControllerBase(ISessionManager sessionManager)
        {
            SessionManager = sessionManager;
        }
    
        public override ActionResult Index(ContentModel model)
        {
            return !EnsureUserAndOrder(out var redirect) ? redirect : CurrentTemplate(model);
        }
    
        public bool EnsureUserAndOrder(out ActionResult redirect)
        {
            if (!Members.IsLoggedIn())
            {
                redirect = RedirectToLogin();
                return false;
            }
    
            if (Order == null || !Order.OrderLines.Any())
            {
                redirect = RedirectToCart();
                return false;
            }
    
            redirect = null;
            return true;
        }
    
        public bool IsValidOrder()
        {
            return RequiredFields.Any(x => string.IsNullOrWhiteSpace(Order.Properties[x]));
        }
    
        public ActionResult RedirectToCart()
        {
            var basket = CurrentPage
                .Root()
                .Descendants<CartPage>()
                .FirstOrDefault();
    
            return new RedirectResult(basket.Url());
        }
    
        public ActionResult RedirectToLogin()
        {
            var registerPage = CurrentPage
                .Root()
                .Descendants<Login>()
                .FirstOrDefault();
    
            return new RedirectResult(registerPage.UrlWithRedirect(CurrentPage.Url()));
        }
    
        public ActionResult RedirectToBillingInfo()
        {
            var orderInfoPage = CurrentPage
                .Root()
                .Descendants<CheckoutOrderInformationPage>()
                .FirstOrDefault();
    
            return new RedirectResult(orderInfoPage.Url());
        }
    }
    

    And for each doc type just inherit from the base:

    public class CheckoutPaymentMethodsPageController : CheckoutControllerBase 
    {
        public CheckoutPaymentMethodsPageController(ISessionManager sessionManager) : base(sessionManager)
        {
        }
    }
    
  • Kyle Eck 130 posts 280 karma points
    Aug 19, 2021 @ 11:57
    Kyle Eck
    0

    Phillip,

    Thanks for this, it is along the lines of what I was thinking of doing. Glad I am not the only one who wants users to have an account prior to purchasing!

    Do you also handle checking out as guest in a similar manner with your valid order checking?

    -Kyle

  • Philip Hayton 98 posts 435 karma points
    Aug 19, 2021 @ 13:38
    Philip Hayton
    0

    Hi Kyle,

    For this project we don't allow checkout as a guest, but yeah I probably would do the validation still - just seems like good practice.

    Cheers

    Phil

Please Sign in or register to post replies

Write your reply to:

Draft