Copied to clipboard

Flag this post as spam?

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


  • seanrock 239 posts 460 karma points
    Jul 09, 2020 @ 15:36
    seanrock
    0

    Nullable object must have a value exception when calling CalculatePrice on shipping method object

    Hi

    I'm trying to display the shipping options for the customer to select during checkout. The shipping methods (x2) have a price and nothing special about them.

    I'm grabbing the methods in the view

    var store = Model.GetStore();
    var currentOrder = VendrApi.Instance.GetCurrentOrder(store.Id);
    var shippingMethods = VendrApi.Instance.GetShippingMethods(store.Id).ToList();
    

    Looping over shippingMethods list, I get the exception when i call the CalculatePrice() method

    [InvalidOperationException: Nullable object must have a value.] System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) +60 System.Nullable'1.getValue() +28 Vendr.Core.ShippingMethodExtensions.CalculatePrice(ShippingMethodReadOnly shippingMethod, ISessionManager session, IShippingCalculator calculator, ITaxSourceFactory taxSourceFactory) +519 Vendr.Core.ShippingMethodExtensions.CalculatePrice(ShippingMethodReadOnly shippingMethod) +135 ASP.PageViewsCheckoutDeliverycshtml.Execute() in C:\Work\Projects\Allermuir at home\src\E-Commerce Solution\Umbraco Baseline\bd2.Umbraco.Web\Views\CheckoutDelivery.cshtml:188 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +252 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +148 System.Web.WebPages.StartPage.ExecutePageHierarchy() +86 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +107 Umbraco.Web.Mvc.ProfilingView.Render(ViewContext viewContext, TextWriter writer) in D:\a\1\s\src\Umbraco.Web\Mvc\ProfilingView.cs:25 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +378 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList'1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +91 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList'1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +793 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList'1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +793 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList'1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +793 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList'1 filters, ActionResult actionResult) +81 System.Web.Mvc.Async.<>cDisplayClass31.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jul 09, 2020 @ 15:58
    Matt Brailsford
    100

    Hey Sean,

    Calling CalculatePrice on the shipping method will attempt to work out the price based upon the current order in the session. To do this, it uses the order.ShippingInfo.CountryId property which it assumes shouldn't be null. My guess is that your order doesn't currently have a shipping country set and so it's erroring.

    We could probably do something to say if the orders shipping country isn't set, then fall back to the current sessions default shipping country, but this could be a bit misleading if it's not the same country as where it ships to and so could display an incorrect price.

    The best approach really is to ensure your order has a shipping country set prior to displaying the shipping options, that we you can ensure the prices displayed is for the exact known country it would be shipped to.

    /Matt

  • seanrock 239 posts 460 karma points
    Jul 09, 2020 @ 16:44
    seanrock
    0

    Hi Matt

    Yes you're correct. I've opted to set the shipping country to the store's default country and that works.

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft