Try our conversational search powered by Generative AI!

Cutom shipping implemetation not working after upgrade to 12.2.0

Vote:
 

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:

public class SampleInitialization : IInitializableModule, IConfigurableModule
{
public void Initialize(InitializationEngine context)
{
//Add initialization logic, this method is called once after CMS has been initialized
}

public void Uninitialize(InitializationEngine context)
{
//Add uninitialization logic
}

public void ConfigureContainer(ServiceConfigurationContext context)
{
var services = context.Services;

services.AddSingleton();
}
}

Below is the custom shipping logic (setting it to 0.0 as a sample):

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().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;
}
}



#193528
Edited, May 30, 2018 17:40
Vote:
 

Not sure what is wrong,  but does it work if you use attribute registration instead?  I.e.  ServiceConfiguration attribute  ? 

#193530
May 30, 2018 17:59
Vote:
 

@Quan Mai: I tried that too just now, but the same result frown

[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;
}
}





#193531
Edited, May 30, 2018 18:12
Vote:
 
<p>Can you post the full stacktrace please?</p>
#193553
May 31, 2018 9:49
Vote:
 

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. 

#193833
Jun 05, 2018 17:09
Vote:
 

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. 

#193835
Jun 05, 2018 17:09
Vote:
 
<p>It was me who was looking into the case. I used dotTrace to decompile the assembly and it has no attribute. Was there something missing?&nbsp;</p>
#193837
Jun 05, 2018 17:50
Vote:
 

@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?). 

#193838
Jun 05, 2018 18:07
Vote:
 

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;
    }
  }
}
#193840
Jun 05, 2018 19:07
Vote:
 

[Pasting files is not allowed]

#193871
Edited, Jun 06, 2018 18:46
Vote:
 
<p>You should have removed the constructor which takes IMarket, that is no longer needed and was mentioned in the breaking change document :)</p>
#193873
Jun 06, 2018 19:19
Vote:
 

@Quan: Works like a charm now :) Thank you so much! :) _/\_

#193877
Jun 06, 2018 19:34
Vote:
 

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

#266934
Nov 18, 2021 12:45
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.