Overview

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The E-commerce module allows you to override the default behavior and calculations by using custom providers that ensure various operations.

 

How does it work?

 

ecommerceguide_clip0205

 

For more information please refer to the Using custom providers chapter.

 

The following example shows the way of customizing the calculation of the shipping cost by modifying the CMS.CustomECommerceProvider.CustomShippingOptionInfoProvider.CalculateShipping method. Similarly, you can modify any method of any class from the CMS.CustomECommerceProvider library.All the methods that can be customized call by default the equivalent methods from the CMS.CMSEcommerce namespace. This ensures the standard behaviour in the case the given method is not modified and the using custom e-commerce provider is enabled at the same time.

 

1. The default code of the CMS.CustomECommerceProvider.CustomShippingOptionInfoProvider.CalculateShipping method.

 

public double CalculateShipping(object cartObj, string siteName)

{

          return CMS.CMSEcommerce.ShippingOptionInfoProvider.CalculateShipping((CMS.Ecommerce.ShoppingCartInfo)cartObj, siteName);

}

 

2. The customized code of the CMS.CustomECommerceProvider.CustomShippingOptionInfoProvider.CalculateShipping method

 

using CMS.Ecommerce;

using CMS.SettingsProvider;

using CMS.SiteProvider;

 

public double CalculateShipping(object cartObj, string siteName)

{          

 

           CMS.Ecommerce.ShoppingCartInfo cart = cartObj as CMS.Ecommerce.ShoppingCartInfo;

          if (cart != null)

           {

              if ((cart.UserInfoObj != null) && (cart.UserInfoObj.IsInRole("VIPCutomers", siteName)))

               {

                  // Free shipping for VIP customers

                  return 0;

               }

              else

               {

                  // Get shipping address details

                   CMS.Ecommerce.AddressInfo address = CMS.Ecommerce.AddressInfoProvider.GetAddressInfo(cart.ShoppingCartShippingAddressID);

                  if (address != null)

                   {

                      // Get shipping address country

                      CountryInfo country = CountryInfoProvider.GetCountryInfo(address.AddressCountryID);

                      if ((country != null) && (country.CountryName.ToLower() != "usa"))

                       {

                          // Add an extra charge to standard shipping price for non-usa customers

                          double extraCharge = SettingsKeyProvider.GetDoubleValue("ShippingExtraCharge");

                          return CMS.CMSEcommerce.ShippingOptionInfoProvider.CalculateShipping(cart, siteName) + extraCharge;

                       }

                   }

               }

           }

 

          // Get standard shipping price in other cases

          return CMS.CMSEcommerce.ShippingOptionInfoProvider.CalculateShipping(cart, siteName);

}

 

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