+1-888-365-2779
Try Now
More in this section

Forums / Ecommerce / Custom Shipping Carrier is not showing up

Custom Shipping Carrier is not showing up

7 posts, 0 answered
  1. Tim
    Tim  avatar
    34 posts
    Registered:
    16 Oct 2012
    14 Jun 2013
    Link to this post
    I created a very simple custom shipping carrier, followed all of the documented steps and I can't get it to show up.

    1. It doesn't show up in the create shipping methods carrier list, Should it  ?

    2. It doesn't show up on the checkout shipping screen, Do I need to modify the Shipping widget template?

    3. In the backend, AdvanceSettings->ShippingCarrierProviders->ProviderType:
    SitefinityWebApp.CustomShipping, SitefinityWebApp (namespace.class,Assembly)
    Even though the instructions say the providerType should be set to:
    assembly.namespace.classname  (I can't save my changes when i try this way)
    What is the correct format of the ProviderTypeField ?

    FYI, I set a breakpoint as well and never get to my provider. (wouldn't expect to, but you never know.  Below is my code (but since I'm not seeing the Carrier show up, I don't think 
    it'sa code problem (yet)

    namespace SitefinityWebApp
    {
        public class CustomShipping : IShippingCarrierProvider
        {
            public const string Name = "CustomShipping";
            private IShippingRequest _shippingData = null;
            private ShippingCarrierProviderSettings _carrierSettings = null;
            public ShippingResponseContext GetServiceRates(IShippingRequest shippingData)
            {
                _shippingData = shippingData;

                // Get an instance of the ShippingManager class.
                ShippingManager manager = new ShippingManager();

                // Retrieve the shipping provider's settings
                _carrierSettings = manager.GetShippingCarrierSetting(Name);
                if (_carrierSettings == null)
                {
                    throw new ArgumentException("Custom Shipping Provider settings not found");
                }

                // _shippingData holds all of the shopping cart and store configuration data 
                var TotalPrice = _shippingData.CartOrder.PreTaxTotal;  
                
                // Create an instance of the ShippingResponseObject class to return from the method.
                ShippingResponseContext shippingResponseContext = new ShippingResponseContext();
                shippingResponseContext.ShippingResponses = new            System.Collections.Generic.List<IShippingResponse>();
                GenericShippingResponse shippingResponse = new GenericShippingResponse();

                shippingResponse.ServicePrice = (Decimal)TotalPrice * (Decimal)0.1; //TODO the actual calualtion here  

                shippingResponseContext.ShippingResponses.Add(shippingResponse);

                return shippingResponseContext;
            }
        }
    }

    Any ideas?
    Thanks,
    Tim




  2. Svetla
    Svetla avatar
    36 posts
    Registered:
    07 Sep 2015
    17 Jun 2013
    Link to this post
    Hi Tim,

    I apologize for the troubles you are encountering with this.

    It seems that the documentation needs to be updated to reflect this change made in Sitefinity 6.0. Since Shipping Carrier Providers is no longer in use and your shipping provider now plugs directly into the UI, it is being installed via a new section - Shipping Methods. I managed to have your shipping method show up with the following settings(attached), however I am just reusing the settings class and the View Type from the FedEx configuration. You can inherit these classes or write your own as well. Make sure to use a unique Guid within your settings.

    Let us know how this works!

     

    Regards,
    Svetla
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Tim
    Tim  avatar
    34 posts
    Registered:
    16 Oct 2012
    18 Jun 2013 in reply to Svetla
    Link to this post
    Thanks you Svetla,

    I can now see my Shipping method, and get to the breakpoint in my code, but upon return, get the error listed below.  Is the above code snippet still valid?  Maybe I missed your point about inheriting from the Fedex classes.  Do you have an example ?

    thanks for you help
    Tim
    Value cannot be null.
    Parameter name: keyDescription: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.ArgumentNullException: Value cannot be null.
    Parameter name: key

    Source Error: 

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    Stack Trace: 

    [ArgumentNullException: Value cannot be null.
    Parameter name: key]
    System.Collections.Generic.Dictionary`2.FindEntry(TKey key) +10683813
    Telerik.Sitefinity.Modules.Ecommerce.BusinessServices.Shipping.Implementations.EcommerceShippingMethodService.GetApplicableShippingMethods(CheckoutState checkoutState, CartOrder cartOrder) +218
    Telerik.Sitefinity.Modules.Ecommerce.Orders.Web.UI.CheckoutViews.ShippingOptions.get_AvailableShippingMethods() +123
    Telerik.Sitefinity.Modules.Ecommerce.Orders.Web.UI.CheckoutViews.ShippingOptions.InitializeControls(GenericContainer container) +212
    Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +52
    System.Web.UI.Control.EnsureChildControls() +83
    System.Web.UI.Control.PreRenderRecursiveInternal() +42
    System.Web.UI.Control.PreRenderRecursiveInternal() +168
    System.Web.UI.Control.PreRenderRecursiveInternal() +168
    System.Web.UI.Control.PreRenderRecursiveInternal() +168
    System.Web.UI.Control.PreRenderRecursiveInternal() +168
    System.Web.UI.Control.PreRenderRecursiveInternal() +168
    System.Web.UI.Control.PreRenderRecursiveInternal() +168
    System.Web.UI.Control.PreRenderRecursiveInternal() +168
    System.Web.UI.Control.PreRenderRecursiveInternal() +168
    System.Web.UI.Control.PreRenderRecursiveInternal() +168
    System.Web.UI.Control.PreRenderRecursiveInternal() +168
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
  4. Tim
    Tim  avatar
    34 posts
    Registered:
    16 Oct 2012
    21 Jun 2013
    Link to this post
    Here are my settings from the advanced->Settings:
    settingstype="Telerik.Sitefinity.Modules.Ecommerce.Shipping.ShippingMethodSettings.FedExSettings, Telerik.Sitefinity.Ecommerce" 
    viewprovidertype="Telerik.Sitefinity.Modules.Ecommerce.Shipping.Web.UI.Fields.FedExSettingsField, Telerik.Sitefinity.Ecommerce" 
    type="SitefinityWebApp.CustomShipping, SitefinityWebApp" name="CustomShipping" 

    I suspect that the error I'm getting is because I am trying to use the FedEx as SettingsType and ViewProvider, but I need some direction on what to replace them with...

    Tim
  5. Svetla
    Svetla avatar
    36 posts
    Registered:
    07 Sep 2015
    25 Jun 2013
    Link to this post
    Hello Tim,

    I appologize for the confusion! 

    Here are a few changes as of 6.0 that you need to be aware of:

    1) Shipping providers are now registered in the shipping methods section in the documentation as per my previous post.
    2) There are a few slight modifications that we need to add to the shipping provider that you described below. Here is the code that worked for me. I have highlighted the differences:

    using System;
    using System.Linq;
    using Telerik.Sitefinity.Ecommerce.Shipping.Model;
    using Telerik.Sitefinity.Modules.Ecommerce.Shipping;
    using Telerik.Sitefinity.Modules.Ecommerce.Shipping.Business.Calculators;
    using Telerik.Sitefinity.Modules.Ecommerce.Shipping.Carriers;
     
    namespace SitefinityWebApp.Custom
    {
        public class CustomShippingProvider : ShippingCalculatorBase, IShippingCarrierProvider
        {
            public const string Name = "Custom";
            private IShippingRequest _shippingData = null;
            private FedExSettings _carrierSettings = null;
            public ShippingResponseContext GetServiceRates(IShippingRequest shippingData)
            {
                _shippingData = shippingData;
     
                // Get an instance of the ShippingManager class.
                ShippingManager manager = new ShippingManager();
     
                // Retrieve the shipping provider's settings
                _carrierSettings = GetShippingMethodSettings<FedExSettings>(shippingData.ShippingMethodId);
     
                if (_carrierSettings == null)
                {
                    throw new ArgumentException("Custom Shipping Provider settings not found");
                }
     
                // _shippingData holds all of the shopping cart and store configuration data
                var TotalPrice = _shippingData.CartOrder.PreTaxTotal;
     
                // Create an instance of the ShippingResponseObject class to return from the method.
                ShippingResponseContext shippingResponseContext = new ShippingResponseContext();
                shippingResponseContext.ShippingResponses = new System.Collections.Generic.List<IShippingResponse>();
                GenericShippingResponse shippingResponse = new GenericShippingResponse();
     
                shippingResponse.ServicePrice = (Decimal)TotalPrice * (Decimal)0.1; //TODO the actual calualtion here
                shippingResponse.ServiceCode = "SC";
     
                shippingResponseContext.ShippingResponses.Add(shippingResponse);
     
                return shippingResponseContext;
            }
        }
    }

    3) To reiterate through the highlighted fields
    • you need to inherit from the ShippingCalculatorBase base class, since it defines public method for getting the settings for a current shipping method. 
    • We are changing the previous call to GetShippingCarrierSettings to the newly defined one in the ShippingCalculatorBase class
    • The reason why you got the key must not be null is because there was no service code associated with the shipping method. I have hardcoded one in this class, which gave me a working shipping method, but this potentially can be based off the settings. For instance - in the fedex shipping provider we issue a request to a FedEx service and then iterate to the possible services and then add those responses to the ShippingResponseContext collection
    4) In the settings when you add a shipping methods you see 3 classes that you need to define
    • A shipping provider that needs to implement IShippingCarrierProvider and inherit ShippingCalculatorBase
    • A shipping settings class - we have just added the namespace for the Fedex settings class, but this is essentially a POCO that only needs to implement IShippingMethodSettings and it can contain any properties that your shipping provider needs. The interface only asks for ServiceSettings and Title, but you can add any properties in this class like this:
      class FedExSettings : IShippingMethodSettings
        {
            public ServiceSettings[] ServiceSettings { get; set; }
       
            public string Title { get; set; }
       
            public string MeterID { get; set; }
       
        }
    • A view provider type - here we also reused Fedex, but this is essentially a field control for persisting the settings defined in the IShippingMethodSettings. You can go about just using the ones for fedex or creating your own field control that will persist those values. If you need to implement your own settings(different hten the existing ones), I have attached how the fedex settings field control looks like for your reference. Of course for a custom provider they can be more stripped down. You will probably not need the service based settings that  we expose and toggle via javascript, it all just boils down to the textboxes for your service URLs - if you actually need these in any way. 

     I hope this helps and please let me know if I can provide any further resources!

    Regards,

    Svetla
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Tim
    Tim  avatar
    34 posts
    Registered:
    16 Oct 2012
    25 Jun 2013 in reply to Svetla
    Link to this post
    Thank you Svetla,
    I have it working now!

    For future readers:
    I was unable to resolve "FedExSettings" :  [private FedExSettings _carrierSettings = null;]
    but since I am doing my own calculations, it commented it out as well as the call to GetShippingMethodSettings() 

    Thanks again Svetla for your help!
    -Tim
  7. Svetla
    Svetla avatar
    36 posts
    Registered:
    07 Sep 2015
    25 Jun 2013
    Link to this post
    Hello Tim,

    Thanks for the feedback!
    You're right, this is one thing I forgot to mention - the FedExSettings class is internal indeed so I just created a new class in my project that implements IShippingMethodSettings. 

    I'm adding this just in case you run into a scenario where you need to provide and configure settings in your shipping providers.

    Regards,
    Svetla
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
7 posts, 0 answered