Copied to clipboard

Flag this post as spam?

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


  • Mark V 28 posts 158 karma points
    Sep 28, 2020 @ 16:00
    Mark V
    0

    Shipping Calculator not kicking in

    Hey,

    I'm running into this problem where our custom shipping calculator doesn't kick in after a deployment. It only starts to calculate shipping after restarting the site in IIS after every deployment (I also clear the cache, delete the temp folders and recycle the app pool). After doing this it works fine, but it's not an ideal solution

    The calculator is registered as mentioned in the docs:

    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public class ServiceComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.RegisterUnique<IShippingCalculator, MyShippingCalculator>();
        }
    }
    

    And the implementation is fairly simple. We just call our shipping service:

    public class MyShippingCalculator : ShippingCalculator
    {
        private readonly ILogger _logger;
        private readonly ShippingService _shippingService;
    
        public MyShippingCalculator(ITaxService taxService, IStoreService storeService, ILogger logger, ShippingService shippingService) : base(taxService, storeService)
        {
            _logger = logger;
            _shippingService = shippingService;
        }
    
        public override Price CalculateShippingMethodPrice(ShippingMethodReadOnly shippingMethod, Guid currencyId, Guid countryId, Guid? regionId, TaxRate taxRate, ShippingCalculatorContext context)
        {
            var shippingPrice = _shippingService.GetShippingPrice(context.Order, currencyId);
    
            if (shippingPrice == null)
            {
                shippingPrice = base.CalculateShippingMethodPrice(shippingMethod, currencyId, countryId, regionId, taxRate, context);
            }
    
            return shippingPrice;
        }
    
        public override TaxRate CalculateShippingMethodTaxRate(ShippingMethodReadOnly shippingMethod, TaxSource taxSource, TaxRate fallbackTaxRate, ShippingCalculatorContext context)
        {
            return base.CalculateShippingMethodTaxRate(shippingMethod, taxSource, fallbackTaxRate, context);
        }
    }
    

    I put some logging in and found just doesn't hit CalculateShippingMethodPrice() and instead just falls back to the default shipping price

    This is using Vendr 1.2.10

    Any ideas what it could be?

    Cheers, Mark V

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Sep 28, 2020 @ 17:18
    Matt Brailsford
    100

    Hi Mark,

    My guess is that you are missing the ComposeAfterAttribute to tell your composer to run after ours and so yours is running first and so getting overridden https://vendr.net/docs/core/1-3-0/key-concepts/dependency-injection/#registering-dependencies

    Try adding the attribute and see if that helps.

    Matt

  • Warren Harding 132 posts 275 karma points
    Jul 08, 2022 @ 09:56
    Warren Harding
    0

    Hi all and appologies for digging up a dead thread - trying to do something similar here, however could you tell me what to reference in order to get ShippingService that is being injected here?

    I'm unable to get GetShippingPrice to work...

    Thank you

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jul 08, 2022 @ 10:01
    Matt Brailsford
    0

    I believe in this instance ShippingService is their own service that is responsible for calculating shipping for their needs, so it's something they have implemented and added to the DI container.

  • Warren Harding 132 posts 275 karma points
    Jul 08, 2022 @ 10:14
    Warren Harding
    0

    Ah that makes more sense, thank you

  • Mark V 28 posts 158 karma points
    Sep 29, 2020 @ 09:20
    Mark V
    0

    Hey,

    Yep, that's done it thank you!

    Turns out I missed this step

    Cheers, Mark V

Please Sign in or register to post replies

Write your reply to:

Draft