Copied to clipboard

Flag this post as spam?

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

  • Rasmus Fjord 672 posts 1562 karma points c-trib
    Jul 19, 2018 @ 11:01
    Rasmus Fjord

    Order.Save fires null reference when used with hangfire

    Hey Guys :)

    We are just doing a super TC solution with a integration for C5 here we have an event being fired by Hangfire.

    When an order has been handled we want to change its order status like this:

        order.OrderStatusId = SkyConstants.OrderStatuses.Completed;

    But it throws the following error:

        System.NullReferenceException: Object reference not set to an instance of an object.
       at TeaCommerce.Api.Web.Infrastructure.Licensing.TopLevelDomainLicense.IsFeatureLicensed(Feature feature)
       at TeaCommerce.Api.Infrastructure.Licensing.LicenseService.ValidateLicenseFeatures(Feature[] features)
       at TeaCommerce.Api.Models.Order.Save()

    We have the license, im guessing its because there is no available httpcontext, but since the TeaCommerce.Api is not on Github i cannot check thi out. Do you have any other trick to change this order status? Old SQL? Or another way to save an order?

  • Rune Grønkjær 1338 posts 3006 karma points
    Aug 06, 2018 @ 07:05
    Rune Grønkjær

    Hi Rasmus,

    Yes, you are exactly right. We are depending on the HttpContext.Current, and it must be missing in your case.

    Then how to do it...

    You can edit in the DB directly, but be aware that Tea Commerce is caching the orders in the application cache, when going through C# TC.whatever and through the javascript API. You will have to clear the application cache if you are changing orders that could be found in the cache.


  • René Pjengaard 114 posts 675 karma points c-trib
    Aug 20, 2018 @ 14:13
    René Pjengaard

    Hi Rune,

    what exactly do you mean by application-cache. Do you have a code-example on how to clear the TC cache?

    Regards René

  • Rune Grønkjær 1338 posts 3006 karma points
    Aug 21, 2018 @ 06:02
    Rune Grønkjær

    Hi René

    That was actually a good question. Basically Tea Commerce caches all orders in the MemoryCache and is using a sliding expiration of a default 10 minutes. You can clear all orders by calling the Tea Commerce CacheService: TeaCommerce.Api.Infrastructure.Caching.CacheService.Invalidate( string cacheKey );

    The cache key for orders is: "Orders-[storeId]"


Please Sign in or register to post replies

Write your reply to: