protected void Page_Load(object sender, EventArgs e) { if (StoreSettings != null) { try { if (!string.IsNullOrEmpty(StoreSettings.CurrencySymbol)) { _localFormat.CurrencySymbol = StoreSettings.CurrencySymbol; } _imageUpdate = _templatePath + "images/" + Localization.GetString("ImageUpdate", LocalResourceFile); _imageDelete = _templatePath + "images/" + Localization.GetString("ImageDelete", LocalResourceFile); ITaxProvider taxProvider = StoreController.GetTaxProvider(StoreSettings.TaxName); ITaxInfo taxInfo = taxProvider.GetDefautTaxRates(PortalId); _defaultTaxRate = taxInfo.DefaultTaxRate; _showTax = taxInfo.ShowTax; if (_linkToDetail) { _linkTitle = Localization.GetString("lnkTitle", LocalResourceFile); if (StoreSettings.SEOFeature) { _productControler = new ProductController(); } } if (IsPostBack == false) { UpdateCartGrid(); } } catch (Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } } }
protected void Page_Load(object sender, EventArgs e) { _catalogNav = new CatalogNavigation(Request.QueryString); _imagesPath = _templatePath + "Images/"; if (!string.IsNullOrEmpty(StoreSettings.CurrencySymbol)) { _localFormat.CurrencySymbol = StoreSettings.CurrencySymbol; } ITaxProvider taxProvider = StoreController.GetTaxProvider(StoreSettings.TaxName); ITaxInfo taxInfo = taxProvider.GetDefautTaxRates(PortalId); _defaultTaxRate = taxInfo.DefaultTaxRate; _showTax = taxInfo.ShowTax; _product = (DataSource as ProductInfo); if (_product != null) { _category = _categoryControler.GetCategory(PortalId, _product.CategoryID); if (StoreSettings.SEOFeature) { _catalogNav.Category = _category.SEOName; if (InList == false) { BasePage.Title = SEO(Localization.GetString("DetailsSEOTitle", LocalResourceFile), MetaTags.Title); BasePage.Description = SEO(Localization.GetString("DetailsSEODescription", LocalResourceFile), MetaTags.Description); BasePage.KeyWords = SEO(Localization.GetString("DetailsSEOKeywords", LocalResourceFile), MetaTags.Keywords); CatalogNavigation canonical = new CatalogNavigation { CategoryID = _product.CategoryID, ProductID = _product.ProductID }; string domain = Request.Url.GetLeftPart(UriPartial.Authority); string url = canonical.GetNavigationUrl(); if (url.StartsWith(domain, true, CultureInfo.CurrentCulture) == false) { url = domain + url; } HeaderHelper.AddCanonicalLink(Page, url); } } plhDetails.Controls.Add(TemplateController.ParseTemplate(MapPath(_templatePath), _template, Localization.GetString("TemplateError", LocalSharedResourceFile), IsLogged, new ProcessTokenDelegate(ProcessToken))); } // Clear error message divError.Visible = false; // Show review panel ? if (ShowReviews && !InList) { int reviewID = _catalogNav.ReviewID; // Show review list or edit? if (reviewID != Null.NullInteger) { if (reviewID > 0 && !CanManageReviews()) { _catalogNav.ReviewID = Null.NullInteger; Response.Redirect(_catalogNav.GetNavigationUrl()); } else { LoadReviewEditControl(); } } else { LoadReviewListControl(); } pnlReviews.Visible = true; } else { pnlReviews.Visible = false; } // Show Return link? if (InList == false) { if (_catalogNav.SearchID == Null.NullInteger) { if (_catalogNav.CategoryID == Null.NullInteger) { lnkReturn.Text = Localization.GetString("lnkReturnToCatalog", LocalResourceFile); } else { lnkReturn.Text = Localization.GetString("lnkReturn", LocalResourceFile); } } else { lnkReturn.Text = Localization.GetString("lnkReturnToSearch", LocalResourceFile); } lnkReturn.NavigateUrl = GetReturnUrl(ReturnPage); pnlReturn.Visible = true; } else { pnlReturn.Visible = false; } }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); int portalId = PortalSettings.PortalId; StoreInfo storeInfo = StoreController.GetStoreInfo(portalId); if (storeInfo != null) { NumberFormatInfo localFormat = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone(); string text; phControls.Visible = true; lblStoreMicroCartItemsTitle.CssClass = _itemsTitleCssClass; lblStoreMicroCartTotalTitle.CssClass = _totalTitleCssClass; lblStoreMicroCartItems.CssClass = _itemsCssClass; lblStoreMicroCartTotal.CssClass = _totalCssClass; string resource = TemplateSourceDirectory + "/App_LocalResources/MicroCart.ascx.resx"; lblStoreMicroCartItemsTitle.Text = Localization.GetString("CartItemsTitle.Text", resource); lblStoreMicroCartTotalTitle.Text = Localization.GetString("CartTotalTitle.Text", resource); try { CartInfo cartInfo = CurrentCart.GetInfo(portalId, storeInfo.SecureCookie); if (!string.IsNullOrEmpty(storeInfo.CurrencySymbol)) { localFormat.CurrencySymbol = storeInfo.CurrencySymbol; } ITaxProvider taxProvider = StoreController.GetTaxProvider(storeInfo.TaxName); ITaxInfo taxInfo = taxProvider.GetDefautTaxRates(portalId); bool showTax = taxInfo.ShowTax; decimal defaultTaxRate = taxInfo.DefaultTaxRate; text = Localization.GetString("CartItems.Text", resource); if (cartInfo != null && cartInfo.Items > 0) { lblStoreMicroCartItems.Text = string.Format(text, cartInfo.Items); decimal cartTotal = cartInfo.Total; if (showTax && _includeVAT && cartInfo.Total > 0) { cartTotal = (cartTotal + (cartTotal * (defaultTaxRate / 100))); } lblStoreMicroCartTotal.Text = cartTotal.ToString("C", localFormat); } else { lblStoreMicroCartItems.Text = string.Format(text, 0); lblStoreMicroCartTotal.Text = (0D).ToString("C", localFormat); } } catch { text = Localization.GetString("Error.Text", resource); lblStoreMicroCartItems.Text = text; lblStoreMicroCartTotalTitle.Text = text; } } else { phControls.Visible = false; } }
/// <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; } } }