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 }
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)); }
public bool CalculateDiscount(Cart cart) { cart.DiscountAmount = 0; if (cart.DiscountCode != null) { SitePreference prefObject = CSFactory.GetCacheSitePref(); List <CouponInfo> couponList = prefObject.CouponItems; CouponInfo foundItem = couponList.FirstOrDefault(x => x.Title.ToLower() == cart.DiscountCode.ToLower()); if (foundItem != null) { if ((int)foundItem.DiscountType == 1) { if (foundItem.IncludeShipping) { cart.DiscountAmount = Math.Round(cart.Total * (foundItem.Discount / 100), 2); } else { cart.DiscountAmount = Math.Round(cart.SubTotal * (foundItem.Discount / 100), 2); } } else if ((int)foundItem.DiscountType == 2) { if (cart.Total >= foundItem.TotalAmount) { cart.DiscountAmount = foundItem.Discount; } else { cart.DiscountAmount = 0; } } else if ((int)foundItem.DiscountType == 5) { // Discount shipping cost of only main skus if (CSWebBase.SiteBasePage.IsFreeShipOrderMainSku(cart)) { decimal discountAmount = SiteBasePage.GetMainSkuShippingCost(cart); cart.DiscountAmount = discountAmount; } else { cart.DiscountAmount = cart.ShippingCost; if (foundItem.Discount > 0) { if (foundItem.IncludeShipping) { cart.DiscountAmount += Math.Round(cart.Total * (foundItem.Discount / 100), 2); } else { cart.DiscountAmount += Math.Round(cart.SubTotal * (foundItem.Discount / 100), 2); } } else if (foundItem.TotalAmount > 0) { cart.DiscountAmount += foundItem.TotalAmount; } } } else //item level coupon { List <CouponItems> items = foundItem.ItemsDiscount; foreach (CouponItems itemInfo in items) { if (itemInfo != null) { if (cart.CartItems.FirstOrDefault(x => x.SkuId == itemInfo.SkuId) != null) { Sku RelatedItem = cart.CartItems.FirstOrDefault(x => x.SkuId == itemInfo.RelatedSkuId); if (RelatedItem != null) { if ((int)itemInfo.DiscountType == 1) { cart.DiscountAmount = Math.Round(RelatedItem.InitialPrice * (itemInfo.DiscountAmount / 100), 2); } else { if (cart.Total >= itemInfo.DiscountAmount) { cart.DiscountAmount = itemInfo.DiscountAmount; } else { cart.DiscountAmount = 0; } } } } } } } } if (cart.DiscountAmount > 0) { return(true); } } return(false); }