Copied to clipboard

Flag this post as spam?

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


  • Anthony Barsotti 26 posts 66 karma points
    Jun 05, 2014 @ 16:50
    Anthony Barsotti
    0

    Object Reference Not Set To Instance of an Object for paymentCountryRegion.name

    For some reason a few orders that have been submitted on my client's site return an error when they try to view them in the Umbraco backend. The error that is returned is the "Object Reference Not Set To Instance of an Object" error in regards to the paymentCountryRegion.name call in the edit-orders.cshtml file. When I comment out the line where that appears I can successfully view the order which tells me that for some reason some orders aren't passing value from the State field of the shipping/payment information when the order is finalized. Has anyone else run across this issue?

  • Anders Burla 2560 posts 8256 karma points
    Jun 06, 2014 @ 08:48
    Anders Burla
    0

    Hi Anthony

    It has nothing to do with the finalize process but is at the information step - properly step 2 of your cart. For some reason the state isn't saved. You can always check it by browsing back to that step and reload the page to see if it is auto selected (if you have implemented that code). Be sure in your editOrder to either take into account that country region id can be null for the order at both payment and shipping information or correct it so the state is always set in the cart step.

    Kind regards
    Anders

  • Anthony Barsotti 26 posts 66 karma points
    Jun 06, 2014 @ 15:47
    Anthony Barsotti
    0

    Right that's what I thought but do you have any idea as to why it isn't automatically selecting the chosen state? I'm using the starter kit and haven't modified the javascript that comes with it so is there anything I need to add to it to get it to work correctly? I'll add the if statement around the line that's throwing the error but there should always be a state because my client only accepts orders from within the US. 

  • Anders Burla 2560 posts 8256 karma points
    Jun 10, 2014 @ 08:35
    Anders Burla
    0

    Try go from the information step choose the country region and then click to the next step. Now use the javascript console to use TC.getCurrentOrder() and see what country region id is at the payment information object for the order. If that is the right id then the assignment works - which it should. THen you need to look into the razor code that selects the country region if that is in place.

    Kind regards
    Anders

  • Anthony Barsotti 26 posts 66 karma points
    Jun 10, 2014 @ 17:11
    Anthony Barsotti
    0

    So I did that and it is returning the correct region ID in the paymentInformation property of the object that's returned but for some reason it's still only setting the country and not the country region.

    My foreach loop in the cshtml that populates the state select is as follows:

    @foreach ( CountryRegion countryRegion in countryRegions ) {

    <option value="@countryRegion.Id"

    @if ( currentPaymentCountryRegion != null && countryRegion.Id == currentPaymentCountryRegion.Id ) {

    @Html.Raw( "selected=true" )

    }

    else if ( currentPaymentCountryRegion == null && paymentCountryRegionLong != null && countryRegion.Id == paymentCountryRegionLong ) {

    @Html.Raw( "selected=true" )

    }

    >

    @countryRegion.Name

    </option>

    }

    The else if statement uses the variable paymentCountryRegionLong which is the currently logged-in member's stateID property (a custom member property I've created). This is set to null initially and only set otherwise if there is a logged-in member which is why I check to see if it isn't null. This basically is supposed to allow users who are logged in to have the state associated with their account automatically selected in the list. This works perfectly for the country select but for some reason it does not work for the state.

  • Anthony Barsotti 26 posts 66 karma points
    Jun 13, 2014 @ 18:24
    Anthony Barsotti
    0

    So I've looked into this a bit more and the problem is that the state field is not validating so if a user goes to the payment step, jumps back to the information step and then doesn't re-select their state it is no longer set in the current order properties. Essentially users can completely skip that field and complete checkout. Does that field use some sort of JS to validate? I currently have jquery.form.js version 3.32 loaded on the site via the same link that the starter kit uses in its master template https://cdnjs.cloudflare.com/ajax/libs/jquery.form/3.32/jquery.form.min.js. ;

  • Anders Burla 2560 posts 8256 karma points
    Jun 16, 2014 @ 08:53
    Anders Burla
    0

    Hi Anthony

    I don't know if there is a bug in the JavaScript - could you try and debug and see if you could get it to work? Then we could fix it in the general starter kit.

    Kind regards
    Anders

  • Anthony Barsotti 26 posts 66 karma points
    Jun 16, 2014 @ 15:46
    Anthony Barsotti
    0

    I've tried adding jQuery Validate to the page and adding the HTML5 required attribute to the select but neither work. The form just submits without validating that field. There are no errors in the console so I don't think it's a javascript error. The other strange thing is that it should automatically re-select the pre-selected value if the user goes back to the information step based on the code in the Razor macro but it doesn't. 

  • Anders Burla 2560 posts 8256 karma points
    Jun 17, 2014 @ 14:28
    Anders Burla
    0

    When changing payment country we found a bug that the shipping method is reset to null. But that doesn't sound like your bug as you say the state/country region isnt set correctly.

    So the way to debug and send results to us is. Try select a state. When you get to the next step. Use the javascript API or Razor API to display the id of the selected state using the Tea Commerce order object. If that is set correctly then the engine is working. Report if this works.

    Then its the UI. Go one step back and hit CTRL + R for realoading the page. Is the state selected in the dropdown. If not - then there is an error in the code that selects the state - then debug that.

    If it works when you hit CTRL + R but not when you get back with the history back button in the browser, then remember that JavaScript don't rerun on a page back event in the browser. So that might be why it doesnt work in that case.

    Kind regards
    Anders

  • Anthony Barsotti 26 posts 66 karma points
    Jun 17, 2014 @ 20:01
    Anthony Barsotti
    0

    Hi Anders I've fixed this. Whatever the data-countryselectid="country" does isn't working for some reason and it was causing the problem. As soon as I removed that attribute it worked correctly.

Please Sign in or register to post replies

Write your reply to:

Draft