Custom Shipping Carrier is not showing up
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
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,
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
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
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;
class
FedExSettings : IShippingMethodSettings
public
ServiceSettings[] ServiceSettings
get
;
set
;
public
string
Title
get
;
set
;
public
string
MeterID
get
;
set
;
I hope this helps and please let me know if I can provide any further resources!
Regards,
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
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