/// <summary> /// Loads order item data to the form fields. /// </summary> private void LoadData() { SKUInfo sku = SKU; // Check if ShoppingCartItem or SKU exist if ((ShoppingCartItem == null) || (sku == null)) { RedirectToInformation("general.ObjectNotFound"); return; } OrderInfo order = ShoppingCart.Order; // Label control must be set even when request is postback if (sku.SKUProductType == SKUProductTypeEnum.EProduct) { // Check whether the order is paid if ((order != null) && order.OrderIsPaid) { // Check whether the e-product is unlimited if (ShoppingCartItem.CartItemValidTo.CompareTo(DateTimeHelper.ZERO_TIME) == 0) { // Display as unlimited EditForm.FieldControls["CartItemValidToLabel"].Value = GetString("general.unlimited"); } else { // Display validity EditForm.FieldControls["CartItemValidToLabel"].Value = TimeZoneHelper.ConvertToUserTimeZone(ShoppingCartItem.CartItemValidTo, true, MembershipContext.AuthenticatedUser, SiteContext.CurrentSite); } } else { // Display conditions when the validity is displayed EditForm.FieldControls["CartItemValidToLabel"].Value = GetString("com.orderitemedit.validtonotset"); } } if (!RequestHelper.IsPostBack()) { // Order must not be paid, order item editing must be allowed bool editingEnabled = ((order == null) || !order.OrderIsPaid) && ECommerceSettings.EnableOrderItemEditing; // Disable UIForm if editing is disabled EditForm.Enabled = editingEnabled; // Product options and bundle items unit count depends on their parents EditForm.FieldControls["SKUUnits"].Enabled = !(ShoppingCartItem.IsProductOption || ShoppingCartItem.IsBundleItem); EditForm.FieldControls["CartItemName"].Value = SKU.SKUName; EditForm.FieldControls["CartItemUnitPrice"].Value = CurrencyInfoProvider.GetFormattedValue(ShoppingCartItem.UnitPrice, ShoppingCart.Currency); string itemText = ShoppingCartItem.CartItemText; // Text product options have text field displayed if (SKU.IsProductOption && !String.IsNullOrEmpty(itemText)) { var controlName = (SKU.SKUOptionCategory.CategorySelectionType == OptionCategorySelectionTypeEnum.TextBox) ? "CartItemTextBox" : "CartItemTextArea"; EditForm.FieldControls[controlName].Value = itemText; } } }
/// <summary> /// Page load. /// </summary> protected void Page_Load(object sender, EventArgs e) { if (!StopProcessing) { if (AuthenticationHelper.IsAuthenticated()) { // Get site id of credits main currency int creditSiteId = ECommerceHelper.GetSiteID(SiteContext.CurrentSiteID, ECommerceSettings.USE_GLOBAL_CREDIT); gridCreditEvents.HideControlForZeroRows = true; gridCreditEvents.IsLiveSite = IsLiveSite; gridCreditEvents.OnExternalDataBound += gridCreditEvents_OnExternalDataBound; gridCreditEvents.OrderBy = "EventDate DESC, EventName ASC"; gridCreditEvents.WhereCondition = "EventCustomerID = " + CustomerId + " AND ISNULL(EventSiteID, 0) = " + creditSiteId; // Get total credit value decimal credit = (decimal)CreditEventInfoProvider.GetTotalCredit(CustomerId, SiteContext.CurrentSiteID); if (Currency != null) { // Convert credit to current currency when using one CurrencyConverter.TryGetExchangeRate(creditSiteId == 0, Currency.CurrencyCode, SiteContext.CurrentSiteID, ref rate); credit = CurrencyConverter.ApplyExchangeRate(credit, rate); } lblCreditValue.Text = CurrencyInfoProvider.GetFormattedPrice((double)credit, Currency); } else { // Hide if user is not authenticated Visible = false; } } }
/// <summary> /// Handles the UniGrid's OnExternalDataBound event. /// </summary> /// <param name="sender">Sender</param> /// <param name="sourceName">Source name</param> /// <param name="parameter">Parameter</param> protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { int shippingCostId = -1; switch (sourceName.ToLowerCSafe()) { case "shippingcostvalue": double value = ValidationHelper.GetDouble(parameter, 0); return(CurrencyInfoProvider.GetFormattedPrice(value, currency)); case "edit": case "delete": if (sender is ImageButton) { // Hide editing/deleting of zero-row (cost from general tab) shippingCostId = ValidationHelper.GetInteger(((DataRowView)((GridViewRow)parameter).DataItem)[0], 0); if (shippingCostId == 0) { ImageButton button = sender as ImageButton; button.Visible = false; } } break; } return(parameter); }
protected void ReloadData() { // Recalculate shopping cart ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart); gridData.DataSource = ShoppingCart.ContentTable; gridData.DataBind(); gridTaxSummary.DataSource = ShoppingCart.ContentTaxesTable; gridTaxSummary.DataBind(); gridShippingTaxSummary.DataSource = ShoppingCart.ShippingTaxesTable; gridShippingTaxSummary.DataBind(); // Show order related discounts plcMultiBuyDiscountArea.Visible = ShoppingCart.OrderRelatedDiscountSummaryItems.Count > 0; ShoppingCart.OrderRelatedDiscountSummaryItems.ForEach(d => { plcOrderRelatedDiscountNames.Controls.Add(new LocalizedLabel { Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(d.Name)) + ":", EnableViewState = false }); plcOrderRelatedDiscountNames.Controls.Add(new Literal { Text = "<br />", EnableViewState = false }); plcOrderRelatedDiscountValues.Controls.Add(new Label { Text = "- " + CurrencyInfoProvider.GetFormattedPrice(d.Value, ShoppingCart.Currency), EnableViewState = false }); plcOrderRelatedDiscountValues.Controls.Add(new Literal { Text = "<br />", EnableViewState = false }); }); // shipping option, payment method initialization InitPaymentShipping(); }
/// <summary> /// Create Shopping cart with item by customer /// </summary> /// <param name="customerAddressID"></param> /// <param name="txtQty"></param> private void CreateShoppingCartByCustomer(SKUInfo product, int customerAddressID, int productQty, double skuPrice) { try { var customerAddress = AddressInfoProvider.GetAddressInfo(customerAddressID); if (!DataHelper.DataSourceIsEmpty(product)) { ShoppingCartInfo cart = new ShoppingCartInfo(); cart.ShoppingCartSiteID = CurrentSite.SiteID; cart.ShoppingCartCustomerID = customerAddressID; cart.ShoppingCartCurrencyID = CurrencyInfoProvider.GetMainCurrency(CurrentSite.SiteID).CurrencyID; cart.SetValue("ShoppingCartCampaignID", ProductCampaignID); cart.SetValue("ShoppingCartProgramID", ProductProgramID); cart.SetValue("ShoppingCartDistributorID", customerAddressID); cart.SetValue("ShoppingCartInventoryType", ProductType); cart.User = CurrentUser; cart.ShoppingCartShippingAddress = customerAddress; cart.ShoppingCartShippingOptionID = ProductShippingID; ShoppingCartInfoProvider.SetShoppingCartInfo(cart); ShoppingCartItemParameters parameters = new ShoppingCartItemParameters(product.SKUID, productQty); parameters.CustomParameters.Add("CartItemCustomerID", customerAddressID); ShoppingCartItemInfo cartItem = cart.SetShoppingCartItem(parameters); cartItem.SetValue("CartItemPrice", skuPrice); cartItem.SetValue("CartItemDistributorID", customerAddressID); cartItem.SetValue("CartItemCampaignID", ProductCampaignID); cartItem.SetValue("CartItemProgramID", ProductProgramID); ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem); cart.InvalidateCalculations(); } } catch (Exception ex) { EventLogProvider.LogException("CustomerCartOperations.ascx.cs", "CreateShoppingCartByCustomer()", ex); } }
/// <summary> /// Changes the selected prices and other object fields. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { int newCurrencyId = currencyElem.SelectedID; // Get the new main currency var newCurrency = CurrencyInfoProvider.GetCurrencyInfo(newCurrencyId); if (newCurrency != null) { // Only select new main currency when no old main currency specified if (mainCurrency == null) { newCurrency.CurrencyIsMain = true; newCurrency.Update(); // Refresh the page URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "saved", "1")); return; } // Change main currency CurrencyInfoProvider.ChangeMainCurrency(editedSiteId, newCurrencyId); // Refresh the page URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "saved", "1")); } else { ShowError(GetString("StoreSettings_ChangeCurrency.NoNewMainCurrency")); } }
protected void Page_Load(object sender, EventArgs e) { product = SKUInfo.Provider.Get(ProductID); // Setup help object options = new { helpName = "lnkProductEditHelp", helpUrl = DocumentationHelper.GetDocumentationTopicUrl(HELP_TOPIC_LINK) }; ScriptHelper.RegisterModule(this, "CMS/DialogContextHelpChange", options); EditedObject = product; if (product != null) { // Check site id CheckEditedObjectSiteID(product.SKUSiteID); // Load product currency productCurrency = CurrencyInfoProvider.GetMainCurrency(product.SKUSiteID); // Display product price headProductPriceInfo.Text = string.Format(GetString("com_sku_volume_discount.skupricelabel"), CurrencyInfoProvider.GetFormattedPrice(product.SKUPrice, productCurrency)); } // Set unigrid properties SetUnigridProperties(); // Initialize the master page elements InitializeMasterPage(); }
/// <summary> /// Calculate total price with product options prices. /// </summary> private void CalculateTotalPrice() { // Add SKU price double price = SKUInfoProvider.GetSKUPrice(SKU, ShoppingCart, true, ShowPriceIncludingTax); // Add prices of all product options List <ShoppingCartItemParameters> optionParams = ProductOptionsParameters; foreach (ShoppingCartItemParameters optionParam in optionParams) { SKUInfo sku = null; if (mProductOptions.Contains(optionParam.SKUID)) { // Get option SKU data sku = (SKUInfo)mProductOptions[optionParam.SKUID]; // Add option price price += SKUInfoProvider.GetSKUPrice(sku, ShoppingCart, true, ShowPriceIncludingTax); } } // Convert to shopping cart currency price = ShoppingCart.ApplyExchangeRate(price); lblPriceValue.Text = CurrencyInfoProvider.GetFormattedPrice(price, ShoppingCart.Currency); }
protected void Page_Load(object sender, EventArgs e) { // Register JQuery ScriptHelper.RegisterJQuery(this); // Check permissions (only global admin can see this dialog) var user = MembershipContext.AuthenticatedUser; if (!user.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin)) { RedirectToAccessDenied(GetString("StoreSettings_ChangeCurrency.AccessDenied")); } int siteId = QueryHelper.GetInteger("siteId", SiteContext.CurrentSiteID); if (user.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin)) { editedSiteId = siteId <= 0 ? 0 : siteId; } else { editedSiteId = SiteContext.CurrentSiteID; } mainCurrency = CurrencyInfoProvider.GetMainCurrency(editedSiteId); if (mainCurrency != null) { lblOldMainCurrency.Text = HTMLHelper.HTMLEncode(mainCurrency.CurrencyDisplayName); } else { plcOldCurrency.Visible = false; } // Load the UI CurrentMaster.Page.Title = GetString("StoreSettings_ChangeCurrency.ChangeCurrencyTitle"); btnOk.Text = GetString("General.saveandclose"); currencyElem.AddSelectRecord = true; currencyElem.SiteID = editedSiteId; if (!RequestHelper.IsPostBack()) { if (QueryHelper.GetBoolean("saved", false)) { // Refresh the page ltlScript.Text = ScriptHelper.GetScript(@" var loc = wopener.location; if(!(/currencysaved=1/.test(loc))) { if(!(/\?/.test(loc))) { loc += '?currencysaved=1'; } else { loc += '¤cysaved=1'; } } wopener.location.replace(loc); CloseDialog();"); ShowChangesSaved(); } } }
/// <summary> /// Indicates if exchange rate from global main currency is needed. /// </summary> protected bool IsFromGlobalRateNeeded() { var siteId = ConfiguredSiteID; if ((siteId == 0) || (ECommerceSettings.UseGlobalCurrencies(siteId))) { return false; } string globalMainCode = CurrencyInfoProvider.GetMainCurrencyCode(0); string siteMainCode = CurrencyInfoProvider.GetMainCurrencyCode(siteId); // Check whether main currencies are defined if (string.IsNullOrEmpty(siteMainCode) || string.IsNullOrEmpty(globalMainCode)) { return false; } // Check whether global and site main currency are the same if (string.Equals(globalMainCode, siteMainCode, StringComparison.InvariantCultureIgnoreCase)) { return false; } // Check if site has currency with same code as global main -> no need for global rate if (CurrencyInfoProvider.GetCurrenciesByCode(siteId).ContainsKey(globalMainCode)) { return false; } return ECommerceSettings.AllowGlobalProductOptions(siteId) || ECommerceSettings.AllowGlobalProducts(siteId) || ECommerceSettings.UseGlobalCredit(siteId) || ECommerceSettings.UseGlobalTaxClasses(siteId); }
/// <summary> /// Handles the UniGrid's OnExternalDataBound event. /// </summary> /// <param name="sender">Sender</param> /// <param name="sourceName">Source name</param> /// <param name="parameter">Parameter</param> protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLowerCSafe()) { case "discountvalue": DataRowView row = (DataRowView)parameter; double value = ValidationHelper.GetDouble(row["VolumeDiscountValue"], 0); bool isFlat = ValidationHelper.GetBoolean(row["VolumeDiscountIsFlatValue"], false); // If value is relative, add "%" next to the value. if (isFlat) { return(CurrencyInfoProvider.GetFormattedPrice(value, productCurrency)); } else { return(value.ToString() + "%"); } case "edit": // Open modal dialog with volume discount edit form int volumeDiscountId = ValidationHelper.GetInteger(((DataRowView)((GridViewRow)parameter).DataItem)[0], 0); ((WebControl)sender).Attributes["onclick"] = "modalDialog('" + URLHelper.GetAbsoluteUrl("~/CMSModules/Ecommerce/Pages/Content/Product/Product_Edit_VolumeDiscount_Edit.aspx") + "?ProductID=" + sku.SKUID + "&VolumeDiscountID=" + volumeDiscountId + "&modaldialog=1', 'VolumeDiscounts', 500, 350); return false;"; break; } return(parameter); }
/// <summary> /// Displays available credit. /// </summary> public override void DisplayAvailableCredit() { CMSCreditPaymentProvider cmsCreditProvider = (CMSCreditPaymentProvider)ShoppingCartControl.PaymentGatewayProvider; if (cmsCreditProvider != null) { lblCredit.Text = ResHelper.GetString("CreditPayment.lblCredit"); if ((cmsCreditProvider.MainCurrencyObj != null) && (cmsCreditProvider.OrderCurrencyObj != null)) { // Order currency is different from main currency if (cmsCreditProvider.MainCurrencyObj.CurrencyID != cmsCreditProvider.OrderCurrencyObj.CurrencyID) { // Set available credit string lblCreditValue.Text = CurrencyInfoProvider.GetFormattedPrice(cmsCreditProvider.AvailableCreditInOrderCurrency, cmsCreditProvider.OrderCurrencyObj); lblCreditValue.Text += " (" + CurrencyInfoProvider.GetFormattedPrice(cmsCreditProvider.AvailableCreditInMainCurrency, cmsCreditProvider.MainCurrencyObj) + ")"; } // Order currency is equal to main currency else { lblCreditValue.Text = CurrencyInfoProvider.GetFormattedPrice(cmsCreditProvider.AvailableCreditInMainCurrency, cmsCreditProvider.MainCurrencyObj); } } } }
protected object productsUniGridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { DataRowView row; switch (sourceName.ToLowerCSafe()) { case "skuprice": row = (DataRowView)parameter; // Get information needed to format SKU price double value = ValidationHelper.GetDouble(row["SKUPrice"], 0); int siteId = ValidationHelper.GetInteger(row["SKUSiteID"], 0); // Return formatted SKU price return(CurrencyInfoProvider.GetFormattedPrice(value, siteId)); case "skuvalidity": row = (DataRowView)parameter; // Get information needed to format SKU validity ValidityEnum validity = DateTimeHelper.GetValidityEnum(ValidationHelper.GetString(row["SKUValidity"], null)); int validFor = ValidationHelper.GetInteger(row["SKUValidFor"], 0); DateTime validUntil = ValidationHelper.GetDateTime(row["SKUValidUntil"], DateTimeHelper.ZERO_TIME); // Return formatted SKU validity return(DateTimeHelper.GetFormattedValidity(validity, validFor, validUntil)); } return(null); }
protected void EditForm_OnItemValidation(object sender, ref string errorMessage) { FormEngineUserControl ctrl = sender as FormEngineUserControl; if ((ctrl != null)) { // Check whether the main currency is being disabled if (ctrl.FieldInfo.Name == "CurrencyEnabled") { CurrencyInfo main = CurrencyInfoProvider.GetMainCurrency(ConfiguredSiteID); if ((main != null) && (mEditedCurrency != null) && (main.CurrencyID == mEditedCurrency.CurrencyID) && !ValidationHelper.GetBoolean(ctrl.Value, true)) { errorMessage = String.Format(GetString("ecommerce.disablemaincurrencyerror"), main.CurrencyDisplayName); } } // Validate currency format string if (ctrl.FieldInfo.Name == "CurrencyFormatString") { try { // Test for double exception string.Format(ctrl.Value.ToString().Trim(), 1.234); string.Format(ctrl.Value.ToString().Trim(), "12.12"); } catch { errorMessage = GetString("Currency_Edit.ErrorCurrencyFormatString"); } } } }
/// <summary> /// Indicates if exchange rate from global main currency is needed. /// </summary> protected bool IsFromGlobalRateNeeded() { string siteName = SiteInfoProvider.GetSiteName(this.ConfiguredSiteID); if ((this.ConfiguredSiteID == 0) || (ECommerceSettings.UseGlobalCurrencies(siteName))) { return(false); } string globalMainCode = CurrencyInfoProvider.GetMainCurrencyCode(0); string siteMainCode = CurrencyInfoProvider.GetMainCurrencyCode(this.ConfiguredSiteID); // Check whether main currencies are defined if (string.IsNullOrEmpty(siteMainCode) || string.IsNullOrEmpty(globalMainCode)) { return(false); } // Check whether global and site main currency are the same if (globalMainCode.ToLower() == siteMainCode.ToLower()) { return(false); } return(ECommerceSettings.AllowGlobalDiscountCoupons(siteName) || ECommerceSettings.AllowGlobalProductOptions(siteName) || ECommerceSettings.AllowGlobalProducts(siteName) || ECommerceSettings.AllowGlobalShippingOptions(siteName) || ECommerceSettings.UseGlobalCredit(siteName) || ECommerceSettings.UseGlobalTaxClasses(siteName)); }
protected void Page_Load(object sender, EventArgs e) { mShippingOptionId = QueryHelper.GetInteger("shippingoptionid", 0); mShippingOptionInfoObj = ShippingOptionInfoProvider.GetShippingOptionInfo(mShippingOptionId); EditedObject = mShippingOptionInfoObj; if (mShippingOptionInfoObj != null) { CheckEditedObjectSiteID(mShippingOptionInfoObj.ShippingOptionSiteID); currency = CurrencyInfoProvider.GetMainCurrency(mShippingOptionInfoObj.ShippingOptionSiteID); } // Init unigrid gridElem.OnAction += new OnActionEventHandler(gridElem_OnAction); gridElem.OnExternalDataBound += new OnExternalDataBoundEventHandler(gridElem_OnExternalDataBound); gridElem.OnAfterRetrieveData += new OnAfterRetrieveData(gridElem_OnAfterRetrieveData); gridElem.WhereCondition = "ShippingCostShippingOptionID = " + mShippingOptionId; gridElem.ZeroRowsText = GetString("com.ui.shippingcost.edit_nodata"); gridElem.GridView.AllowSorting = false; // Prepare the new shipping cost header action CurrentMaster.HeaderActions.AddAction(new HeaderAction() { Text = GetString("com.ui.shippingcost.edit_new"), RedirectUrl = ResolveUrl("ShippingOption_Edit_ShippingCosts_Edit.aspx?shippingCostShippingOptionId=" + mShippingOptionId + "&siteId=" + SiteID), ImageUrl = GetImageUrl("Objects/Ecommerce_ShippingOption/add.png"), ControlType = HeaderActionTypeEnum.Hyperlink }); }
object grid_OnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLower()) { case "skuenabled": return(UniGridFunctions.ColoredSpanYesNo(parameter)); case "skuprice": DataRowView row = (DataRowView)parameter; double value = ValidationHelper.GetDouble(row["SKUPrice"], 0); int siteId = ValidationHelper.GetInteger(row["SKUSiteID"], 0); // Format price return(CurrencyInfoProvider.GetFormattedPrice(value, siteId)); case "delete": case "moveup": case "movedown": { ImageButton button = sender as ImageButton; if (button != null) { // Hide actions when not allowed button.Visible = allowActions; } } break; } return(parameter); }
private void LoadData() { // Payment summary lblTotalPriceValue.Text = CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.RoundedTotalPrice, ShoppingCart.Currency); lblOrderIdValue.Text = Convert.ToString(ShoppingCart.OrderId); if (ShoppingCart.PaymentOption != null) { lblPaymentValue.Text = ResHelper.LocalizeString(ShoppingCart.PaymentOption.PaymentOptionDisplayName); } // Add payment gateway custom data ShoppingCartControl.PaymentGatewayProvider.AddCustomData(); // Show "Order saved" info message if (!ShoppingCartControl.IsCurrentStepPostBack) { //if (this.ShoppingCartControl.IsInternalOrder) //{ // lblInfo.Text = GetString("General.ChangesSaved"); //} //else //{ // lblInfo.Text = GetString("ShoppingCart.PaymentGateway.OrderSaved"); //} lblInfo.Text = GetString("ShoppingCart.PaymentGateway.OrderSaved"); lblInfo.Visible = true; } else { lblInfo.Text = ""; } }
/// <summary> /// Generates where condition for uniselector. /// </summary> protected override string GenerateWhereCondition() { CurrencyInfo main = CurrencyInfoProvider.GetMainCurrency(SiteID); int mainCurrencyId = (main != null) ? main.CurrencyID : 0; // Prepare where condition string where = ""; if (DisplayOnlyWithExchangeRate) { ExchangeTableInfo tableInfo = ExchangeTableInfoProvider.GetLastExchangeTableInfo(SiteID); if (tableInfo != null) { where = "(CurrencyID = " + mainCurrencyId + " OR CurrencyID IN (SELECT ExchangeRateToCurrencyID FROM COM_CurrencyExchangeRate WHERE COM_CurrencyExchangeRate.ExchangeTableID = " + tableInfo.ExchangeTableID + ") AND CurrencyEnabled = 1)"; } else { where = "(0=1)"; } } // Add site main currency when required if (AddSiteDefaultCurrency && (main != null)) { where = SqlHelper.AddWhereCondition(where, "CurrencyID = " + mainCurrencyId, "OR"); } // Exclude site main currency when required if (ExcludeSiteDefaultCurrency && (main != null)) { where = SqlHelper.AddWhereCondition(where, "(NOT CurrencyID = " + mainCurrencyId + ")"); } // Add base where condition return(SqlHelper.AddWhereCondition(where, base.GenerateWhereCondition())); }
/// <summary> /// Gets current main currency. /// </summary> private void GetCurrentMainCurrency() { int mainCurrencyId = -1; CurrencyInfo mainCurrency = CurrencyInfoProvider.GetMainCurrency(ConfiguredSiteID); if (mainCurrency != null) { mainCurrencyId = mainCurrency.CurrencyID; lblMainCurrency.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(mainCurrency.CurrencyDisplayName)); } else { lblMainCurrency.Text = GetString("general.na"); } DataSet ds = CurrencyInfo.Provider.Get() .TopN(1) .WhereTrue("CurrencyEnabled") .Where("CurrencyID", QueryOperator.NotEquals, mainCurrencyId) .OnSite(ConfiguredSiteID); // When there is no choice if (DataHelper.DataSourceIsEmpty(ds)) { // Disable "change main currency" button btnChangeCurrency.Enabled = false; } }
/// <summary> /// Gets current main currency. /// </summary> private void GetCurrentMainCurrency() { int mainCurrencyId = -1; CurrencyInfo mainCurrency = CurrencyInfoProvider.GetMainCurrency(this.ConfiguredSiteID); if (mainCurrency != null) { mainCurrencyId = mainCurrency.CurrencyID; lblMainCurrency.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(mainCurrency.CurrencyDisplayName)); } else { lblMainCurrency.Text = GetString("general.na"); } DataSet ds = CurrencyInfoProvider.GetCurrencies("CurrencyEnabled = 1 AND ISNULL(CurrencySiteID, 0) = " + this.ConfiguredSiteID + " AND NOT CurrencyID = " + mainCurrencyId, null); // When there is no choice if (DataHelper.DataSourceIsEmpty(ds)) { // Disable "change main currency" button this.btnChangeCurrency.Enabled = false; } }
/// <summary> /// Recalculates and formats price. /// </summary> /// <param name="row">Data row to create price label for.</param> private string GetPrice(DataRow row) { var sku = new SKUInfo(row); // Get site main currency var currency = CurrencyInfoProvider.GetMainCurrency(sku.SKUSiteID); // Get product price var price = sku.SKUPrice; if (price != 0) { var roundingServiceFactory = Service.Resolve <IRoundingServiceFactory>(); var roundingService = roundingServiceFactory.GetRoundingService(SiteContext.CurrentSiteID); // Round price price = roundingService.Round(price, currency); // Prevent double encoding in DDL bool encode = SelectionType != OptionCategorySelectionTypeEnum.Dropdownlist; // Format price string formattedPrice = CurrencyInfoProvider.GetRelativelyFormattedPrice(price, currency, encode); return(" (" + formattedPrice + ")"); } return(string.Empty); }
/// <summary> /// Adds price to individual shipping options when shopping cart object supplied. /// </summary> /// <param name="item">Shipping option item to add price to.</param> protected override void OnListItemCreated(ListItem item) { // Adding price to shipping option is not required if (!DisplayShippingOptionPrice) { return; } if ((item != null) && (ShoppingCart != null)) { // Calculate hypothetical shipping cost for shipping option from supplied list item var optionID = ValidationHelper.GetInteger(item.Value, 0); var option = ShippingOptionInfoProvider.GetShippingOptionInfo(optionID); var shippingPrice = CalculateShipping(option); var formattedPrice = CurrencyInfoProvider.GetFormattedPrice(shippingPrice, ShoppingCart.Currency, false); if (shippingPrice > 0) { var detailInfo = $"({formattedPrice})"; var rtl = IsLiveSite ? CultureHelper.IsPreferredCultureRTL() : CultureHelper.IsUICultureRTL(); if (rtl) { item.Text = $"{detailInfo} {item.Text}"; } else { item.Text += $" {detailInfo}"; } } } }
/// <summary> /// Preselects currency. /// </summary> protected void SelectCurrency() { // Try to set the currency to the currency preferred by the user if (ShoppingCart.ShoppingCartCurrencyID == 0) { // Set customer preferred options CustomerInfo currentCustomer = ECommerceContext.CurrentCustomer; if ((currentCustomer != null) && (currentCustomer.CustomerUser != null)) { ShoppingCart.ShoppingCartCurrencyID = currentCustomer.CustomerUser.GetUserPreferredCurrencyID(ShoppingCart.SiteName); // Invalidate the shopping cart ShoppingCart.InvalidateExchangeRate(); ShoppingCart.InvalidateCalculations(); } } // Set the currency to the site currency, if preferred currency isn't set by the user if (ShoppingCart.ShoppingCartCurrencyID == 0) { CurrencyInfo mainCurrency = CurrencyInfoProvider.GetMainCurrency(ShoppingCart.ShoppingCartSiteID); if ((ShoppingCart.SiteName != null) && (mainCurrency != null)) { ShoppingCart.ShoppingCartCurrencyID = mainCurrency.CurrencyID; // Invalidate the shopping cart ShoppingCart.InvalidateExchangeRate(); ShoppingCart.InvalidateCalculations(); } } }
/// <summary> /// Recalculates and formats price. /// </summary> /// <param name="row">Data row to create price label for.</param> private string GetPrice(DataRow row) { var sku = new SKUInfo(row); // Get site main currency var currency = CurrencyInfoProvider.GetMainCurrency(sku.SKUSiteID); // Get product price var price = sku.SKUPrice; if (price != 0) { string prefix = (price >= 0) ? "+ " : "- "; price = Math.Abs(price); // Round price price = CurrencyInfoProvider.RoundTo(price, currency); // Format price string formattedPrice = CurrencyInfoProvider.GetFormattedPrice(price, currency); return(" (" + prefix + formattedPrice + ")"); } return(string.Empty); }
protected void InitPaymentShipping() { if (currentSite != null) { // Get shipping option name ShippingOptionInfo shippingObj = ShoppingCart.ShippingOption; if (shippingObj != null) { mAddressCount++; tdShippingAddress.Visible = true; plcShipping.Visible = true; plcShippingOption.Visible = true; lblShippingOptionValue.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(shippingObj.ShippingOptionDisplayName)); lblShippingValue.Text = CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.TotalShipping, ShoppingCart.Currency); } else { tdShippingAddress.Visible = false; plcShippingOption.Visible = false; plcShipping.Visible = false; } } // Get payment method name PaymentOptionInfo paymentObj = PaymentOptionInfo.Provider.Get(ShoppingCart.ShoppingCartPaymentOptionID); if (paymentObj != null) { lblPaymentMethodValue.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(paymentObj.PaymentOptionDisplayName)); } // Total price initialization lblTotalPriceValue.Text = CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.GrandTotal, ShoppingCart.Currency); lblTotalTaxValue.Text = CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.TotalTax, ShoppingCart.Currency); }
/// <summary> /// Returns formatted total credit string. /// </summary> private string GetFormattedTotalCredit() { // Get total credit double totalCredit = CreditEventInfoProvider.GetTotalCredit(customerId, SiteContext.CurrentSiteID); // Return formatted total credit according to the credits main currency format string return(CurrencyInfoProvider.GetFormattedPrice(totalCredit, currency)); }
private object ugOptions_OnExternalDataBound(object sender, string sourceName, object parameter) { DataRowView option = (DataRowView)parameter; switch (sourceName) { // Create formatted SKU price case "SKUPrice": var value = ValidationHelper.GetDecimal(option["SKUPrice"], 0); if (value.Equals(0)) { return(null); } // Format price int siteId = ValidationHelper.GetInteger(option["SKUSiteID"], 0); return(CurrencyInfoProvider.GetRelativelyFormattedPrice(value, siteId)); case UniGrid.SELECTION_EXTERNAL_DATABOUND: string optionId = ValidationHelper.GetString(option["SKUID"], ""); var chkBox = (CMSCheckBox)sender; if (OptionIdsUsedInVariant.Contains(optionId)) { // Inform user that option is used in variants a make sure it is checked chkBox.Enabled = false; chkBox.Style["cursor"] = "help"; chkBox.ToolTip = GetString("com.optioncategory.usedinvariant"); } else if (DisabledOptionsIds.Contains(optionId)) { // Inform user that option is not allowed and cannot by checked chkBox.Enabled = false; chkBox.Style["cursor"] = "help"; chkBox.ToolTip = GetString("com.optioncategory.assignonlyenabled"); } break; case UniGrid.SELECTALL_EXTERNAL_DATABOUND: if (OptionIdsUsedInVariant.Any() || DisabledOptionsIds.Any()) { // Hide 'select all' checkbox to prevent removing of options used in variants or adding of disabled options var chkBoxHeader = (CMSCheckBox)sender; chkBoxHeader.Visible = false; } break; } return(parameter); }
/// <summary> /// Saves order information from ShoppingCartInfo object to database as new order. /// </summary> public override bool ProcessStep() { // Load first step if there is no address if (ShoppingCart.ShoppingCartBillingAddress == null) { ShoppingCartControl.LoadStep(0); return(false); } // Deal with order note ShoppingCartControl.SetTempValue(ORDER_NOTE, null); ShoppingCart.ShoppingCartNote = TextHelper.LimitLength(txtNote.Text.Trim(), txtNote.MaxLength); try { // Set order culture ShoppingCart.ShoppingCartCulture = LocalizationContext.PreferredCultureCode; // Create order ShoppingCartInfoProvider.SetOrder(ShoppingCart); } catch (Exception ex) { // Show error lblError.Text = GetString("Ecommerce.OrderPreview.ErrorOrderSave"); // Log exception Service.Resolve <IEventLogService>().LogException("Shopping cart", "SAVEORDER", ex, ShoppingCart.ShoppingCartSiteID); return(false); } // Track order activity string siteName = SiteContext.CurrentSiteName; if (LogActivityForCustomer) { var mainCurrency = CurrencyInfoProvider.GetMainCurrency(ShoppingCart.ShoppingCartSiteID); var grandTotalInMainCurrency = Service.Resolve <ICurrencyConverterService>().Convert(ShoppingCart.GrandTotal, ShoppingCart.Currency.CurrencyCode, mainCurrency.CurrencyCode, ShoppingCart.ShoppingCartSiteID); var formattedPrice = CurrencyInfoProvider.GetFormattedPrice(grandTotalInMainCurrency, mainCurrency); ShoppingCartControl.TrackActivityPurchasedProducts(ShoppingCart, siteName, ContactID); ShoppingCartControl.TrackActivityPurchase(ShoppingCart.OrderId, ContactID, SiteContext.CurrentSiteName, RequestContext.CurrentRelativePath, grandTotalInMainCurrency, formattedPrice); } // Raise finish order event ShoppingCartControl.RaiseOrderCompletedEvent(); if (chkSendEmail.Checked) { // Send order notification emails OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart); OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart); } return(true); }
// Displays total price protected void DisplayTotalPrice() { pnlPrice.Visible = true; lblTotalPriceValue.Text = CurrencyInfoProvider.GetFormattedPrice(ShoppingCartInfoObj.RoundedTotalPrice, ShoppingCartInfoObj.CurrencyInfoObj); lblTotalPrice.Text = GetString("ecommerce.cartcontent.totalpricelabel"); lblShippingPrice.Text = GetString("ecommerce.cartcontent.shippingpricelabel"); lblShippingPriceValue.Text = CurrencyInfoProvider.GetFormattedPrice(ShoppingCartInfoObj.TotalShipping, ShoppingCartInfoObj.CurrencyInfoObj); }