API Questions on Kentico API.
Version 5.x > API > Custom Shipping Calculator - Clear Example View modes: 
User avatar
Member
Member
ssp - 10/3/2011 2:06:28 AM
   
Custom Shipping Calculator - Clear Example
Has anyone successfully implemented a customer shipping calculator based on item total weight?

I have read the following guides on devnet, but it makes little sense to me:

http://devnet.kentico.com/docs/ecommerceguide/index.html?custom_providers_overview.htm

I have successfully implemented a custom payment gateway, but custom shipping calculator implementation baffles me.

User avatar
Kentico Support
Kentico Support
janh-kentico - 10/3/2011 3:50:15 AM
   
RE:Custom Shipping Calculator - Clear Example
Hello,

If you will follow that link you mentioned, you can easily write your own custom function for a shipping calculation. The function may look like this:

public double CalculateShipping(object cartObj, string siteName)
{
CMS.Ecommerce.ShoppingCartInfo cart = cartObj as CMS.Ecommerce.ShoppingCartInfo;

if (cart != null)
{
double weight = 0.0;

// get weight
foreach (ShoppingCartItemInfo cartItem in cart.CartItems)
{
weight += cartItem.SKUObj.SKUWeight;
}

if (weight > 50.0)
{
return 10;
}
else
{
return 100;
}
}
// Get standard shipping price in other cases
return CMS.CMSEcommerce.ShippingOptionInfoProvider.CalculateShipping(cart, siteName);
}


Best regards,
Jan Hermann

User avatar
Member
Member
ssp - 10/3/2011 4:18:10 PM
   
RE:Custom Shipping Calculator - Clear Example
Hi Jan,

I have no problems writing the code to do the actual calculation.

The problem I have is that I don't understand how I would use the CalculateShipping method in the CustomShippingOptionInfoProvider.

For CustomPaymentGatewayProvider, you would simply create a new provider in CMSDesk > E-Commerce > Configuration > Payment methods and provide the Assembly name and Class name.

How would I do a similar thing for CustomShippingOptionInfoProvider? Or am I am thinking about this in a completely wrong way?

User avatar
Kentico Support
Kentico Support
janh-kentico - 10/4/2011 3:23:47 AM
   
RE:Custom Shipping Calculator - Clear Example
Hi,

The problem is, that the function for a shipping calculation is only the one and it is compiled to the dll file so you have to overload it with your own CalculateShipping method, in which you can check what kind of shipping your user chose or you can get also the shipping charge of that shipping and multiply it according to the total weight. Here are two approaches, how to use custom ecommerce providers:

1) http://devnet.kentico.com/docs/5_5r2/ecommerceguide/index.html?using_custom_providers.htm

2) If you are using Kentico CMS version 5.5 or higher, you can apply following approach:

- Copy all .cs files from the Kentico installation folder -> C:\Program Files\KenticoCMS\5.5R2\CodeSamples\CustomECommerceProvider to your project into the ~\App_Code\ECP\ directory

- Open web.config file and add two new keys into it:
<add key="CMSUseCustomEcommerceProviders" value="true" />
<add key="CMSCustomEcommerceProviderAssembly" value="App_Code" />

- Open the CMSCustom.cs file in the ~\App_Code\Global\CMS\ directory and please update the GetCustomClass function with the code below:

public static object GetCustomClass(string className)
{
// Provide your custom classes
switch (className)
{
// Custom E-commerce provider

case "App_Code.CustomAddressInfoProvider":

return new CMS.CustomECommerceProvider.CustomAddressInfoProvider();

case "App_Code.CustomCreditEventInfoProvider":

return new CMS.CustomECommerceProvider.CustomCreditEventInfoProvider();

case "App_Code.CustomCurrencyInfoProvider":

return new CMS.CustomECommerceProvider.CustomCurrencyInfoProvider();

case "App_Code.CustomCustomerInfoProvider":

return new CMS.CustomECommerceProvider.CustomCustomerInfoProvider();

case "App_Code.CustomDepartmentInfoProvider":

return new CMS.CustomECommerceProvider.CustomDepartmentInfoProvider();

case "App_Code.CustomDiscountCouponInfoProvider":

return new CMS.CustomECommerceProvider.CustomDiscountCouponInfoProvider();

case "App_Code.CustomDiscountLevelInfoProvider":

return new CMS.CustomECommerceProvider.CustomDiscountLevelInfoProvider();

case "App_Code.CustomExchangeRateInfoProvider":

return new CMS.CustomECommerceProvider.CustomExchangeRateInfoProvider();

case "App_Code.CustomExchangeTableInfoProvider":

return new CMS.CustomECommerceProvider.CustomExchangeTableInfoProvider();

case "App_Code.CustomInternalStatusInfoProvider":

return new CMS.CustomECommerceProvider.CustomInternalStatusInfoProvider();

case "App_Code.CustomManufacturerInfoProvider":

return new CMS.CustomECommerceProvider.CustomManufacturerInfoProvider();

case "App_Code.CustomOptionCategoryInfoProvider":

return new CMS.CustomECommerceProvider.CustomOptionCategoryInfoProvider();

case "App_Code.CustomOrderInfoProvider":

return new CMS.CustomECommerceProvider.CustomOrderInfoProvider();

case "App_Code.CustomOrderItemInfoProvider":

return new CMS.CustomECommerceProvider.CustomOrderItemInfoProvider();

case "App_Code.CustomOrderStatusInfoProvider":

return new CMS.CustomECommerceProvider.CustomOrderStatusInfoProvider();

case "App_Code.CustomOrderStatusUserInfoProvider":

return new CMS.CustomECommerceProvider.CustomOrderStatusUserInfoProvider();

case "App_Code.CustomPaymentOptionInfoProvider":

return new CMS.CustomECommerceProvider.CustomPaymentOptionInfoProvider();

case "App_Code.CustomPublicStatusInfoProvider":

return new CMS.CustomECommerceProvider.CustomPublicStatusInfoProvider();

case "App_Code.CustomShippingOptionInfoProvider":

return new CMS.CustomECommerceProvider.CustomShippingOptionInfoProvider();

case "App_Code.CustomShoppingCartInfoProvider":

return new CMS.CustomECommerceProvider.CustomShoppingCartInfoProvider();

case "App_Code.CustomShoppingCartItemInfoProvider":

return new CMS.CustomECommerceProvider.CustomShoppingCartItemInfoProvider();

case "App_Code.CustomSKUInfoProvider":

return new CMS.CustomECommerceProvider.CustomSKUInfoProvider();

case "App_Code.CustomSupplierInfoProvider":

return new CMS.CustomECommerceProvider.CustomSupplierInfoProvider();

case "App_Code.CustomTaxClassInfoProvider":

return new CMS.CustomECommerceProvider.CustomTaxClassInfoProvider();

case "App_Code.CustomVolumeDiscountInfoProvider":

return new CMS.CustomECommerceProvider.CustomVolumeDiscountInfoProvider();
}

return null;
}


Now you might be able to write your own CalculateShipping function in the CustomShippingOptionInfoProvider.cs file.

JH

User avatar
Member
Member
ssp - 10/19/2011 6:57:03 PM
   
RE:Custom Shipping Calculator - Clear Example
Hi Jan,

I finally got around to trying your last suggested method and the good news is, it worked!

Thanks a lot mate.

User avatar
Member
Member
eagleag - 12/11/2011 11:01:20 AM
   
RE:Custom Shipping Calculator - Clear Example
And if using 4.1 is this the same?

User avatar
Kentico Support
Kentico Support
kentico_janh - 12/12/2011 1:42:12 AM
   
RE:Custom Shipping Calculator - Clear Example
Hello,

Yes, it is very similar to the approach described in a first point of my answer. Please follow the link below for an approach for version 4.1 of Kentico CMS:

http://devnet.kentico.com/docs/4_1/ecommerceguide/index.html?custom_providers_overview.htm

Best regards,
Jan Hermann

User avatar
Guest
denis - 11/6/2013 2:02:42 AM
   
RE:Custom Shipping Calculator - Clear Example
I have version 7.0. In this version there are not these folders. How can I do?

thanks

User avatar
Kentico Support
Kentico Support
kentico_janh - 11/6/2013 2:17:32 AM
   
RE:Custom Shipping Calculator - Clear Example
Hello,

In version 7, you can implement it directly in the App_Code folder:

http://devnet.kentico.com/docs/devguide/index.html?custom_providers_info_example.htm

Best regards,
Jan Hermann

User avatar
Guest
denis - 11/6/2013 5:17:12 AM
   
RE:Custom Shipping Calculator - Clear Example
Thanks for the reply.

I tried to follow the instructions, but I get the following error:

The name 'ShippingOptionInfoProvider' does not exist in the current context.


How can I do?

Thanks

User avatar
Kentico Support
Kentico Support
kentico_janh - 11/11/2013 8:00:28 AM
   
RE:Custom Shipping Calculator - Clear Example
Hello,

Have you followed that documentation I provided? Have you registered proper namespaces?

using CMS.Ecommerce;
using CMS.SettingsProvider;


Best regards,
Jan Hermann