CustomData in custom CarrierProvider is empty

Andy Bochmann asked on May 23, 2019 02:23

Hello,

I'm trying to access the CustomData property inside my own ICarrierProvider CanDeliver(Delivery delivery) implementation.

public bool CanDeliver(Delivery delivery)
{
    var value = ValidationHelper.GetInteger(delivery.CustomData["KEY"], 1);
    // ...
}

However, this data container is always empty, it doesn't contain the custom data values from my shopping cart. In other areas of Kentico, e.g. a custom IShoppingCartCalculator or custom OrderInfoProvider, this property always contains the custom data from the ShoppingCartInfo object.

Why isn't this the case for custom CarrierProviders? Is this a bug in Kentico or is there a different solution?

Thanks, Andy

Correct Answer

Andy Bochmann answered on May 23, 2019 19:41

Thank Dmitry,

I found a good solution. After asking this question, I found out I can write a custom DeliveryBuilder which can copy the neccessary data from the CalculationRequest object:

[assembly: RegisterImplementation(typeof(IDeliveryBuilder), typeof(CustomDeliveryBuilder))]
public class CustomDeliveryBuilder : DefaultDeliveryBuilder
{
    protected override void InitCustomData(CalculationRequest request)
    {
        base.InitCustomData(request);

        request.RequestCustomData.ColumnNames.ForEach(column => SetCustomData(column, request.RequestCustomData[column]));
    }
}

I hope this will also help others who have the same issue.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Dmitry Bastron answered on May 23, 2019 13:00

Hi Andy,

According to the documentation CustomData seems to be used across different methods inside Carrier Provider but not the CustomData from order or shopping cart.

What might be the case of using it during the delivery availability check? Could you give an axemple of business requirement so perhaps it could be done differently?

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.