I've got an issue on the CustomShippingCalculator when it trying to run on the development environment of Umbraco cloud the code doesn't get hit or getting inside the shipping calculator function. Bt its working fine on my local solution. Any idea. Why this is happening?
Hmm, that does sound odd. First thing would be to check to make sure your code is absolutely deployed on cloud? And also maybe check your log file to see if there is anything in there to suggest why it wouldn't load?
Tried logging there is no such logs for why it wouldn't load. I've logged inside the customShippingcalculator but that also wouldn't load in the trace logs. Deployed the DLL's manually and deployed again . But no changes.
Can you please explain how these events work briefly? Is Shipping calculator triggers outside from the domain? Any authentication issue or anything like that to block the event?
Hi Matt, I've tried other custom calculators like Order Line Calculator
Its works fine on Umbraco cloud development environment. Event triggers finely. Only this issue on the Shipping calculator. :/
That's very strange as the different calculators are all loaded by the same approach so if one works, I would expect them all to work. Are you doing anything custom with AutoFac at all? this is the DI framework TC uses to load it's dependencies so just making sure there is nothing that would affect it.
I'm just checking back with the previous project owner just in case they have any known issues or ideas so I'll see what they come back with and let you know.
Are you able to share the code for you Shipping Calculator? You can strip out the actual logic of the functions if it's sensitive, the main thing I want to see is how you are using the SupressDependency attribute.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TeaCommerce.Api.Dependency;
using TeaCommerce.Api.Models;
using TeaCommerce.Api.PriceCalculators;
using TeaCommerce.Api.Services;
using Umbraco.Core.Logging;
[SuppressDependency("TeaCommerce.Api.PriceCalculators.IShippingCalculator", "TeaCommerce.Api")]
public class CustomShippingCalculator : ShippingCalculator
{
public CustomShippingCalculator(IVatGroupService vatGroupService)
: base(vatGroupService)
{
}
public override Price CalculatePrice(ShippingMethod shippingMethod, Currency currency, Order order)
{
try
{
LogHelper.Info<CustomShippingCalculator>($"CustomShippingCalculator/CalculatePrice order id:{order.Id}");
if (order != null && order.OrderLines.Count() != 0 && !string.IsNullOrWhiteSpace(order.Properties["shippingRateFinal"]))
{
//shippingRate Comes with incl/excl according to VAT logic
var shippingRate = Convert.ToDecimal(order.Properties["shippingRateFinal"]);
if (shippingRate != 0)
{
LogHelper.Info<CustomShippingCalculator>($"CustomShippingCalculator/CalculatePrice shippingRate:{shippingRate}");
return new Price(shippingRate, new VatRate(0), currency);
}
else
{
return new Price(currency);
}
}
else
{
return new Price(currency);
}
}
catch (Exception ex)
{
LogHelper.Error<CustomShippingCalculator>($"CustomShippingCalculator/CalculatePrice Error occured due to:", ex);
throw;
}
}
}
}
Have you looked in your umbraco deploy log files? In Umbraco Cloud dashboard, navigate to Kudu from the project dropdown
From there, go to "Debug Console > CMD" from the upper menu, and then in the table below go to "site > deployments" and review the recent deployments log files to see if anything failed to deploy. I have had it before where it's failed to compile on Cloud and so the file deployment has failed (thought I would have expected cloud support to have looked into this for you)
And if you go into "site > wwroot > bin" and download your DLL, are you able to use a tool like DotPeek to review the DLL code and see that your code is in the deployed DLL?
Hmm, I'm really struggling for what else to suggest then.
If the code is there, and other calculators are working, I can't see why this one wouldn't work.
Ultimately something must be affecting Autofac in some way, either causing the core module registrations to run multiple times such that it's resetting the overrides, or the class just isn't being found in the DLL. I take it your other calculators are within the same DLL? if so, that would suggest the DLL is being found ok.
Looking in the code for TC, when supressing a dependency, it should write to the log file if it fails, so again, I would expect to see that if this was the problem.
Yeah It all within the same dll. We've tried a basic Umbraco website with teacommerce starter kit installed and done a hardcoded shipping calculator that given in the teacommerce doc . The website was hosted out of umbraco cloud and it worked.
Ok, last thing I can think. Just before the shipping calculator is called, it checks order.ShipmentInformation.ShippingMethodId and if it's null, it won't access the calculator.
Custom Shipping calculator load issue
I've got an issue on the CustomShippingCalculator when it trying to run on the development environment of Umbraco cloud the code doesn't get hit or getting inside the shipping calculator function. Bt its working fine on my local solution. Any idea. Why this is happening?
Hi Vineeth,
Hmm, that does sound odd. First thing would be to check to make sure your code is absolutely deployed on cloud? And also maybe check your log file to see if there is anything in there to suggest why it wouldn't load?
Tried logging there is no such logs for why it wouldn't load. I've logged inside the customShippingcalculator but that also wouldn't load in the trace logs. Deployed the DLL's manually and deployed again . But no changes.
Ok, I'm not too familiar with cloud, but are you able to restart the app instance? Wondering if the DLLs haven't reloaded.
Ok anyway thanks for the help Matt :) .
Did you get it to work? Happy to keep suggesting what I can.
Not yet. I'm going to ask the Umbraco cloud support team and let you know
Ok great, let me know how you get on 👍
Hi Matt, This issue still persists Cloud support team is also struggling for a solution :( .
Can you please explain how these events work briefly? Is Shipping calculator triggers outside from the domain? Any authentication issue or anything like that to block the event?
Hi Vineeth,
I'm currently away on holiday right now so don't have the source code to hand to dig into this. Are you able to wait till Monday when I'm back?
Yeah sure
Awesome. I'll get back to you then. In the meantime enjoy the rest of your week, and thank you for using Tea Commerce.
Hi Matt, I've tried other custom calculators like Order Line Calculator Its works fine on Umbraco cloud development environment. Event triggers finely. Only this issue on the Shipping calculator. :/
Hi Vineeth,
That's very strange as the different calculators are all loaded by the same approach so if one works, I would expect them all to work. Are you doing anything custom with AutoFac at all? this is the DI framework TC uses to load it's dependencies so just making sure there is nothing that would affect it.
Yeah, it's really strange. I'm doing absolutely nothing with AutoFac .Cloud Team is checking since last week they don't have any clue yet .
Strange.
I'm just checking back with the previous project owner just in case they have any known issues or ideas so I'll see what they come back with and let you know.
Thank you Matt
Are you able to share the code for you Shipping Calculator? You can strip out the actual logic of the functions if it's sensitive, the main thing I want to see is how you are using the SupressDependency attribute.
Yes sure. Please have a look
Hmm, that looks ok to me.
Have you looked in your umbraco deploy log files? In Umbraco Cloud dashboard, navigate to Kudu from the project dropdown
From there, go to "Debug Console > CMD" from the upper menu, and then in the table below go to "site > deployments" and review the recent deployments log files to see if anything failed to deploy. I have had it before where it's failed to compile on Cloud and so the file deployment has failed (thought I would have expected cloud support to have looked into this for you)
I can't see any deployment error on the logs :/
And if you go into "site > wwroot > bin" and download your DLL, are you able to use a tool like DotPeek to review the DLL code and see that your code is in the deployed DLL?
Yeah I will give a try on that and get back to you
I've checked the deployed DLL with DotPeek. All the codes are there.
Hmm, I'm really struggling for what else to suggest then.
If the code is there, and other calculators are working, I can't see why this one wouldn't work.
Ultimately something must be affecting Autofac in some way, either causing the core module registrations to run multiple times such that it's resetting the overrides, or the class just isn't being found in the DLL. I take it your other calculators are within the same DLL? if so, that would suggest the DLL is being found ok.
Looking in the code for TC, when supressing a dependency, it should write to the log file if it fails, so again, I would expect to see that if this was the problem.
Yeah It all within the same dll. We've tried a basic Umbraco website with teacommerce starter kit installed and done a hardcoded shipping calculator that given in the teacommerce doc . The website was hosted out of umbraco cloud and it worked.
Wow, that's pretty strange.
Ok, last thing I can think. Just before the shipping calculator is called, it checks
order.ShipmentInformation.ShippingMethodId
and if it's null, it won't access the calculator.Your order has a shipping method id set right?
I didn't get what you said on resetting the overrides issue
' causing the core module registrations to run multiple times such that it's resetting the overrides' ?
Just if Autofac is configured twice, you might get a situation like
Oh, my man. That was a shipping id setting issue. It worked now :D . Thanks a lot. :D
🎉🎉🎉🎉🎉
Phew! Well that took some doing, but so glad we got there.
is working on a reply...