private void UpdateCartGrid() { _cartTotal = 0; _itemsCount = 0; List <ItemInfo> cartItems = CurrentCart.GetItems(PortalId, StoreSettings.SecureCookie); if (cartItems.Count == 0) { grdItems.Visible = false; lblCartEmpty.Visible = true; } else { grdItems.Visible = true; if (_showThumbnail) { grdItems.Columns[0].Visible = true; } else { grdItems.Columns[0].Visible = false; } grdItems.DataSource = cartItems; grdItems.DataBind(); lblCartEmpty.Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { if (StoreSettings != null) { try { string templatePath = CssTools.GetTemplatePath(this, StoreSettings.PortalTemplates); CssTools.AddCss(Page, templatePath, StoreSettings.StyleSheet); // Read module settings and define cart properties Core.Cart.MiniCartSettings cartSettings = new ModuleSettings(ModuleId, TabId).MiniCart; cartControl.ShowThumbnail = cartSettings.ShowThumbnail; cartControl.ThumbnailWidth = cartSettings.ThumbnailWidth; cartControl.GIFBgColor = cartSettings.GIFBgColor; cartControl.EnableImageCaching = cartSettings.EnableImageCaching; cartControl.CacheImageDuration = cartSettings.CacheImageDuration; cartControl.ProductColumn = cartSettings.ProductColumn.ToLower(); cartControl.LinkToDetail = cartSettings.LinkToDetail; cartControl.IncludeVAT = cartSettings.IncludeVAT; cartControl.TemplatePath = templatePath; cartControl.ModuleConfiguration = ModuleConfiguration; cartControl.StoreSettings = StoreSettings; cartControl.EditComplete += cartControl_EditComplete; _itemsCount = CurrentCart.GetItems(PortalId, StoreSettings.SecureCookie).Count; if (_itemsCount == 0) { phlViewCart.Visible = false; } } catch (Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } } else { if (UserInfo.IsSuperUser) { string ErrorSettings = Localization.GetString("ErrorSettings", LocalResourceFile); string ErrorSettingsHeading = Localization.GetString("ErrorSettingsHeading", LocalResourceFile); UI.Skins.Skin.AddModuleMessage(this, ErrorSettingsHeading, ErrorSettings, UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning); } divControls.Visible = false; } }
public HttpResponseMessage GetCart() { try { int portalID = PortalController.Instance.GetCurrentPortalSettings().PortalId; StoreInfo storeSettings = StoreController.GetStoreInfo(portalID); CartInfo cart = CurrentCart.GetInfo(portalID, storeSettings.SecureCookie); CartDTO cartDTO = new CartDTO { CartID = cart.CartID, Total = cart.Items > 0 ? cart.Total : 0 }; List <ItemInfo> cartItems = CurrentCart.GetItems(portalID, storeSettings.SecureCookie); List <ItemDTO> itemsDTO = new List <ItemDTO>(cartItems.Count); foreach (ItemInfo item in cartItems) { ItemDTO itemDTO = new ItemDTO { ItemID = item.ItemID, ProductID = item.ProductID, Manufacturer = item.Manufacturer, ModelNumber = item.ModelNumber, ModelName = item.ModelName, ProductImage = item.ProductImage, UnitCost = item.UnitCost, Quantity = item.Quantity, Discount = item.Discount }; itemsDTO.Add(itemDTO); } cartDTO.Items = itemsDTO; return(Request.CreateResponse(HttpStatusCode.OK, cartDTO)); } catch { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, LocalizeString("Unexpected.Error"))); } }
/// <summary> /// Calculate the tax and shipping cost for the order. /// </summary> private void CalculateTaxAndShipping(CouponInfo coupon) { if (Order != null) { List <ItemInfo> cartItems = CurrentCart.GetItems(PortalId, StoreSettings.SecureCookie); IShippingInfo shippingInfo; // Calculate Shipping if enabled IShippingProvider shippingProvider = StoreController.GetShippingProvider(StoreSettings.ShippingName); if (StoreSettings.NoDelivery || Shipping == ShippingMode.None || ApplyFreeShipping(cartItems, ShippingAddress.CountryCode)) { shippingInfo = shippingProvider.GetFreeShipping(); } else { shippingInfo = shippingProvider.CalculateShippingFee(PortalId, BillingAddress, ShippingAddress, cartItems); } if (shippingInfo == null) { plhCheckout.Visible = false; lblError.Text = String.Format(Localization.GetString("ErrorShippingRates", LocalResourceFile), StoreSettings.DefaultEmailAddress); plhError.Visible = true; return; } plhCheckout.Visible = true; plhError.Visible = false; // Check for coupon validity bool couponIsValid = false; if (StoreSettings.AllowCoupons) { int couponID = Order.CouponID; if (couponID != Null.NullInteger) { if (coupon == null || coupon.CouponID != couponID) { CouponController couponController = new CouponController(); coupon = couponController.GetCoupon(PortalId, couponID); } couponIsValid = ValidateCoupon(coupon, Order); } divStoreCheckoutCoupon.Visible = true; } else { divStoreCheckoutCoupon.Visible = false; } // Apply Discount if coupon is valid if (couponIsValid) { decimal discountTotal = 0; switch (coupon.DiscountType) { case CouponDiscount.Percentage: decimal discountPercentage = Convert.ToDecimal(coupon.DiscountPercentage) / 100; foreach (ItemInfo cartItem in cartItems) { switch (coupon.ApplyTo) { case CouponApplyTo.Order: cartItem.Discount = cartItem.SubTotal * discountPercentage; discountTotal += cartItem.Discount; break; case CouponApplyTo.Category: if (ValidateCategoryCoupon(coupon, cartItem.CategoryID)) { cartItem.Discount = cartItem.SubTotal * discountPercentage; discountTotal += cartItem.Discount; } break; case CouponApplyTo.Product: if (cartItem.ProductID == coupon.ItemID) { cartItem.Discount = cartItem.SubTotal * discountPercentage; discountTotal += cartItem.Discount; } break; } } break; case CouponDiscount.FixedAmount: int itemsCount = cartItems.Count; foreach (ItemInfo cartItem in cartItems) { switch (coupon.ApplyTo) { case CouponApplyTo.Order: cartItem.Discount = coupon.DiscountAmount / itemsCount; discountTotal = coupon.DiscountAmount; break; case CouponApplyTo.Category: if (ValidateCategoryCoupon(coupon, cartItem.CategoryID)) { cartItem.Discount = coupon.DiscountAmount * cartItem.Quantity; discountTotal += cartItem.Discount; } break; case CouponApplyTo.Product: if (cartItem.ProductID == coupon.ItemID) { cartItem.Discount = coupon.DiscountAmount * cartItem.Quantity; discountTotal += cartItem.Discount; } break; } } break; case CouponDiscount.FreeShipping: discountTotal = shippingInfo.Cost; // If Free Shipping exclude amount before tax computation! shippingInfo.Cost = 0; break; } Order.Discount = -discountTotal; lblDiscount.Text = Order.Discount.ToString("C", _localFormat); tbDiscount.Visible = Order.Discount > 0; } else { // Reset order discount Order.CouponID = Null.NullInteger; Order.Discount = Null.NullDecimal; foreach (ItemInfo cartItem in cartItems) { cartItem.Discount = 0; } tbDiscount.Visible = false; } // Add Surcharges if any decimal fixedSurcharge = PaymentControl.SurchargeFixed; decimal percentSurcharge = PaymentControl.SurchargePercent; if (fixedSurcharge != 0 || percentSurcharge != 0) { Order.ShippingCost = shippingInfo.Cost + fixedSurcharge + ((Order.OrderNetTotal + shippingInfo.Cost + fixedSurcharge) * (percentSurcharge / 100)); shippingInfo.Cost = Order.ShippingCost; } else { Order.ShippingCost = shippingInfo.Cost; } plhShippingCheckout.Visible = Order.ShippingCost > 0; // Calculate Tax Amount ITaxProvider taxProvider = StoreController.GetTaxProvider(StoreSettings.TaxName); ITaxInfo taxInfo = taxProvider.CalculateSalesTax(PortalId, cartItems, shippingInfo, BillingAddress); if (taxInfo.ShowTax && taxInfo.SalesTax > 0) { plhTaxCheckout.Visible = true; Order.TaxTotal = taxInfo.SalesTax; Order.ShippingTax = taxInfo.ShippingTax; } else { plhTaxCheckout.Visible = false; Order.TaxTotal = 0; Order.ShippingTax = 0; } } }