Replace / Overwrite DefaultDeliveryBuilder?

Senior Software Engineer - Kentico Xperience MVP

Trevor Fayas asked on August 25, 2017 19:51

Hey fellow Kentico-ians,

I'm wondering if anyone knows how to implement a custom DeliveryBuilder. We are trying to configure some customization that will split single cart items into multiple DeliveryItems, so we need to override the DefaultDeliveryBuilder.AddItems(ShoppingCartInfo cart) or something similar.

Correct Answer

Brenden Kehren answered on August 25, 2017 22:09

So the documentation has something a bit different than you have for your assembly.

Should be:
[assembly:RegisterImplementation(typeof(IDeliveryBuilder), typeof(CustomDeliveryBuilder))]

VS:

[assembly: RegisterCustomClass("CustomDeliveryBuilder", typeof(CustomDeliveryBuilder))]

May make a difference for you. Also looks like you can override these 2 methods:

  • GetItemCustomDataContainers - Override this method to populate the supplied list with the custom data containers.
  • InitCustomData - Override this method to add custom data to the constructed Delivery.
0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on August 25, 2017 20:01

Wonder if you can't assign something to the sku and do some work like I mentioned here:

https://devnet.kentico.com/questions/split-orderitems-into-new-individual-orders

If not, then Kentico 11 coupled with UCommerce will offer Split Shipments out of the box.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on August 25, 2017 20:15

That's the second option yeah, to make a module to store the split shipment information and store it in the item's custom data, then modify each shipping provider to look for that when processing, but if i can overwrite the BuildDelivery methods then i don't have to modify each shipping provider.

i'm looking forward to UCommerce.

Anyone else, otherwise i'll try contacting support. Got to be a way to overwrite it, sadly i've tried the below with no luck:

[assembly: RegisterCustomClass("CustomDeliveryBuilder", typeof(CustomDeliveryBuilder))]
public class CustomDeliveryBuilder : DefaultDeliveryBuilder
    {
        public override Delivery BuildDelivery()
        {
            var baseDelivery = base.BuildDelivery();
            return baseDelivery;
        }
     }
0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on August 25, 2017 22:15

That was it! It triggered properly with that one, thanks Brenden. I'll have to decompile the existing builder so i can only modify the couple things needed!

1 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on August 28, 2017 16:17

Just to add in additionally from support, you can overwrite specific methods of the existing class that uses the implementation by using the RegisterImplementation of your class that inherits from the other one... here's the below for anyone else!

using CMS;
using CMS.Ecommerce;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for CustomDefaultDeliveryBuildercs
/// </summary>
[assembly: RegisterImplementation(typeof(IDeliveryBuilder), typeof(MyDeliveryBuilder))]
public class MyDeliveryBuilder : DefaultDeliveryBuilder
{
    protected override void AddItems(ShoppingCartInfo cart, Func<ShoppingCartItemInfo, bool> itemSelector = null)
    {
        itemSelector = itemSelector ?? (item => true);

        var items = cart.CartContentItems
                        .Where(itemSelector)
                        .Where(item => !item.SKU.IsProductOption || item.SKU.IsAccessoryProduct);
        // Modify below to add multiple 'items' for multiple shipments
        foreach (var item in items)
        {
            // If the item is a multiple shipment, create 2 seperate CartItems and add them seperately with the proper dimensions
            AddItem(item);
        }
    }
}
0 votesVote for this answer Mark as a Correct answer

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