Copied to clipboard

Flag this post as spam?

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


  • Graham Carr 277 posts 389 karma points
    Aug 26, 2016 @ 14:07
    Graham Carr
    0

    MembershipHelper, Custom Calculator and Ajax Issue

    Hello,

    I am currently experiencing a strange problem I was hoping you might be able to shed some light on.

    Firstly I am running Umbraco v7.4.3 and Teacommerce 3.1.1 as well as utilising the shoppingCart.js and teaCommerceEvents.js files from the example site. I have added some CustomPrice and CustomOrderLine calculators which sit in the AppCode/TeaCommerce folder as well.

    The issue I am having is that everything works fine when browsing the site as normal, such as viewing products, variants, basket, etc. but then randomly I start getting problems with the AddToBasket, increase quantity buttons, etc. in that I receive 500 errors from the form post.

    I have analysed using the developer tools to see what is happening on the Ajax posts and the errors are occuring in the custom calculators.

    Basically I create a membershiphelper based on the current UmbracoContext and normally this is picking up the user I am logged in as when browsing the site normally. However when I click the AddToBasket, Increase Qty buttons which have the Ajax calls, the user being returned is 'admin' which errors admin is an Umbraco user and not a member and the referenced properties do not exist.

    The crux of it is, do you have any idea why the 'admin' user is being returned rather than the current logged in member when creating a membershiphelper in a custom calculator from an Ajax call??

    Example code is shown below:

            MembershipHelper mHelper = new MembershipHelper(UmbracoContext.Current);
            var helper = new UmbracoHelper(UmbracoContext.Current);
            var countries = TeaCommerce.Umbraco.Web.TC.GetCountries(1);
            decimal basePrice = Convert.ToDecimal(helper.TypedContent(productIdentifier).GetPropertyValue("price"));
            decimal discountLevel = 0;
            if (mHelper.IsLoggedIn())
            {
                discountLevel = Convert.ToDecimal(mHelper.GetCurrentMember().GetPropertyValue("discount"));
            }
    
  • Anders Burla 2560 posts 8256 karma points
    Aug 29, 2016 @ 07:18
    Anders Burla
    0

    Hi Graham

    That sounds a bit weird. We only have something in TC where we temp switch the order id when doing admin edit in the backoffice of Tea Commerce, but nothing with changing members. Its pretty weird that it happens when the Ajax is being used, but then again - its not a true full stack Umbraco server request and response. So maybe there is a case that Umbraco hasen't covered when a AJAX request is made.

    Have you tried to use the Membership API of .NET and not use the Umbraco API for it? Maybe that will make it work.

    Or try to update Umbraco so you have the latest version where most bugs will be fixed.

    Kind regards

    Anders

  • Graham Carr 277 posts 389 karma points
    Aug 31, 2016 @ 08:42
    Graham Carr
    0

    Hi Anders,

    Many thanks for the reply. I have tried using the Membership API of .Net such as the following:

    var member = Membership.GetUser()
    

    However when performing the same Ajax calls (e.g. add qty, delete line item, etc.) this is returning null. If I perform a non Ajax action (e.g. login) then the member variable is not null and contains the user that is logging in. It seems that when performing the Ajax call the correct member context is not being returned and for the life of me I cannot work out why. I have used the code from this TeaCommerce documentation page:

    https://documentation.teacommerce.net/net-api/price-calculators/order-line-calculator/
    

    But have added code to return the current user and it is when doing the Ajax call and this code is hit that the member is showing as null.

    Any further ideas as I have also updated to the latest version and the issue still remains?

    Graham

  • Graham Carr 277 posts 389 karma points
    Aug 31, 2016 @ 08:59
    Graham Carr
    0

    I also forgot to mention that this issue seems to only happen when using Google Chrome. If I clear the history and cookies from the browser then everything works fine for a short time and then randomly the issue re-appears.

Please Sign in or register to post replies

Write your reply to:

Draft