Copied to clipboard

Flag this post as spam?

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


  • Gordon Saxby 1315 posts 1553 karma points
    May 01, 2019 @ 14:20
    Gordon Saxby
    0

    Custom Property problem

    I have a strange (or possibly not!) issue with the code below:

    if (User.Identity.IsAuthenticated)
    {
        var membershipUser = Membership.GetUser();
        var membershipUsername = membershipUser.UserName;
        var umbracoMember = ApplicationContext.Services.MemberService.GetByUsername(membershipUsername);
        TC.AddOrUpdateOrderProperty(storeId, "lastName", (umbracoMember.GetValue("surname") != null) ? umbracoMember.GetValue("surname").ToString() : "");
        TC.AddOrUpdateOrderProperty(storeId, "firstName", (umbracoMember.GetValue("forename") != null) ? umbracoMember.GetValue("forename").ToString() : "");
        TC.AddOrUpdateOrderProperty(storeId, "phone", (umbracoMember.GetValue("phoneNumber") != null) ? umbracoMember.GetValue("phoneNumber").ToString() : "");
        TC.AddOrUpdateOrderProperty(storeId, "streetAddress", (umbracoMember.GetValue("street") != null) ? umbracoMember.GetValue("street").ToString() : "");
        TC.AddOrUpdateOrderProperty(storeId, "city", (umbracoMember.GetValue("city") != null) ? umbracoMember.GetValue("city").ToString() : "");
        TC.AddOrUpdateOrderProperty(storeId, "zipCode", (umbracoMember.GetValue("postcode") != null) ? umbracoMember.GetValue("postcode").ToString() : "");
        TC.AddOrUpdateOrderProperty(storeId, "email", umbracoMember.Email);
    }
    

    The first time through, only the first "AddOrUpdateOrderProperty" line seems to work, as later in the page, the values are used to populate text fields. E.g. :

    value="@order.Properties[ "firstName" ]"
    

    If I then press F5 to refresh the page, all textboxes are populated.

    It is only the first line that works, if I change the order, then whichever line is first gets populated - in terms of showing in the textfield on the page.

    Am I missing some code, do I need to reload the order after creating the order properties?

  • Matt Brailsford 2284 posts 11095 karma points MVP 6x c-trib
    May 02, 2019 @ 12:49
    Matt Brailsford
    0

    Does an order exist before you hit this code? Or more specifically, at what point in the checkout process do you hit this code?

  • Matt Brailsford 2284 posts 11095 karma points MVP 6x c-trib
    May 02, 2019 @ 12:53
    Matt Brailsford
    0

    One thing you could try to get it working could be to call TC.AddOrUpdateOrderProperties instead which should set all the properties in one go. But I'd still like to try and understand what is happening here.

  • Gordon Saxby 1315 posts 1553 karma points
    May 02, 2019 @ 13:27
    Gordon Saxby
    0

    It is a new order process. A user has added items to the basket and have gone to the first checkout step (enter your name and details).

    On their way, they can login if they are an existing customer (which is when the issue is presenting itself). If they do login, the code above gets their current details and populates the form with their details.

    Only the first item gets set on the current "order" variable. Above, I have the surname first, originally it was forename.

    I have added the line:

        order = TC.GetCurrentOrder(storeId, false);
    

    at the end of the "if" statement and now the form populates completely - but why does the first property work without reloading the order?

  • Matt Brailsford 2284 posts 11095 karma points MVP 6x c-trib
    May 02, 2019 @ 13:36
    Matt Brailsford
    100

    Quick answer, I'm not entirely sure 😁

    Looking at the set order property method though, each one of those calls sets a property and then saves the order so unless these are all happening too quickly, I'm not sure why.

    There is some logic in the process that says if the current order has started the payment process, then it actually clones the order leaving the original as is so I wasn't sure if that was playing a part, but I don't think it would here.

    I'll have to try and dig a little deeper, but in the mean time I would suggest you switch to using TC.AddOrUpdateOrderProperties at least as this will set all the properties at once and only trigger a single Save() request, saving on DB hits.

  • Gordon Saxby 1315 posts 1553 karma points
    May 02, 2019 @ 14:29
    Gordon Saxby
    0

    Subject to more testing - using TC.AddOrUpdateOrderProperties seems to have fixed it.

    By the way, I also removed the order = TC.GetCurrentOrder(storeId, false) line too.

  • Matt Brailsford 2284 posts 11095 karma points MVP 6x c-trib
    May 02, 2019 @ 15:13
    Matt Brailsford
    0

    Interesting. I've got a feeling it is something to do with each request causing a save, so that is a lot of things happening so maybe it just struggles.

    Good to know the TC.AddOrUpdateOrderProperties resolves it for you though 👍

Please Sign in or register to post replies

Write your reply to:

Draft