using System; using System.Web.UI; using System.Web.UI.WebControls; using CMS.CMSHelper; using CMS.Ecommerce; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.SettingsProvider; public partial class CMSWebParts_Ecommerce_ShoppingCart_ShoppingCartMiniPreviewWebPart : CMSAbstractWebPart { protected string rtlFix = ""; #region "Web part properties" /// /// Shopping cart icon image URL. /// public string IconImageUrl { get { return DataHelper.GetNotEmpty(GetValue("IconImageUrl"), GetImageUrl("CMSModules/CMS_Ecommerce/cart.png")); } set { SetValue("IconImageUrl", value); imgCartIcon.ImageUrl = value; } } /// /// Indicates if shopping cart icon should be displayed. /// public bool ShowIconImage { get { return ValidationHelper.GetBoolean(GetValue("ShowIconImage"), ShowTotalPrice); } set { SetValue("ShowIconImage", value); imgCartIcon.Visible = value; } } /// /// Shopping cart link URL. /// public string ShoppingCartLinkUrl { get { return DataHelper.GetNotEmpty(GetValue("ShoppingCartLinkUrl"), ECommerceSettings.ShoppingCartURL(SiteName)); } set { SetValue("ShoppingCartLinkUrl", value); lnkShoppingCart.NavigateUrl = value; } } /// /// Shopping cart link text. /// public string ShoppingCartLinkText { get { return DataHelper.GetNotEmpty(GetValue("ShoppingCartLinkText"), GetString("ShopingCartMiniPreview.ShoppingCartLinkText")); } set { SetValue("ShoppingCartLinkText", value); lnkShoppingCart.Text = value; } } /// /// Indicates if link to the shopping cart content page should be displayed. /// public bool ShowShoppingCartLink { get { return ValidationHelper.GetBoolean(GetValue("ShowShoppingCartLink"), true); } set { SetValue("ShowShoppingCartLink", value); plcShoppingCart.Visible = value; } } /// /// My account link URL. /// public string MyAccountLinkUrl { get { return DataHelper.GetNotEmpty(GetValue("MyAccountLinkUrl"), SettingsKeyProvider.GetStringValue(SiteName + ".CMSMyAccountURL")); } set { SetValue("MyAccountLinkUrl", value); lnkMyAccount.NavigateUrl = value; } } /// /// My account link text. /// public string MyAccountLinkText { get { return DataHelper.GetNotEmpty(GetValue("MyAccountLinkText"), GetString("ShopingCartMiniPreview.MyAccountLinkText")); } set { SetValue("MyAccountLinkText", value); lnkMyAccount.Text = value; } } /// /// Indicates if link to user's account page should be displayed. /// public bool ShowMyAccountLink { get { return ValidationHelper.GetBoolean(GetValue("ShowMyAccountLink"), true); } set { SetValue("ShowMyAccountLink", value); plcMyAccount.Visible = value; } } /// /// My wish list link URL. /// public string MyWishlistLinkUrl { get { return DataHelper.GetNotEmpty(GetValue("WishlistLinkUrl"), ECommerceSettings.WishListURL(SiteName)); } set { SetValue("WishlistLinkUrl", value); lnkMyWishlist.NavigateUrl = value; } } /// /// My wish list link text. /// public string MyWishlistLinkText { get { return DataHelper.GetNotEmpty(GetValue("WishlistLinkText"), GetString("ShopingCartMiniPreview.MyWishlistLinkText")); } set { SetValue("WishlistLinkText", value); lnkMyWishlist.Text = value; } } /// /// Indicates if link to the user's wish list page should be displayed. /// public bool ShowMyWishlistLink { get { return ValidationHelper.GetBoolean(GetValue("ShowWishlistLink"), true); } set { SetValue("ShowWishlistLink", value); plcMyWishlist.Visible = value; } } /// /// Link separator /// public string Separator { get { return DataHelper.GetNotEmpty(GetValue("Separator"), "| "); } set { SetValue("Separator", value); } } /// /// Total price title text. /// public string TotalPriceTitleText { get { return DataHelper.GetNotEmpty(GetValue("TotalPriceTitleText"), GetString("ShopingCartMiniPreview.TotalPriceTitleText")); } set { SetValue("TotalPriceTitleText", value); lblTotalPriceTitle.Text = value; } } /// /// Indicates if shopping cart total price title should be displayed. /// public bool ShowTotalPriceTitle { get { return ValidationHelper.GetBoolean(GetValue("ShowTotalPriceTitle"), ShowTotalPrice); } set { SetValue("ShowTotalPriceTitle", value); lblTotalPriceTitle.Visible = value; } } /// /// Indicates if shopping cart total price value should be displayed. /// public bool ShowTotalPrice { get { return ValidationHelper.GetBoolean(GetValue("ShowTotalPrice"), true); } set { SetValue("ShowTotalPrice", value); lblTotalPriceValue.Visible = value; } } /// /// Text which is displayed when shopping cart is empty. /// public string EmptyShoppingCartText { get { return DataHelper.GetNotEmpty(GetValue("EmptyShoppingCartText"), GetString("ShoppingCart.Empty")); } set { SetValue("EmptyShoppingCartText", value); } } /// /// Indicates if text given by EmptyShoppingCartText property is displayed when shopping is empty. /// public bool ShowEmptyShoppingCartText { get { return ValidationHelper.GetBoolean(GetValue("ShowEmptyShoppingCartText"), true); } set { SetValue("ShowEmptyShoppingCartText", value); } } #endregion #region "Other properties" /// /// Gets the site name. /// protected string SiteName { get { return ECommerceContext.CurrentShoppingCart.SiteName; } } /// /// Gets formatted shopping cart total price value. /// public string TotalPriceValue { get { ShoppingCartInfo sc = ECommerceContext.CurrentShoppingCart; if ((sc != null) && (sc.CartItems.Count > 0)) { return sc.GetFormattedPrice(sc.RoundedTotalPrice); } else { return ""; } } } #endregion /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); } /// /// Initializes links /// protected void SetLinks() { // Shopping cart icon if (ShowIconImage) { imgCartIcon.Visible = true; imgCartIcon.ImageUrl = ResolveUrl(IconImageUrl); imgCartIcon.AlternateText = GetString("ShoppingcartPreview.Icon"); // Check if RTL fix must be applied if (CultureHelper.IsPreferredCultureRTL()) { rtlFix = "."; } } else { imgCartIcon.Visible = false; } // Link to user's shopping cart if (ShowShoppingCartLink && (ShoppingCartLinkUrl != "")) { lnkShoppingCart.NavigateUrl = URLHelper.ResolveUrl(URLHelper.AddPrefixToUrl(ShoppingCartLinkUrl)); lnkShoppingCart.Text = ShoppingCartLinkText; } else { plcShoppingCart.Visible = false; } // Link to user's wish list if (ShowMyWishlistLink && (MyWishlistLinkUrl != "")) { lnkMyWishlist.NavigateUrl = URLHelper.ResolveUrl(URLHelper.AddPrefixToUrl(MyWishlistLinkUrl)); lnkMyWishlist.Text = MyWishlistLinkText; } else { plcMyWishlist.Visible = false; } // Link to user's account if (ShowMyAccountLink && (MyAccountLinkUrl != "")) { lnkMyAccount.NavigateUrl = URLHelper.ResolveUrl(URLHelper.AddPrefixToUrl(MyAccountLinkUrl)); lnkMyAccount.Text = MyAccountLinkText; } else { plcMyAccount.Visible = false; } } /// OnPreRender override /// protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (!StopProcessing) { SetLinks(); SetShoppingCartPreviewText(); } } private void SetShoppingCartPreviewText() { // Hide total price info by default plcTotalPrice.Visible = false; lblTotalPriceTitle.Visible = false; lblTotalPriceValue.Visible = false; // Is cart empty? ShoppingCartInfo sc = ECommerceContext.CurrentShoppingCart; bool cartEmpty = (sc != null) && (sc.CartItems.Count <= 0); if (!cartEmpty || (cartEmpty && !ShowEmptyShoppingCartText)) { // Display title if (ShowTotalPriceTitle) { plcTotalPrice.Visible = true; lblTotalPriceTitle.Visible = true; lblTotalPriceTitle.Text = TotalPriceTitleText; } // Display total price if (ShowTotalPrice) { plcTotalPrice.Visible = true; lblTotalPriceValue.Visible = true; lblTotalPriceValue.Text = TotalPriceValue; } } else if (ShowEmptyShoppingCartText) { // Display 'cart empty' text plcTotalPrice.Visible = true; lblTotalPriceTitle.Visible = true; lblTotalPriceTitle.Text = EmptyShoppingCartText; } } }