예제 #1
0
        public static decimal GetMainSkuShippingCost(Cart cart)
        {
            decimal            shippingCost    = 0;
            List <SkuShipping> skuShippingList = ShippingDAL.GetSkuShipping();

            SitePreference sitePreference = CSFactory.GetCartPrefrence(cart);

            if (sitePreference != null)
            {
                foreach (Sku sku in cart.CartItems)
                {
                    if (SiteBasePage.IsMainSku(sku.SkuId))
                    {
                        CSData.SkuShipping skuShipping = skuShippingList.FirstOrDefault(x =>
                        {
                            return(x.PrefId == sitePreference.ShippingPrefID &&
                                   x.SkuId == sku.SkuId);
                        });

                        if (skuShipping != null)
                        {
                            shippingCost += (skuShipping.Cost * sku.Quantity);
                        }
                    }
                }
            }

            return(shippingCost);
            // TODO: add rush sku cost support
        }
예제 #2
0
        private decimal GetSurchargeAmt(Order orderItem)
        {
            SitePreference sitePreference = CSFactory.GetCartPrefrence();

            List <SkuShipping> shippingCosts = ShippingDAL.GetSkuShipping();

            decimal surcharge = 0;

            foreach (Sku sku in orderItem.SkuItems)
            {
                if (!sku.AttributeValuesLoaded)
                {
                    sku.LoadAttributeValues();
                }

                if (!sku.SkuCode.ToUpper().Contains("SURCHARGE"))
                {
                    continue;
                }

                CSData.SkuShipping skuShipping = shippingCosts.FirstOrDefault(x =>
                {
                    return(x.PrefId == sitePreference.ShippingPrefID &&
                           x.SkuId == sku.SkuId);
                });

                if (skuShipping != null)
                {
                    surcharge += (skuShipping.Cost * sku.Quantity);
                }
            }

            return(surcharge);
        }
예제 #3
0
        private decimal GetMerchandiseSubtotal(Order orderItem)
        {
            SitePreference sitePreference = CSFactory.GetCartPrefrence();

            List <SkuShipping> shippingCosts = ShippingDAL.GetSkuShipping();

            decimal rushCharge = 0;

            foreach (Sku sku in orderItem.SkuItems)
            {
                if (!sku.AttributeValuesLoaded)
                {
                    sku.LoadAttributeValues();
                }

                if (!sku.GetAttributeValue("RushSku", false))
                {
                    continue;
                }

                CSData.SkuShipping skuShipping = shippingCosts.FirstOrDefault(x =>
                {
                    return(x.PrefId == sitePreference.ShippingPrefID &&
                           x.SkuId == sku.SkuId);
                });

                if (skuShipping != null)
                {
                    rushCharge += (skuShipping.Cost * sku.Quantity);
                }
            }

            return(rushCharge);
        }
        public decimal CalculateFullPrice(CSBusiness.ShoppingManagement.Cart cart)
        {
            decimal        taxToReturn   = 0;
            SitePreference list          = CSFactory.GetCartPrefrence();
            decimal        taxableAmount = cart.SubTotalFullPrice;

            if (list.IncludeShippingCostInTaxCalculation)
            {
                decimal shippingCostDiscount = 0;
                if (CSWebBase.SiteBasePage.IsFreeShipOrderMainSku(cart))
                {
                    shippingCostDiscount = SiteBasePage.GetMainSkuShippingCost(cart);
                }

                taxableAmount += cart.ShippingCost;
                if (cart.ShippingMethod == CSBusiness.Shipping.UserShippingMethodType.Rush)
                {
                    taxableAmount += cart.RushShippingCost;
                }

                taxableAmount -= shippingCostDiscount; // don't count shipping cost amount in tax calcultor
            }

            //If this returns a value, it means country has states and we need to
            //find tax for states
            if (cart.ShippingAddress.CountryId > 0)
            {
                //CodeReview By Sri on 09/15: Need to change TaxRegionCache Object
                TaxRegion countryRegion = null, stateRegion = null, zipRegion = null;

                //Comments on 11/2: pulling data from Cache object
                TaxregionCache   cache      = new TaxregionCache(HttpContext.Current);
                List <TaxRegion> taxRegions = (List <TaxRegion>)cache.Value;

                countryRegion = taxRegions.FirstOrDefault(t => t.CountryId == cart.ShippingAddress.CountryId && t.StateId == 0 && string.IsNullOrEmpty(t.ZipCode));
                stateRegion   = taxRegions.FirstOrDefault(t => t.CountryId == cart.ShippingAddress.CountryId && t.StateId == cart.ShippingAddress.StateProvinceId && string.IsNullOrEmpty(t.ZipCode));
                zipRegion     = taxRegions.FirstOrDefault(t => t.CountryId == cart.ShippingAddress.CountryId && t.StateId == cart.ShippingAddress.StateProvinceId &&
                                                          t.ZipCode == cart.ShippingAddress.ZipPostalCode);

                //Tax regions are always returned by country
                //taxRegions = CSFactory.GetTaxByCountry(cart.ShippingAddress.CountryId);
                if (zipRegion != null)
                {
                    taxToReturn = taxableAmount * zipRegion.Value / 100;
                }
                else if (stateRegion != null)
                {
                    taxToReturn = taxableAmount * stateRegion.Value / 100;
                }
                else if (countryRegion != null)
                {
                    taxToReturn = taxableAmount * countryRegion.Value / 100;
                }
            }
            return(Math.Round(taxToReturn, 2));
        }
예제 #5
0
        private decimal GetRushShippingCost(List <Sku> skuItems, ref ShippingMethodEnum shippingMethod)
        {
            SitePreference sitePreference = CSFactory.GetCartPrefrence();

            List <SkuShipping> shippingCosts = ShippingDAL.GetSkuShipping();

            decimal rushCharge = 0;

            foreach (Sku sku in skuItems)
            {
                if (!sku.AttributeValuesLoaded)
                {
                    sku.LoadAttributeValues();
                }

                if (!sku.GetAttributeValue("RushSku", false))
                {
                    continue;
                }

                CSData.SkuShipping skuShipping = shippingCosts.FirstOrDefault(x =>
                {
                    return(x.PrefId == sitePreference.ShippingPrefID &&
                           x.SkuId == sku.SkuId);
                });

                if (skuShipping != null)
                {
                    // this will set shippingmethod to last one in list - there should really be on rush sku in cart, however
                    switch (sku.SkuCode.ToUpper())
                    {
                    case "OVERNIGHT":
                        shippingMethod = ShippingMethodEnum.NextDay;
                        break;

                    case "002UPS":
                        shippingMethod = ShippingMethodEnum.SecondDay;
                        break;
                    }

                    rushCharge += (skuShipping.Cost * sku.Quantity);
                }
            }

            return(rushCharge);
        }
        public decimal CalculateSkuBaseShipping(int skuId)
        {
            //Order orderData = CSResolve.Resolve<IOrderService>().GetOrderDetails(orderId);
            SitePreference     shippingPreferences = CSFactory.GetCartPrefrence(CartContext.CartInfo);
            int                prefid           = shippingPreferences.ShippingPrefID;
            List <SkuShipping> skuShippingItems = ShippingDAL.GetSkuShipping();
            decimal            shippingCost     = 0;

            int totalShippingSettings = skuShippingItems.Count;

            for (int i = 0; i < totalShippingSettings; i++)
            {
                SkuShipping currentSetting = skuShippingItems[i];
                if (skuId == currentSetting.SkuId && prefid == currentSetting.PrefId)
                {
                    shippingCost += currentSetting.Cost;
                }
            }
            return(shippingCost);
        }
예제 #7
0
        public static decimal CalculateTaxRate(int orderId, decimal skuPrice)
        {
            Order          orderItem     = new OrderManager().GetBatchProcessOrder(orderId);
            decimal        taxToReturn   = 0;
            SitePreference list          = CSFactory.GetCartPrefrence();
            decimal        taxableAmount = skuPrice;

            //If this returns a value, it means country has states and we need to
            //find tax for states
            if (orderItem.CustomerInfo.ShippingAddress.CountryId > 0)
            {
                //CodeReview By Sri on 09/15: Need to change TaxRegionCache Object
                TaxRegion countryRegion = null, stateRegion = null, zipRegion = null;

                //Comments on 11/2: pulling data from Cache object
                TaxregionCache   cache      = new TaxregionCache(HttpContext.Current);
                List <TaxRegion> taxRegions = (List <TaxRegion>)cache.Value;

                countryRegion = taxRegions.FirstOrDefault(t => t.CountryId == orderItem.CustomerInfo.ShippingAddress.CountryId && t.StateId == 0 && string.IsNullOrEmpty(t.ZipCode));
                stateRegion   = taxRegions.FirstOrDefault(t => t.CountryId == orderItem.CustomerInfo.ShippingAddress.CountryId && t.StateId == orderItem.CustomerInfo.ShippingAddress.StateProvinceId && string.IsNullOrEmpty(t.ZipCode));
                zipRegion     = taxRegions.FirstOrDefault(t => t.CountryId == orderItem.CustomerInfo.ShippingAddress.CountryId && t.StateId == orderItem.CustomerInfo.ShippingAddress.StateProvinceId &&
                                                          t.ZipCode == orderItem.CustomerInfo.ShippingAddress.ZipPostalCode);

                //Tax regions are always returned by country
                //taxRegions = CSFactory.GetTaxByCountry(cart.ShippingAddress.CountryId);
                if (zipRegion != null)
                {
                    taxToReturn = zipRegion.Value;
                }
                else if (stateRegion != null)
                {
                    taxToReturn = stateRegion.Value;
                }
                else if (countryRegion != null)
                {
                    taxToReturn = countryRegion.Value;
                }
            }

            return(taxToReturn);
        }
예제 #8
0
        /// <summary>
        /// Retrieve data that is going to be stored in cache
        /// </summary>
        /// <returns></returns>
        protected override object GetData()
        {
            SitePreference list = CSFactory.GetCartPrefrence();

            return(list);
        }
        public void Calculate(Cart cart, int prefID)
        {
            SitePreference shippingPreferences = CSFactory.GetCartPrefrence(cart);

            if (shippingPreferences != null)
            {
                ShippingOptionType  option     = shippingPreferences.ShippingOptionId;
                IShippingCalculator calculator = _allShippingCalculators[option];
                calculator.Calculate(cart, shippingPreferences.ShippingPrefID);

                //CodeReview: Instead of Cart pref and compute based on the admin pref
                if (cart.ShippingMethod == UserShippingMethodType.Rush)
                {
                    ShippingOptionType  rushOption     = shippingPreferences.RushShippingOptionID;
                    IShippingCalculator rushCalculator = _allRushShippingCalculators[rushOption];
                    rushCalculator.Calculate(cart, shippingPreferences.RushShippingPrefID);
                }
                else
                {
                    cart.RushShippingCost = 0;
                }

                // code Review 10/09/2013
                bool additionalShippingScenario = false;
                bool additionalShippingScenarioWithSingleSKUinCart     = false;
                bool overRideShippingCostforAdditionalShippingScenario = false;
                bool additionalShippingScenarioWithOtherItems          = false;

                Dictionary <string, string>  dicSKUandPrice = new Dictionary <string, string>();
                Dictionary <string, string>  dicSKUShippingCostWithQtyRange     = new Dictionary <string, string>();
                Dictionary <string, XmlNode> dicSKUShippingCostWithQtyRangeList = new Dictionary <string, XmlNode>();

                SitePreference sitePreference = CSFactory.GetCacheSitePref();
                if (!sitePreference.AttributeValuesLoaded)
                {
                    sitePreference.LoadAttributeValues();
                }

                if (sitePreference.AttributeValues.ContainsKey("additionalshippingscenario"))
                {
                    if (sitePreference.AttributeValues["additionalshippingscenario"].Value != null)
                    {
                        additionalShippingScenario = sitePreference.AttributeValues["additionalshippingscenario"].BooleanValue;
                    }
                }

                if (sitePreference.AttributeValues.ContainsKey("additionalshippingscenariowithsingleskuincart"))
                {
                    if (sitePreference.AttributeValues["additionalshippingscenariowithsingleskuincart"].Value != null)
                    {
                        additionalShippingScenarioWithSingleSKUinCart = sitePreference.AttributeValues["additionalshippingscenariowithsingleskuincart"].BooleanValue;
                    }
                }


                if (sitePreference.AttributeValues.ContainsKey("additionalshippingscenariowithotheritems"))
                {
                    if (sitePreference.AttributeValues["additionalshippingscenariowithotheritems"].Value != null)
                    {
                        additionalShippingScenarioWithOtherItems = sitePreference.AttributeValues["additionalshippingscenariowithotheritems"].BooleanValue;
                    }
                }

                if (sitePreference.AttributeValues.ContainsKey("overrideshippingcostforadditionalshippingscenario"))
                {
                    if (sitePreference.AttributeValues["overrideshippingcostforadditionalshippingscenario"].Value != null)
                    {
                        overRideShippingCostforAdditionalShippingScenario = sitePreference.AttributeValues["overrideshippingcostforadditionalshippingscenario"].BooleanValue;
                    }
                }

                string additionalShippingScenarioSKUandPrice = "";
                if (sitePreference.AttributeValues.ContainsKey("additionalshippingscenarioskuandprice"))
                {
                    if (sitePreference.AttributeValues["additionalshippingscenarioskuandprice"].Value != null)
                    {
                        additionalShippingScenarioSKUandPrice = sitePreference.AttributeValues["additionalshippingscenarioskuandprice"].Value.Trim();
                    }
                }

                if (additionalShippingScenario)
                {
                    try
                    {
                        string dicKey = "";
                        string shippingcostwithqtyrange = "no";
                        if (!additionalShippingScenarioSKUandPrice.Equals(""))
                        {
                            XmlDocument xml = new XmlDocument();
                            xml.LoadXml(additionalShippingScenarioSKUandPrice);
                            XmlNodeList resources = xml.SelectNodes("skulist/sku");
                            foreach (XmlNode node in resources)
                            {
                                dicKey = node.Attributes["skuid"].Value + "_" + node.Attributes["shippingprefid"].Value;
                                if (dicSKUandPrice.ContainsKey(dicKey) == false)
                                {
                                    dicSKUandPrice.Add(dicKey, node.Attributes["shippingcost"].Value); // node.Attributes["skuid"].Value
                                }

                                shippingcostwithqtyrange = "no";

                                if (node.Attributes["shippingcostwithqtyrange"] != null)
                                {
                                    if (node.Attributes["shippingcostwithqtyrange"].Value != null)
                                    {
                                        shippingcostwithqtyrange = node.Attributes["shippingcostwithqtyrange"].Value.ToLower();
                                        XmlNode nodeQtyRangeList = node.SelectSingleNode("qtyrangelist");
                                        if (nodeQtyRangeList != null)
                                        {
                                            if (dicSKUShippingCostWithQtyRangeList.ContainsKey(dicKey) == false)
                                            {
                                                dicSKUShippingCostWithQtyRangeList.Add(dicKey, nodeQtyRangeList);
                                            }
                                        }
                                    }
                                }

                                if (dicSKUShippingCostWithQtyRange.ContainsKey(dicKey) == false)
                                {
                                    dicSKUShippingCostWithQtyRange.Add(dicKey, shippingcostwithqtyrange);
                                }
                            }
                        }
                        else
                        {
                            dicSKUandPrice.Clear();
                            dicSKUShippingCostWithQtyRange.Clear();
                            dicSKUShippingCostWithQtyRangeList.Clear();
                        }

                        dicKey = "";
                        int    lowerQty       = 0;
                        int    upperQty       = 0;
                        string nodeName       = "";
                        string nodeXml        = "";
                        bool   cartHasXMlItem = false;
                        foreach (Sku st in cart.CartItems)
                        {
                            string key = st.SkuId.ToString() + "_" + shippingPreferences.ShippingPrefID;
                            if (dicSKUandPrice.ContainsKey(key))
                            {
                                cartHasXMlItem = true;
                                break;
                            }
                        }

                        if (dicSKUandPrice.Count > 0 && cartHasXMlItem == true)
                        {
                            bool loopSingleSKUinCart = false;
                            if (additionalShippingScenarioWithSingleSKUinCart && cart.ItemCount == 1)
                            {
                                loopSingleSKUinCart = true;
                                decimal shippingCost    = 0;
                                decimal skuShippingCost = 0;
                                bool    isSKUPresent    = false;

                                foreach (Sku st in cart.CartItems)
                                {
                                    // if (st.SkuId == currentSetting.SkuId)
                                    string key = st.SkuId.ToString() + "_" + shippingPreferences.ShippingPrefID;
                                    if (dicSKUandPrice.ContainsKey(key))
                                    {
                                        isSKUPresent    = true;
                                        skuShippingCost = Convert.ToDecimal(dicSKUandPrice[key].ToString());

                                        if (dicSKUShippingCostWithQtyRange[key].ToString().ToLower().Equals("yes") && dicSKUShippingCostWithQtyRangeList.ContainsKey(key) == true && dicSKUShippingCostWithQtyRange.ContainsKey(key) == true)
                                        {
                                            nodeName = (dicSKUShippingCostWithQtyRangeList[key]).Name;
                                            nodeXml  = "<" + nodeName + ">" + dicSKUShippingCostWithQtyRangeList[key].InnerXml.ToString() + "</" + nodeName + ">";
                                            XmlDocument doc = new XmlDocument();
                                            doc.LoadXml(nodeXml);
                                            XmlNodeList nodeList = doc.SelectNodes("/" + nodeName + "/range");
                                            foreach (XmlNode node in nodeList)
                                            {
                                                if (node.Attributes["lowerqty"] != null && node.Attributes["upperqty"] != null)
                                                {
                                                    if (node.Attributes["lowerqty"].Value != null && node.Attributes["upperqty"].Value != null)
                                                    {
                                                        lowerQty = Convert.ToInt32(node.Attributes["lowerqty"].Value);
                                                        upperQty = Convert.ToInt32(node.Attributes["upperqty"].Value);
                                                        if (st.Quantity >= lowerQty && st.Quantity <= upperQty)
                                                        {
                                                            if (node.Attributes["shippingcostrange"] != null)
                                                            {
                                                                if (node.Attributes["shippingcostrange"].Value != null)
                                                                {
                                                                    skuShippingCost = Convert.ToDecimal(node.Attributes["shippingcostrange"].Value);
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        st.LoadAttributeValues();
                                        if (st.AttributeValues.ContainsKey("shippingwithquantity"))
                                        {
                                            if (st.AttributeValues["shippingwithquantity"].Value == null)
                                            {
                                                shippingCost += skuShippingCost;
                                            }
                                            else if (st.AttributeValues["shippingwithquantity"].BooleanValue)
                                            {
                                                shippingCost += skuShippingCost * st.Quantity;
                                            }
                                            else
                                            {
                                                shippingCost += skuShippingCost;
                                            }
                                        }
                                        else
                                        {
                                            shippingCost += skuShippingCost;
                                        }
                                    }
                                }
                                if (isSKUPresent)
                                {
                                    if (overRideShippingCostforAdditionalShippingScenario)
                                    {
                                        cart.ShippingCost = shippingCost;
                                    }
                                    else
                                    {
                                        cart.ShippingCost += shippingCost;
                                    }
                                    cart.RushShippingCost = 0;
                                }
                            }

                            if (loopSingleSKUinCart == false)
                            {
                                if (additionalShippingScenarioWithOtherItems)
                                {
                                    decimal shippingCost    = 0;
                                    decimal skuShippingCost = 0;
                                    bool    isSKUPresent    = false;
                                    foreach (Sku st in cart.CartItems)
                                    {
                                        // if (st.SkuId == currentSetting.SkuId)
                                        string key = st.SkuId.ToString() + "_" + shippingPreferences.ShippingPrefID;
                                        if (dicSKUandPrice.ContainsKey(key))
                                        {
                                            isSKUPresent    = true;
                                            skuShippingCost = Convert.ToDecimal(dicSKUandPrice[key].ToString());

                                            if (dicSKUShippingCostWithQtyRange[key].ToString().ToLower().Equals("yes") && dicSKUShippingCostWithQtyRangeList.ContainsKey(key) == true && dicSKUShippingCostWithQtyRange.ContainsKey(key) == true)
                                            {
                                                nodeName = (dicSKUShippingCostWithQtyRangeList[key]).Name;
                                                nodeXml  = "<" + nodeName + ">" + dicSKUShippingCostWithQtyRangeList[key].InnerXml.ToString() + "</" + nodeName + ">";
                                                XmlDocument doc = new XmlDocument();
                                                doc.LoadXml(nodeXml);
                                                XmlNodeList nodeList = doc.SelectNodes("/" + nodeName + "/range");
                                                foreach (XmlNode node in nodeList)
                                                {
                                                    if (node.Attributes["lowerqty"] != null && node.Attributes["upperqty"] != null)
                                                    {
                                                        if (node.Attributes["lowerqty"].Value != null && node.Attributes["upperqty"].Value != null)
                                                        {
                                                            lowerQty = Convert.ToInt32(node.Attributes["lowerqty"].Value);
                                                            upperQty = Convert.ToInt32(node.Attributes["upperqty"].Value);
                                                            if (st.Quantity >= lowerQty && st.Quantity <= upperQty)
                                                            {
                                                                if (node.Attributes["shippingcostrange"] != null)
                                                                {
                                                                    if (node.Attributes["shippingcostrange"].Value != null)
                                                                    {
                                                                        skuShippingCost = Convert.ToDecimal(node.Attributes["shippingcostrange"].Value);
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            st.LoadAttributeValues();
                                            if (st.AttributeValues.ContainsKey("shippingwithquantity"))
                                            {
                                                if (st.AttributeValues["shippingwithquantity"].BooleanValue)
                                                {
                                                    shippingCost += skuShippingCost * st.Quantity;
                                                }
                                                else
                                                {
                                                    shippingCost += skuShippingCost;
                                                }
                                            }
                                            else
                                            {
                                                shippingCost += skuShippingCost;
                                            }
                                        }
                                    }
                                    if (isSKUPresent)
                                    {
                                        if (overRideShippingCostforAdditionalShippingScenario)
                                        {
                                            cart.ShippingCost = shippingCost;
                                        }
                                        else
                                        {
                                            cart.ShippingCost += shippingCost;
                                        }
                                        cart.RushShippingCost = 0;
                                    }
                                }
                                else
                                {
                                    // Check here if cart has only items which in XML SKU List.
                                    bool cartHasOnlyXMLSku = false;
                                    foreach (Sku st in cart.CartItems)
                                    {
                                        string key = st.SkuId.ToString() + "_" + shippingPreferences.ShippingPrefID;
                                        if (dicSKUandPrice.ContainsKey(key))
                                        {
                                            cartHasOnlyXMLSku = true;
                                        }
                                        else
                                        {
                                            cartHasOnlyXMLSku = false;
                                            break;
                                        }
                                    }

                                    if (cartHasOnlyXMLSku)
                                    {
                                        decimal shippingCost    = 0;
                                        decimal skuShippingCost = 0;
                                        bool    isSKUPresent    = false;
                                        foreach (Sku st in cart.CartItems)
                                        {
                                            // if (st.SkuId == currentSetting.SkuId)
                                            string key = st.SkuId.ToString() + "_" + shippingPreferences.ShippingPrefID;
                                            if (dicSKUandPrice.ContainsKey(key))
                                            {
                                                isSKUPresent    = true;
                                                skuShippingCost = Convert.ToDecimal(dicSKUandPrice[key].ToString());

                                                if (dicSKUShippingCostWithQtyRange[key].ToString().ToLower().Equals("yes") && dicSKUShippingCostWithQtyRangeList.ContainsKey(key) == true && dicSKUShippingCostWithQtyRange.ContainsKey(key) == true)
                                                {
                                                    nodeName = (dicSKUShippingCostWithQtyRangeList[key]).Name;
                                                    nodeXml  = "<" + nodeName + ">" + dicSKUShippingCostWithQtyRangeList[key].InnerXml.ToString() + "</" + nodeName + ">";
                                                    XmlDocument doc = new XmlDocument();
                                                    doc.LoadXml(nodeXml);
                                                    XmlNodeList nodeList = doc.SelectNodes("/" + nodeName + "/range");
                                                    foreach (XmlNode node in nodeList)
                                                    {
                                                        if (node.Attributes["lowerqty"] != null && node.Attributes["upperqty"] != null)
                                                        {
                                                            if (node.Attributes["lowerqty"].Value != null && node.Attributes["upperqty"].Value != null)
                                                            {
                                                                lowerQty = Convert.ToInt32(node.Attributes["lowerqty"].Value);
                                                                upperQty = Convert.ToInt32(node.Attributes["upperqty"].Value);
                                                                if (st.Quantity >= lowerQty && st.Quantity <= upperQty)
                                                                {
                                                                    if (node.Attributes["shippingcostrange"] != null)
                                                                    {
                                                                        if (node.Attributes["shippingcostrange"].Value != null)
                                                                        {
                                                                            skuShippingCost = Convert.ToDecimal(node.Attributes["shippingcostrange"].Value);
                                                                            break;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                                st.LoadAttributeValues();
                                                if (st.AttributeValues.ContainsKey("shippingwithquantity"))
                                                {
                                                    if (st.AttributeValues["shippingwithquantity"].BooleanValue)
                                                    {
                                                        shippingCost += skuShippingCost * st.Quantity;
                                                    }
                                                    else
                                                    {
                                                        shippingCost += skuShippingCost;
                                                    }
                                                }
                                                else
                                                {
                                                    shippingCost += skuShippingCost;
                                                }
                                            }
                                        }
                                        if (isSKUPresent)
                                        {
                                            if (overRideShippingCostforAdditionalShippingScenario)
                                            {
                                                cart.ShippingCost = shippingCost;
                                            }
                                            else
                                            {
                                                cart.ShippingCost += shippingCost;
                                            }
                                            cart.RushShippingCost = 0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        CSCore.CSLogger.Instance.LogException("Additional Shipping Scenario Calculation Issue ", ex);
                        throw;
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Missing shipping preferences");
            }
        }
예제 #10
0
        public decimal CalculateTax(Order order)
        {
            decimal taxToReturn = 0;
            //decimal taxToReturn2 = 0;
            SitePreference list          = CSFactory.GetCartPrefrence();
            decimal        taxableAmount = 0;

            if (list.IncludeShippingCostInTaxCalculation)
            {
                taxableAmount += order.ShippingCost;
            }

            //If this returns a value, it means country has states and we need to
            //find tax for states
            //CodeReview By Sri on 09/15: Need to change TaxRegionCache Object
            TaxRegion countryRegion = null, stateRegion = null, zipRegion = null;

            //Comments on 11/2: pulling data from Cache object
            TaxregionCache   cache      = new TaxregionCache(HttpContext.Current);
            List <TaxRegion> taxRegions = (List <TaxRegion>)cache.Value;

            countryRegion = taxRegions.FirstOrDefault(t => t.CountryId == order.CustomerInfo.ShippingAddress.CountryId && t.StateId == 0 && string.IsNullOrEmpty(t.ZipCode));
            stateRegion   = taxRegions.FirstOrDefault(t => t.CountryId == order.CustomerInfo.ShippingAddress.CountryId && t.StateId == order.CustomerInfo.ShippingAddress.StateProvinceId && string.IsNullOrEmpty(t.ZipCode));
            zipRegion     = taxRegions.FirstOrDefault(t => t.CountryId == order.CustomerInfo.ShippingAddress.CountryId && t.StateId == order.CustomerInfo.ShippingAddress.StateProvinceId &&
                                                      t.ZipCode == order.CustomerInfo.ShippingAddress.ZipPostalCode);

            if (zipRegion != null)
            {
                taxToReturn = Math.Round(taxableAmount * zipRegion.Value / 100, 2, MidpointRounding.AwayFromZero);;
            }
            else if (stateRegion != null)
            {
                taxToReturn = Math.Round(taxableAmount * stateRegion.Value / 100, 2, MidpointRounding.AwayFromZero);;
            }
            else if (countryRegion != null)
            {
                taxToReturn = Math.Round(taxableAmount * countryRegion.Value / 100, MidpointRounding.AwayFromZero);;
            }
            taxToReturn = Math.Round(taxToReturn, 2, MidpointRounding.AwayFromZero);
            int i = 0;

            foreach (Sku item in order.SkuItems)
            {
                i++;

                decimal itemPrice = item.FullPrice;
                if (i == 1)
                {
                    if (order.DiscountAmount > 0)
                    {
                        itemPrice -= order.DiscountAmount;
                    }
                }
                if (order.CustomerInfo.ShippingAddress.CountryId > 0)
                {
                    if (zipRegion != null)
                    {
                        taxToReturn += Math.Round((itemPrice * item.Quantity) * zipRegion.Value / 100, 2, MidpointRounding.AwayFromZero);
                    }
                    else if (stateRegion != null)
                    {
                        taxToReturn += Math.Round((itemPrice * item.Quantity) * stateRegion.Value / 100, 2, MidpointRounding.AwayFromZero);
                    }
                    else if (countryRegion != null)
                    {
                        taxToReturn += Math.Round((itemPrice * item.Quantity) * countryRegion.Value / 100, 2, MidpointRounding.AwayFromZero);
                    }
                }
            }

            //if (order.DiscountAmount > 0)
            //{
            //    if (zipRegion != null)
            //    {
            //        taxToReturn += Math.Round(-order.DiscountAmount * zipRegion.Value / 100, 2, MidpointRounding.AwayFromZero); ;
            //    }
            //    else if (stateRegion != null)
            //    {
            //        taxToReturn += Math.Round(-order.DiscountAmount * stateRegion.Value / 100, 2, MidpointRounding.AwayFromZero); ;
            //    }
            //    else if (countryRegion != null)
            //    {
            //        taxToReturn += Math.Round(-order.DiscountAmount * countryRegion.Value / 100, MidpointRounding.AwayFromZero); ;
            //    }
            //}


            return(Math.Round(taxToReturn, 2, MidpointRounding.AwayFromZero));
        }