protected bool CreateVolumeDiscount() { // Prepare the parameters string where = "SKUName LIKE '12 �prouvettes'"; SKUInfo product = null; // Get the product DataSet products = SKUInfoProvider.GetSKUs(where, null); if (!DataHelper.DataSourceIsEmpty(products)) { product = new SKUInfo(products.Tables[0].Rows[0]); } if (product != null) { // Create new volume discount object VolumeDiscountInfo newDiscount = new VolumeDiscountInfo(); // Set the properties newDiscount.VolumeDiscountMinCount = 1; newDiscount.VolumeDiscountValue = 10; newDiscount.VolumeDiscountSKUID = product.SKUID; newDiscount.VolumeDiscountIsFlatValue = false; // Create the volume discount VolumeDiscountInfoProvider.SetVolumeDiscountInfo(newDiscount); return(true); } return(false); }
/// <summary> /// Load data of editing volumeDiscount. /// </summary> /// <param name="volumeDiscountObj">VolumeDiscount object</param> protected void LoadData(VolumeDiscountInfo volumeDiscountObj) { // Load data from database txtVolumeDiscountValue.Text = Convert.ToString(volumeDiscountObj.VolumeDiscountValue); txtVolumeDiscountMinCount.Text = Convert.ToString(volumeDiscountObj.VolumeDiscountMinCount); radDiscountAbsolute.Checked = (volumeDiscountObj.VolumeDiscountIsFlatValue); radDiscountRelative.Checked = !(volumeDiscountObj.VolumeDiscountIsFlatValue); }
protected void EditForm_OnItemValidation(object sender, ref string errorMessage) { // Look for record with the same minimal amount FormEngineUserControl ctrl = sender as FormEngineUserControl; if ((ctrl != null) && (ctrl.FieldInfo.Name == "VolumeDiscountMinCount")) { int mincount = ValidationHelper.GetInteger(ctrl.Value, 0); VolumeDiscountInfo discount = VolumeDiscountInfoProvider.GetVolumeDiscountInfo(Product.SKUID, mincount); if ((discount != null) && (mincount == discount.VolumeDiscountMinCount) && (EditedDiscount.VolumeDiscountID != discount.VolumeDiscountID)) { errorMessage = GetString("product_edit_volumediscount_edit.minamountexists"); EditForm.StopProcessing = false; } } }
/// <summary> /// Gets and updates volume discount. Called when the "Get and update discount" button is pressed. /// Expects the CreateVolumeDiscount method to be run first. /// </summary> private bool GetAndUpdateVolumeDiscount() { // Prepare the parameters string where = "SKUName LIKE N'MyNew%'"; SKUInfo product = null; // Get the product DataSet products = SKUInfoProvider.GetSKUs(where, null); if (!DataHelper.DataSourceIsEmpty(products)) { product = new SKUInfo(products.Tables[0].Rows[0]); } if (product != null) { // Get the volume discount DataSet discounts = VolumeDiscountInfoProvider.GetVolumeDiscounts(product.SKUID); if (!DataHelper.DataSourceIsEmpty(discounts)) { // Create object from DataRow VolumeDiscountInfo discount = new VolumeDiscountInfo(discounts.Tables[0].Rows[0]); // Update the value discount.VolumeDiscountMinCount = 800; // Update the volume discount VolumeDiscountInfoProvider.SetVolumeDiscountInfo(discount); return true; } } return false; }
/// <summary> /// Creates volume discount. Called when the "Create discount" button is pressed. /// Expects the CreateProduct method to be run first. /// </summary> private bool CreateVolumeDiscount() { // Prepare the parameters string where = "SKUName LIKE N'MyNew%'"; SKUInfo product = null; // Get the product DataSet products = SKUInfoProvider.GetSKUs(where, null); if (!DataHelper.DataSourceIsEmpty(products)) { product = new SKUInfo(products.Tables[0].Rows[0]); } if (product != null) { // Create new volume discount object VolumeDiscountInfo newDiscount = new VolumeDiscountInfo(); // Set the properties newDiscount.VolumeDiscountMinCount = 100; newDiscount.VolumeDiscountValue = 20; newDiscount.VolumeDiscountSKUID = product.SKUID; newDiscount.VolumeDiscountIsFlatValue = false; // Create the volume discount VolumeDiscountInfoProvider.SetVolumeDiscountInfo(newDiscount); return true; } return false; }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (sku == null) { return; } if (CheckProductPermissions(sku)) { // True if there is already same min count; bool isMinCountUnique = false; // Server side validation of user input string errorMessage = new Validator().NotEmpty(txtVolumeDiscountValue.Text, "product_edit_volumediscount_edit.volumediscountvaluelabel") .NotEmpty(txtVolumeDiscountMinCount.Text, "product_edit_volumediscount_edit.volumediscountmincountlabel").Result; // Discount value validation if (errorMessage == "") { // Relative if (this.radDiscountRelative.Checked && !ValidationHelper.IsInRange(0, 100, ValidationHelper.GetDouble(this.txtVolumeDiscountValue.Text.Trim(), -1))) { errorMessage = GetString("Com.Error.RelativeDiscountValue"); } // Absolute else if (this.radDiscountAbsolute.Checked && !ValidationHelper.IsPositiveNumber(ValidationHelper.GetDouble(this.txtVolumeDiscountValue.Text.Trim(), -1))) { errorMessage = GetString("Com.Error.AbsoluteDiscountValue"); } } if (errorMessage == "") { VolumeDiscountInfo volumeDiscountObj = VolumeDiscountInfoProvider.GetVolumeDiscountInfo(volumeDiscountID); // If volumeDiscount doesnt already exist, create new one if (volumeDiscountObj == null) { // Create new volume discount volumeDiscountObj = new VolumeDiscountInfo(); // When creating new one, set his SKUID to productID (obtained from URL) volumeDiscountObj.VolumeDiscountSKUID = productID; } // Set volumeDiscountObj values volumeDiscountObj.VolumeDiscountValue = Convert.ToDouble(txtVolumeDiscountValue.Text.Trim()); volumeDiscountObj.VolumeDiscountMinCount = Convert.ToInt32(txtVolumeDiscountMinCount.Text.Trim()); volumeDiscountObj.VolumeDiscountIsFlatValue = radDiscountAbsolute.Checked; // Set isMinCountUnique VolumeDiscountInfo vdi = VolumeDiscountInfoProvider.GetVolumeDiscountInfo(productID, volumeDiscountObj.VolumeDiscountMinCount); if (vdi == null) { isMinCountUnique = true; } else { isMinCountUnique = (vdi.VolumeDiscountMinCount != volumeDiscountObj.VolumeDiscountMinCount); } // Check if min count is unique or it is update of existing item if ((isMinCountUnique) || (vdi.VolumeDiscountID == volumeDiscountObj.VolumeDiscountID)) { string dialogString = ""; if (dialog) { dialogString = "&dialog=1"; } // Sets data to database VolumeDiscountInfoProvider.SetVolumeDiscountInfo(volumeDiscountObj); string redirectUrl = "Product_Edit_VolumeDiscount_Edit.aspx?VolumeDiscountID=" + Convert.ToString(volumeDiscountObj.VolumeDiscountID) + "&siteId=" + SiteID + "&saved=1&productID=" + productID + dialogString; URLHelper.Redirect(redirectUrl); } else { lblError.Text = GetString("product_edit_volumediscount_edit.minamountexists"); lblError.Visible = true; } } else { lblError.Visible = true; lblError.Text = errorMessage; } } }
protected void Page_Load(object sender, EventArgs e) { ScriptHelper.RegisterJQuery(this); if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Ecommerce", "Products.VolumeDiscounts")) { RedirectToCMSDeskUIElementAccessDenied("CMS.Ecommerce", "Products.VolumeDiscounts"); } volumeDiscountID = QueryHelper.GetInteger("VolumeDiscountID", 0); productID = QueryHelper.GetInteger("ProductID", 0); sku = SKUInfoProvider.GetSKUInfo(productID); if (sku != null) { CheckEditedObjectSiteID(sku.SKUSiteID); currencyCode = HTMLHelper.HTMLEncode(CurrencyInfoProvider.GetMainCurrencyCode(sku.SKUSiteID)); // Check presence of main currency string currencyErr = CheckMainCurrency(sku.SKUSiteID); if (!string.IsNullOrEmpty(currencyErr)) { // Show message lblError.Text = currencyErr; lblError.Visible = true; } } string titleText = ""; string titleImage = ""; // Init labels lblVolumeDiscountValue.Text = GetString("product_edit_volumediscount_edit.volumediscountvaluelabel"); lblVolumeDiscountMinCount.Text = GetString("product_edit_volumediscount_edit.volumediscountmincountlabel"); radDiscountAbsolute.Text = GetString("product_edit_volumediscount_edit.rbdiscountabsolute"); radDiscountRelative.Text = GetString("product_edit_volumediscount_edit.rbdiscountrelative"); // Init value validator error messages rfvDiscountValue.ErrorMessage = GetString("product_edit_volumediscount_edit.rfvDiscountValue"); rvDiscountValue.ErrorMessage = GetString("product_edit_volumediscount_edit.rvDiscountValue"); rvDiscountValue.MaximumValue = int.MaxValue.ToString(); // Init min count validator error messages rfvMinCount.ErrorMessage = GetString("product_edit_volumediscount_edit.rfvMinCount"); rvMinCount.ErrorMessage = GetString("product_edit_volumediscount_edit.rvMinCount"); rvMinCount.MaximumValue = int.MaxValue.ToString(); radDiscountAbsolute.Attributes["onclick"] = "jQuery('span[id*=\"lblCurrency\"]').html(" + ScriptHelper.GetString("(" + currencyCode + ")") + ")"; radDiscountRelative.Attributes["onclick"] = "jQuery('span[id*=\"lblCurrency\"]').html('(%)')"; btnOk.Text = GetString("General.OK"); string currentVolumeDiscount = GetString("Product_Edit_VolumeDiscount_Edit.NewItemCaption"); // If true, then we will edit existing record if (volumeDiscountID > 0) { // Check if there is already VolumeDiscountInfo with this volumeDiscountID volumeDiscountObj = VolumeDiscountInfoProvider.GetVolumeDiscountInfo(volumeDiscountID); if (volumeDiscountID > 0) { EditedObject = volumeDiscountObj; } if (volumeDiscountObj != null) { // Fill editing form with existing data when not postback if (!RequestHelper.IsPostBack()) { LoadData(volumeDiscountObj); // Set caption of edited item currentVolumeDiscount = GetString("product_edit_volumediscount_edit.edittitletext"); // Show that the volumeDiscount was created or updated successfully if (QueryHelper.GetString("saved", "") == "1") { lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); // Refresh parent page when editing in modal dialog if (dialog) { ltlScript.Text = ScriptHelper.GetScript("wopener.RefreshPage();"); } } } } // Set page title to "volume discount properties" titleText = GetString("product_edit_volumediscount_edit.edittitletext"); titleImage = GetImageUrl("Objects/Ecommerce_VolumeDiscount/new.png"); } // Do this when creating new discount else { // Set default radio button value if (!URLHelper.IsPostback()) { radDiscountRelative.Checked = true; radDiscountAbsolute.Checked = false; } // Init page header to "new item" titleText = GetString("product_edit_volumediscount_edit.newitemcaption"); titleImage = GetImageUrl("Objects/Ecommerce_VolumeDiscount/add.png"); } // Show breadcrumbs only when not editing in modal dialog if (!dialog) { // Initializes breadcrumb master page element InitializeBreadcrumbs(currentVolumeDiscount); } else { // Change validators location spanMinCount.Attributes["style"] = "display:block"; spanValue.Attributes["style"] = "display:block"; } InitializeMasterPage(titleText, titleImage); RegisterEscScript(); RegisterModalPageScripts(); }
/// <summary> /// Creates volume discount. Called when the "Create discount" button is pressed. /// Expects the CreateProduct method to be run first. /// </summary> private bool CreateVolumeDiscount() { // Get the data var product = SKUInfoProvider.GetSKUs() .WhereStartsWith("SKUName", "MyNew") .FirstOrDefault(); if (product != null) { // Create new volume discount object VolumeDiscountInfo newDiscount = new VolumeDiscountInfo(); // Set the properties newDiscount.VolumeDiscountMinCount = 100; newDiscount.VolumeDiscountValue = 20; newDiscount.VolumeDiscountSKUID = product.SKUID; newDiscount.VolumeDiscountIsFlatValue = false; // Create the volume discount VolumeDiscountInfoProvider.SetVolumeDiscountInfo(newDiscount); return true; } return false; }
protected void Page_Load(object sender, EventArgs e) { ScriptHelper.RegisterJQuery(this); volumeDiscountID = QueryHelper.GetInteger("VolumeDiscountID", 0); sku = SKUInfoProvider.GetSKUInfo(ProductID); if (sku != null) { CheckEditedObjectSiteID(sku.SKUSiteID); // Get currency of product price currency = CurrencyInfoProvider.GetMainCurrency(sku.SKUSiteID); currencyCode = (currency != null) ? currency.CurrencyCode : ""; currencyCode = HTMLHelper.HTMLEncode(currencyCode); // Display product price lblProductPrice.Text = CurrencyInfoProvider.GetFormattedPrice(sku.SKUPrice, currency); // Check presence of main currency string currencyWarning = CheckMainCurrency(sku.SKUSiteID); if (!string.IsNullOrEmpty(currencyWarning)) { ShowWarning(currencyWarning, null, null); } } string titleText = ""; string titleImage = ""; // Init labels lblVolumeDiscountValue.Text = GetString("product_edit_volumediscount_edit.volumediscountvaluelabel"); lblVolumeDiscountMinCount.Text = GetString("product_edit_volumediscount_edit.volumediscountmincountlabel"); radDiscountAbsolute.Text = GetString("product_edit_volumediscount_edit.rbdiscountabsolute"); radDiscountRelative.Text = GetString("product_edit_volumediscount_edit.rbdiscountrelative"); // Init value validator error messages rfvDiscountValue.ErrorMessage = GetString("product_edit_volumediscount_edit.rfvDiscountValue"); rvDiscountValue.ErrorMessage = GetString("product_edit_volumediscount_edit.rvDiscountValue"); rvDiscountValue.MaximumValue = int.MaxValue.ToString(); // Init min count validator error messages rfvMinCount.ErrorMessage = GetString("product_edit_volumediscount_edit.rfvMinCount"); rvMinCount.ErrorMessage = GetString("product_edit_volumediscount_edit.rvMinCount"); rvMinCount.MaximumValue = int.MaxValue.ToString(); radDiscountAbsolute.Attributes["onclick"] = "jQuery('span[id*=\"lblCurrency\"]').html(" + ScriptHelper.GetString("(" + currencyCode + ")") + ")"; radDiscountRelative.Attributes["onclick"] = "jQuery('span[id*=\"lblCurrency\"]').html('(%)')"; string currentVolumeDiscount = GetString("Product_Edit_VolumeDiscount_Edit.NewItemCaption"); // If true, then we will edit existing record if (volumeDiscountID > 0) { // Check if there is already VolumeDiscountInfo with this volumeDiscountID volumeDiscountObj = VolumeDiscountInfoProvider.GetVolumeDiscountInfo(volumeDiscountID); if (volumeDiscountID > 0) { EditedObject = volumeDiscountObj; } if (volumeDiscountObj != null) { // Fill editing form with existing data when not postback if (!RequestHelper.IsPostBack()) { LoadData(volumeDiscountObj); // Set caption of edited item currentVolumeDiscount = GetString("product_edit_volumediscount_edit.edittitletext"); // Show that the volumeDiscount was created or updated successfully if (QueryHelper.GetString("saved", "") == "1") { // Show message ShowChangesSaved(); // Refresh parent page when editing in modal dialog if (dialog) { ltlScript.Text = ScriptHelper.GetScript("wopener.RefreshPage();"); } } } } // Set page title to "volume discount properties" titleText = GetString("product_edit_volumediscount_edit.edittitletext"); titleImage = GetImageUrl("Objects/Ecommerce_VolumeDiscount/object.png"); } // Do this when creating new discount else { // Set default radio button value if (!URLHelper.IsPostback()) { radDiscountRelative.Checked = true; radDiscountAbsolute.Checked = false; } // Init page header to "new item" titleText = GetString("product_edit_volumediscount_edit.newitemcaption"); titleImage = GetImageUrl("Objects/Ecommerce_VolumeDiscount/new.png"); } // Show breadcrumbs only when not editing in modal dialog if (!dialog) { // Initializes breadcrumb master page element InitializeBreadcrumbs(currentVolumeDiscount); } else { // Change validators location spanMinCount.Attributes["style"] = "display:block"; spanValue.Attributes["style"] = "display:block"; } InitializeMasterPage(titleText, titleImage); RegisterEscScript(); RegisterModalPageScripts(); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (sku == null) { return; } if (CheckProductPermissions(sku)) { // True if there is already same min count; bool isMinCountUnique = false; // Server side validation of user input string errorMessage = new Validator().NotEmpty(txtVolumeDiscountValue.Text, "product_edit_volumediscount_edit.volumediscountvaluelabel") .NotEmpty(txtVolumeDiscountMinCount.Text, "product_edit_volumediscount_edit.volumediscountmincountlabel").Result; // Discount value validation if (errorMessage == "") { // Relative if (radDiscountRelative.Checked && !ValidationHelper.IsInRange(0, 100, ValidationHelper.GetDouble(txtVolumeDiscountValue.Text.Trim(), -1))) { errorMessage = GetString("Com.Error.RelativeDiscountValue"); } // Absolute else if (radDiscountAbsolute.Checked && !ValidationHelper.IsPositiveNumber(ValidationHelper.GetDouble(txtVolumeDiscountValue.Text.Trim(), -1))) { errorMessage = GetString("Com.Error.AbsoluteDiscountValue"); } } if (errorMessage == "") { VolumeDiscountInfo volumeDiscountObj = VolumeDiscountInfoProvider.GetVolumeDiscountInfo(volumeDiscountID); // If volumeDiscount doesnt already exist, create new one if (volumeDiscountObj == null) { // Create new volume discount volumeDiscountObj = new VolumeDiscountInfo(); // When creating new one, set his SKUID to productID (obtained from URL) volumeDiscountObj.VolumeDiscountSKUID = ProductID; } // Set volumeDiscountObj values volumeDiscountObj.VolumeDiscountValue = Convert.ToDouble(txtVolumeDiscountValue.Text.Trim()); volumeDiscountObj.VolumeDiscountMinCount = Convert.ToInt32(txtVolumeDiscountMinCount.Text.Trim()); volumeDiscountObj.VolumeDiscountIsFlatValue = radDiscountAbsolute.Checked; // Set isMinCountUnique VolumeDiscountInfo vdi = VolumeDiscountInfoProvider.GetVolumeDiscountInfo(ProductID, volumeDiscountObj.VolumeDiscountMinCount); if (vdi == null) { isMinCountUnique = true; } else { isMinCountUnique = (vdi.VolumeDiscountMinCount != volumeDiscountObj.VolumeDiscountMinCount); } // Check if min count is unique or it is update of existing item if ((isMinCountUnique) || (vdi.VolumeDiscountID == volumeDiscountObj.VolumeDiscountID)) { string dialogString = ""; if (dialog) { dialogString = "&modaldialog=1"; } // Sets data to database VolumeDiscountInfoProvider.SetVolumeDiscountInfo(volumeDiscountObj); string redirectUrl = "Product_Edit_VolumeDiscount_Edit.aspx?VolumeDiscountID=" + volumeDiscountObj.VolumeDiscountID + "&siteId=" + SiteID + "&saved=1&productID=" + ProductID + dialogString; URLHelper.Redirect(AddNodeIDParameterToUrl(redirectUrl)); } else { // Show error message ShowError(GetString("product_edit_volumediscount_edit.minamountexists")); } } else { // Show error message ShowError(errorMessage); } } }
protected void Page_Load(object sender, EventArgs e) { ScriptHelper.RegisterJQuery(this); if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Content", "ContentProduct.VolumeDiscounts")) { RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "ContentProduct.VolumeDiscounts"); } // Get parameters from querystring volumeDiscountID = QueryHelper.GetInteger("VolumeDiscountID", 0); productID = QueryHelper.GetInteger("ProductID", 0); sku = SKUInfoProvider.GetSKUInfo(productID); if (sku != null) { currencyCode = CurrencyInfoProvider.GetMainCurrencyCode(sku.SKUSiteID); // Check presence of main currency string currencyErr = CheckMainCurrency(sku.SKUSiteID); if (!string.IsNullOrEmpty(currencyErr)) { // Show message lblError.Text = currencyErr; lblError.Visible = true; } } // Init labels lblVolumeDiscountValue.Text = GetString("product_edit_volumediscount_edit.volumediscountvaluelabel"); lblVolumeDiscountMinCount.Text = GetString("product_edit_volumediscount_edit.volumediscountmincountlabel"); radDiscountAbsolute.Text = GetString("product_edit_volumediscount_edit.rbdiscountabsolute"); radDiscountRelative.Text = GetString("product_edit_volumediscount_edit.rbdiscountrelative"); // Init value validator error messages rfvDiscountValue.ErrorMessage = GetString("product_edit_volumediscount_edit.rfvdiscountvalue"); rvDiscountValue.ErrorMessage = GetString("product_edit_volumediscount_edit.rvdiscountvalue"); rvDiscountValue.MaximumValue = int.MaxValue.ToString(); // Init min count validator error messages rfvMinCount.ErrorMessage = GetString("product_edit_volumediscount_edit.rfvmincount"); rvMinCount.ErrorMessage = GetString("product_edit_volumediscount_edit.rvmincount"); rvMinCount.MaximumValue = int.MaxValue.ToString(); radDiscountAbsolute.Attributes["onclick"] = "jQuery('span[id*=\"lblCurrency\"]').html(" + ScriptHelper.GetString("(" + currencyCode + ")") + ")"; radDiscountRelative.Attributes["onclick"] = "jQuery('span[id*=\"lblCurrency\"]').html('(%)')"; btnOk.Text = GetString("general.ok"); btnCancel.Text = GetString("general.cancel"); // If true, edit the existing volume discount if (volumeDiscountID > 0) { // Check if there is already VolumeDiscountInfo with this volumeDiscountID VolumeDiscountInfo volumeDiscountObj = VolumeDiscountInfoProvider.GetVolumeDiscountInfo(volumeDiscountID); EditedObject = volumeDiscountObj; if (volumeDiscountObj != null) { // Fill editing form with existing data when not postback if (!RequestHelper.IsPostBack()) { LoadData(volumeDiscountObj); // Show that the volumeDiscount was created or updated successfully if (QueryHelper.GetString("saved", "") == "1") { lblInfo.Visible = true; lblInfo.Text = GetString("general.changessaved"); // Refresh parent page when editing in modal dialog ltlScript.Text = ScriptHelper.GetScript("wopener.RefreshPage(); window.close();"); } } } // Set page title to "volume discount properties" this.CurrentMaster.Title.TitleText = GetString("product_edit_volumediscount_edit.edittitletext"); this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Ecommerce_VolumeDiscount/object.png"); } // Create new volume discount else { if (!RequestHelper.IsPostBack()) { // Set defaults this.radDiscountRelative.Checked = true; } // Init page header to "new item" this.CurrentMaster.Title.TitleText = GetString("product_edit_volumediscount_edit.newitemcaption"); this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Ecommerce_VolumeDiscount/new.png"); } this.CurrentMaster.Title.HelpTopicName = "newedit_discount"; this.CurrentMaster.Title.HelpName = "helpTopic"; this.CurrentMaster.HeadElements.Text = "<base target=\"_self\" />"; this.CurrentMaster.HeadElements.Visible = true; ScriptHelper.RegisterWOpenerScript(Page); }