Not sure what is wrong, but does it work if you use attribute registration instead? I.e. ServiceConfiguration attribute ?
@Quan Mai: I tried that too just now, but the same result
[ServiceConfiguration(ServiceType = typeof(IShippingGateway), Lifecycle = ServiceInstanceScope.Singleton)] public class CustomShipping : IShippingGateway { public ShippingRate GetRate(IMarket market, Guid methodId, Shipment shipment, ref string message) { ShippingRate shippingRate = (ShippingRate)null; ShippingMethodDto shippingMethod = ShippingManager.GetShippingMethodsByMarket(ServiceLocator.Current.GetInstance<Mediachase.Commerce.ICurrentMarket>().GetCurrentMarket().MarketId.ToString(), false); ShippingMethodDto.ShippingMethodRow shippingMethodRow = shippingMethod.ShippingMethod[0]; shippingRate = new ShippingRate(methodId, shippingMethodRow.DisplayName, new Money(shippingMethodRow.BasePrice, new Currency(shippingMethodRow.Currency))); return shippingRate; } }
Hi @Quan Sorry for the late reply, below is the stack trace for your reference:
https://www.screencast.com/t/tScdKWphIesw
Also, the support team has escalated this issue to the Product Development Engineering team. I sent my solution and the database to the support team and they as well were unable to figure out this error.
Hi @Quan Sorry for the late reply, below is the stack trace for your reference:
https://www.screencast.com/t/tScdKWphIesw
Also, the support team has escalated this issue to the Product Development Engineering team. I sent my solution and the database to the support team and they as well were unable to figure out this error.
@Quan: To the best of my knowledge, no. But we also have a shippping library which we add into our project. Also, I have replied to the support ticket just now; asking if they need anything else (Is there a way to have this discussion on the ticket?).
I can't really access the ticket now - This is from dotPeek (not dotTrace) - I changed the namespace for you.
This is from the solution you sent. there was no source code (only the dll), so I couldn't try the attribute
One thing to look into is to make sure the shipping method was configured with class name in Commerce Manager. As you said it worked before upgrade so it's unlikely, but let's make sure no stone is left untuned
namespace name.space { public class CustomShippingGateway : IShippingGateway { private IMarket _market; public CustomShippingGateway(IMarket market) { this._market = market; } public CustomShippingGateway() { } public ShippingRate GetRate(IMarket market, Guid methodId, Shipment shipment, ref string message) { ShippingRate shippingRate = (ShippingRate) null; ICustomShipping customShipping = ServiceLocator.Current.GetAllInstances<ICustomShipping>().FirstOrDefault<ICustomShipping>(); if (customShipping != null) shippingRate = customShipping.GetCustomRate(methodId, shipment, ref message); if (shippingRate == null) message = "The shipping method could not be loaded."; return shippingRate; } } }
HI @Quan @Siddhart
We are facing the same issue with our upgrade. We are at version 12.0.1.
However our get rate method does not get hit.
using System;
using BaseContentTypes.Business;
using EPiServer;
using EPiServer.ServiceLocation;
using Hephaestus.Commerce.Basket;
using Hephaestus.Commerce.CustomerService.CustomerContactService;
using Hephaestus.Commerce.Shipping;
using log4net;
using Mediachase.Commerce;
using Mediachase.Commerce.Catalog;
using Mediachase.Commerce.Orders;
namespace WexShippingProvider
{
[ServiceConfiguration(ServiceType = typeof(IShippingGateway), Lifecycle = ServiceInstanceScope.Singleton)]
public class WexShipping : IShippingGateway
{
private static readonly ILog Logger = LogManager.GetLogger("OrderImportLogger");
//private IMarket _market;
private IBasketService _basketService;
private ICustomerContactService _customerContactService;
private ReferenceConverter _referenceConverter;
private IContentLoader _contentLoader;
//public WexShipping(IMarket market)
//{
// this._market = market;
//}
//public WexShipping()
//{
//}
public ShippingRate GetRate(IMarket market, Guid methodId, Shipment shipment, ref string message)
{
string actionName = string.Empty;
var id = (shipment[BaseContentTypes.Constants.MetaFieldNames.ErpDeliveryServiceId] == null ||
string.IsNullOrEmpty(shipment[BaseContentTypes.Constants.MetaFieldNames.ErpDeliveryServiceId].ToString())) ? string.Empty :
shipment[BaseContentTypes.Constants.MetaFieldNames.ErpDeliveryServiceId].ToString();
try
{
actionName += $"Setting up references;";
_referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>();
_customerContactService = ServiceLocator.Current.GetInstance<ICustomerContactService>();
_basketService = ServiceLocator.Current.GetInstance<IBasketService>();
_contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
actionName += $"Getting delivery service;";
var deliveryService = new WexDeliveryMatrix(_referenceConverter, _customerContactService, _contentLoader);
actionName += $"Checking ErpDeliverServiceId;";
if (shipment[BaseContentTypes.Constants.MetaFieldNames.ErpDeliveryServiceId] == null ||
string.IsNullOrEmpty(shipment[BaseContentTypes.Constants.MetaFieldNames.ErpDeliveryServiceId].ToString()))
{
return null;
}
var selectedDelivery = deliveryService.GetDeliveryServiceById(shipment[BaseContentTypes.Constants.MetaFieldNames.ErpDeliveryServiceId].ToString(), shipment);
//TODO: DeliveryFix
actionName += $"Response Name={selectedDelivery.Name} Cost={Convert.ToString(selectedDelivery.Cost)};";
var wexShippingMethodName = selectedDelivery.Name;
var shippingCost = selectedDelivery.Cost;
var shippingrate = new ShippingRate(methodId, wexShippingMethodName,
Money.CreateMoneyWithDefaultCurrencyFallback(shippingCost, new Currency(market.DefaultCurrency)));
actionName += $"Exiting;";
//Logger.Error($"GetRate for ServiceId={id} Exception at: {actionName}");
return shippingrate;
}
catch (Exception ex)
{
Logger.Error($"GetRate for ServiceId={id} Exception at: {actionName}", ex);
}
return null;
}
}
}
Regards
Sandeep
Hi,
Below is a custom shipping implementation, I have also registered it in the ConfigureContainer method. But it doesnt even hit the break point and I get an error saying the IShippingGateway or IShippingPlugin is not implemented. I migrated from 10.7.0 to 12.2.0 FYI. Could someone please guide me on this:
Below is the Initialization:
Below is the custom shipping logic (setting it to 0.0 as a sample):