to Custom shipping and adding tax to shipping

balinder singh asked on July 7, 2014 14:54

Hi there,

I am trying to add shipping on the fly in CustomShippingOptionProvider class under APP_CODE folder using 7.0 version. But unluckily It is getting into a loop and crash the site while running my code . Any help would be much appreciated.

Thanks..


protected override double CalculateShippingInternal(ShoppingCartInfo cartObj)
{

    // Check validity
    if (cartObj != null && cartObj.ShoppingCartShippingOptionID != 0 && ShippingOptionInfoProvider.GetShippingOptionInfo(cartObj.ShoppingCartShippingOptionID) != null)
    {
        // Check free shipping conditions
        try
        {

            // Check validity

         return base.CalculateShippingInternal(cartObj) + GetCalculatedShippingAmount(cartObj);


        }
        catch (Exception ee)
        {

        }

    }
    return base.CalculateShippingInternal(cartObj);
}

Recent Answers


Joshua Adams answered on July 10, 2014 16:02

Can you take your getcalculatedshippingamount method and call that only in the try catch. Then have your return outside of the try catch block. You could have it set to return that value if the getcalculatedshippingamount is greater than 0 or something.

0 votesVote for this answer Mark as a Correct answer

balinder singh answered on July 10, 2014 16:08

Thanks for the answer.

I have figured it out and now it is working pretty well.

Thanks, Balinder

My Solution:

    public class CustomShippingOptionInfoProvider : ShippingOptionInfoProvider
{
    /// <summary>
    /// Calculates shipping cost for the given shopping cart. Shipping free limit is applied. Shipping taxes are not included. Result is in site main currency. 
    /// </summary>
    /// <param name="cartObj">Shopping cart object</param>
    protected override double CalculateShippingInternal(ShoppingCartInfo cartObj)
    {
        if (cartObj != null && cartObj.ShoppingCartShippingOptionID != 0 && ShippingOptionInfoProvider.GetShippingOptionInfo(cartObj.ShoppingCartShippingOptionID) != null)
        {




            double defaultvalue = base.CalculateShippingInternal(cartObj);

            return GetCalculatedShippingAmount(cartObj, defaultvalue);


        }
      return base.CalculateShippingInternal(cartObj);

    }

    }
1 votesVote for this answer Mark as a Correct answer

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