private DiscountCouponInfo GetDiscountByOrderId(int orderID) { var ev = new EventLogProvider(); try { DiscountCouponInfo discountCouponInfo = new DiscountCouponInfo(); string sql = "SELECT [DiscountCouponID],[DiscountCouponValue],[DiscountCouponIsFlatValue],[DiscountCouponValidTo] FROM [COM_DiscountCoupon] " + "INNER JOIN [COM_Order] ON [COM_Order].[OrderDiscountCouponID] = [COM_DiscountCoupon].[DiscountCouponID] " + "WHERE [COM_Order].[OrderID] = @orderID"; var param = new QueryDataParameters(); param.Add(new DataParameter("@orderID", orderID)); DataSet ds = ConnectionHelper.ExecuteQuery(sql, param, QueryTypeEnum.SQLQuery); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow reader in ds.Tables[0].Rows) { discountCouponInfo.DiscountCouponID = ValidationHelper.GetInteger(reader["DiscountCouponID"], 0); discountCouponInfo.DiscountCouponIsFlatValue = ValidationHelper.GetBoolean(reader["DiscountCouponIsFlatValue"], false); discountCouponInfo.DiscountCouponValue = ValidationHelper.GetDouble(reader["DiscountCouponValue"], 0); discountCouponInfo.DiscountCouponValidTo = ValidationHelper.GetDateTime(reader["DiscountCouponValidTo"], DateTime.MinValue); return(discountCouponInfo); } } return(discountCouponInfo); } catch (Exception ex) { ev.LogEvent("E", DateTime.Now, "CMSModuleLoader.GetDiscountValueById", ex.Message); } return(null); }
/// <summary> /// Returns DiscountCoupnValue of products in current shopping cart. /// </summary> private object GetDiscountValueShoppingCart(MacroResolver resolver) { var currentOrderId = resolver.ResolveMacros("{% Order.OrderID %}"); double discountCoupon = 0; CMS.Ecommerce.ShoppingCartInfo shoppingCartInfo = resolver.SourceObject as CMS.Ecommerce.ShoppingCartInfo; CMS.Ecommerce.CurrencyInfo currentCurrency = null; DiscountCouponInfo currentDiscountCouponInfo = GetDiscountByOrderId(int.Parse(currentOrderId)); if (shoppingCartInfo != null) { currentCurrency = shoppingCartInfo.Currency; discountCoupon = currentDiscountCouponInfo.DiscountCouponValue; if (currentDiscountCouponInfo.DiscountCouponIsFlatValue) { return(discountCoupon + " €"); } return(discountCoupon + " %"); } return(string.Empty); }
/// <summary> /// Checks whether entered dsicount coupon code is usable for this cart. Returns true if so. /// </summary> private bool CheckDiscountCoupon() { bool success = true; if (txtCoupon.Text.Trim() != "") { // Get discount info DiscountCouponInfo dci = DiscountCouponInfoProvider.GetDiscountCouponInfo(txtCoupon.Text.Trim(), this.ShoppingCartInfoObj.SiteName); // Do not validate coupon when editing existing order and coupon code was not changed, otherwise process validation if ((dci != null) && (((this.ShoppingCartInfoObj.IsCreatedFromOrder) && (ShoppingCartInfoObj.ShoppingCartDiscountCouponID == dci.DiscountCouponID)) || dci.IsValid)) { ShoppingCartInfoObj.ShoppingCartDiscountCouponID = dci.DiscountCouponID; } else { ShoppingCartInfoObj.ShoppingCartDiscountCouponID = 0; // Discount coupon is not valid lblError.Text = GetString("ecommerce.error.couponcodeisnotvalid"); success = false; } } else { ShoppingCartInfoObj.ShoppingCartDiscountCouponID = 0; } return(success); }
protected void Page_Load(object sender, EventArgs e) { string currentDiscountCoupon = ""; mDiscountId = QueryHelper.GetInteger("discountid", 0); if (mDiscountId > 0) { DiscountCouponInfo discountCouponObj = DiscountCouponInfoProvider.GetDiscountCouponInfo(mDiscountId); if (discountCouponObj != null) { editedSiteId = discountCouponObj.DiscountCouponSiteID; // Check if edited object belongs to configured site CheckEditedObjectSiteID(editedSiteId); currentDiscountCoupon = ResHelper.LocalizeString(discountCouponObj.DiscountCouponDisplayName); } } CMSMasterPage master = (CMSMasterPage)CurrentMaster; // Initializes page title breadcrumbs control string[,] breadcrumbs = new string[2, 3]; breadcrumbs[0, 0] = GetString("DiscounCoupon_Edit.ItemListLink"); breadcrumbs[0, 1] = "~/CMSModules/Ecommerce/Pages/Tools/DiscountCoupons/DiscountCoupon_List.aspx?siteId=" + SiteID; breadcrumbs[0, 2] = "ecommerceContent"; breadcrumbs[1, 0] = FormatBreadcrumbObjectName(currentDiscountCoupon, editedSiteId); breadcrumbs[1, 1] = ""; breadcrumbs[1, 2] = ""; CurrentMaster.Title.Breadcrumbs = breadcrumbs; // Tabs master.Tabs.OnTabCreated += Tabs_OnTabCreated; }
protected void Page_Load(object sender, EventArgs e) { orderCoupon.Text = GetString("Ecommerce.Discount.IsAnOrderDiscount"); rfvCouponCode.ErrorMessage = GetString("DiscounCoupon_Edit.errorCode"); rfvDisplayName.ErrorMessage = GetString("DiscounCoupon_Edit.errorDisplay"); radFixed.Text = GetString("DiscounCoupon_Edit.radFixed"); radPercentage.Text = GetString("DiscounCoupon_Edit.radPercentage"); dtPickerDiscountCouponValidTo.SupportFolder = "~/CMSAdminControls/Calendar"; dtPickerDiscountCouponValidFrom.SupportFolder = "~/CMSAdminControls/Calendar"; // Get discountCoupon id from querystring mDiscountId = QueryHelper.GetInteger("discountid", 0); editedSiteId = ConfiguredSiteID; if (mDiscountId > 0) { DiscountCouponInfo discountCouponObj = DiscountCouponInfoProvider.GetDiscountCouponInfo(mDiscountId); EditedObject = discountCouponObj; if (discountCouponObj != null) { editedSiteId = discountCouponObj.DiscountCouponSiteID; // Check if edited object belongs to configured site CheckEditedObjectSiteID(editedSiteId); // Fill editing form if (!RequestHelper.IsPostBack()) { LoadData(discountCouponObj); // Show that the discountCoupon was created or updated successfully if (QueryHelper.GetString("saved", "") == "1") { ShowChangesSaved(); } } } } currencyCode = HTMLHelper.HTMLEncode(CurrencyInfoProvider.GetMainCurrencyCode(editedSiteId)); // Check presence of main currency string currencyWarning = CheckMainCurrency(ConfiguredSiteID); if (!string.IsNullOrEmpty(currencyWarning)) { ShowWarning(currencyWarning, null, null); } radFixed.Attributes["onclick"] = "jQuery('span[id*=\"lblCurrency\"]').html(" + ScriptHelper.GetString("(" + currencyCode + ")") + ")"; radPercentage.Attributes["onclick"] = "jQuery('span[id*=\"lblCurrency\"]').html('(%)')"; }
/// <summary> /// Load data of editing discountCoupon. /// </summary> /// <param name="discountCouponObj">DiscountCoupon object</param> protected void LoadData(DiscountCouponInfo discountCouponObj) { txtDiscountCouponValue.Text = Convert.ToString(discountCouponObj.DiscountCouponValue); dtPickerDiscountCouponValidTo.SelectedDateTime = discountCouponObj.DiscountCouponValidTo; txtDiscountCouponCode.Text = discountCouponObj.DiscountCouponCode; txtDiscountCouponDisplayName.Text = discountCouponObj.DiscountCouponDisplayName; dtPickerDiscountCouponValidFrom.SelectedDateTime = discountCouponObj.DiscountCouponValidFrom; radPercentage.Checked = !discountCouponObj.DiscountCouponIsFlatValue; radFixed.Checked = discountCouponObj.DiscountCouponIsFlatValue; }
/// <summary> /// Load data of editing discountCoupon. /// </summary> /// <param name="discountCouponObj">DiscountCoupon object</param> protected void LoadData(DiscountCouponInfo discountCouponObj) { txtDiscountCouponValue.Text = Convert.ToString(discountCouponObj.DiscountCouponValue); dtPickerDiscountCouponValidTo.SelectedDateTime = discountCouponObj.DiscountCouponValidTo; txtDiscountCouponCode.Text = discountCouponObj.DiscountCouponCode; txtDiscountCouponDisplayName.Text = discountCouponObj.DiscountCouponDisplayName; dtPickerDiscountCouponValidFrom.SelectedDateTime = discountCouponObj.DiscountCouponValidFrom; radPercentage.Checked = !discountCouponObj.DiscountCouponIsFlatValue; radFixed.Checked = discountCouponObj.DiscountCouponIsFlatValue; orderCoupon.Checked = ValidationHelper.GetBoolean(discountCouponObj.GetValue("DiscountCouponIsForOrder"), false); }
protected void Page_Load(object sender, EventArgs e) { if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Ecommerce", "DiscountCoupons.Products")) { RedirectToCMSDeskUIElementAccessDenied("CMS.Ecommerce", "DiscountCoupons.Products"); } mDiscountCouponId = QueryHelper.GetInteger("discountid", 0); if (mDiscountCouponId > 0) { mDiscountCouponInfoObj = DiscountCouponInfoProvider.GetDiscountCouponInfo(mDiscountCouponId); EditedObject = mDiscountCouponInfoObj; if (mDiscountCouponInfoObj != null) { // Check if edited object belongs to configured site CheckEditedObjectSiteID(mDiscountCouponInfoObj.DiscountCouponSiteID); // Get the active skus DataSet ds = SKUInfoProvider.GetCouponProducts(mDiscountCouponId); if (!DataHelper.DataSourceIsEmpty(ds)) { mCurrentValues = TextHelper.Join(";", SqlHelperClass.GetStringValues(ds.Tables[0], "SKUID")); } if (!RequestHelper.IsPostBack()) { this.uniSelector.Value = mCurrentValues; radFollowing.Checked = true; radExcept.Checked = false; if (mDiscountCouponInfoObj.DiscountCouponIsExcluded) { radFollowing.Checked = false; radExcept.Checked = true; } } } } this.uniSelector.IconPath = GetObjectIconUrl("ecommerce.sku", "object.png"); this.uniSelector.OnSelectionChanged += uniSelector_OnSelectionChanged; this.uniSelector.WhereCondition = GetWhereCondition(); this.lblApplies.Text = GetString("Discount_Product.Applies"); this.radExcept.Text = GetString("Discount_Product.radExcept"); this.radFollowing.Text = GetString("Discount_Product.radFollowing"); }
/// <inheritdoc /> public Task <UpdateStatus> UpdateDiscountCouponAsync(DiscountCouponInfo coupon, CancellationToken cancellationToken) { if (coupon == null) { throw new ArgumentNullException(); } if (string.IsNullOrWhiteSpace(coupon.Code)) { throw new ArgumentException("Coupon code must have a value", nameof(coupon.Code)); } return(PutApiAsync <UpdateStatus>(GetUrl($"{DiscountCouponsUrl}/{coupon.Code}"), coupon, cancellationToken)); }
private double CalculateDiscount(DiscountCouponInfo discountCoupon, double price) { double result = 0; double totalPrice = price; if (discountCoupon.DiscountCouponIsFlatValue) { result = discountCoupon.DiscountCouponValue; } else { result = totalPrice * discountCoupon.DiscountCouponValue / 100.0; } return(result); }
protected void Page_Load(object sender, EventArgs e) { string currentDiscountCoupon = ""; mDiscountId = QueryHelper.GetInteger("discountid", 0); if (mDiscountId > 0) { DiscountCouponInfo discountCouponObj = DiscountCouponInfoProvider.GetDiscountCouponInfo(mDiscountId); if (discountCouponObj != null) { editedSiteId = discountCouponObj.DiscountCouponSiteID; // Check if edited object belongs to configured site CheckEditedObjectSiteID(editedSiteId); currentDiscountCoupon = ResHelper.LocalizeString(discountCouponObj.DiscountCouponDisplayName); } } CMSMasterPage master = (CMSMasterPage)this.CurrentMaster; // Page title master.Title.HelpTopicName = "new_coupongeneral_tab"; master.Title.HelpName = "helpTopic"; // Initializes page title breadcrumbs control string[,] breadcrumbs = new string[2, 3]; breadcrumbs[0, 0] = GetString("DiscounCoupon_Edit.ItemListLink"); breadcrumbs[0, 1] = "~/CMSModules/Ecommerce/Pages/Tools/DiscountCoupons/DiscountCoupon_List.aspx?siteId=" + SiteID; breadcrumbs[0, 2] = "ecommerceContent"; breadcrumbs[1, 0] = FormatBreadcrumbObjectName(currentDiscountCoupon, editedSiteId); breadcrumbs[1, 1] = ""; breadcrumbs[1, 2] = ""; this.CurrentMaster.Title.Breadcrumbs = breadcrumbs; // Tabs master.Tabs.ModuleName = "CMS.Ecommerce"; master.Tabs.ElementName = "DiscountCoupons"; master.Tabs.UrlTarget = "DiscountContent"; master.Tabs.OnTabCreated += new UITabs.TabCreatedEventHandler(Tabs_OnTabCreated); // Set master title master.Title.TitleText = GetString("com.discountcoupon.edit"); master.Title.TitleImage = GetImageUrl("Objects/Ecommerce_DiscountCoupon/object.png"); }
protected void Page_Load(object sender, EventArgs e) { mDiscountCouponId = QueryHelper.GetInteger("discountid", 0); if (mDiscountCouponId > 0) { mDiscountCouponInfoObj = DiscountCouponInfoProvider.GetDiscountCouponInfo(mDiscountCouponId); EditedObject = mDiscountCouponInfoObj; if (mDiscountCouponInfoObj != null) { // Check if edited object belongs to configured site CheckEditedObjectSiteID(mDiscountCouponInfoObj.DiscountCouponSiteID); // Get the active skus DataSet ds = SKUInfoProvider.GetCouponProducts(mDiscountCouponId); if (!DataHelper.DataSourceIsEmpty(ds)) { mCurrentValues = TextHelper.Join(";", SystemDataHelper.GetStringValues(ds.Tables[0], "SKUID")); } if (!RequestHelper.IsPostBack()) { uniSelector.Value = mCurrentValues; radFollowing.Checked = true; radExcept.Checked = false; if (mDiscountCouponInfoObj.DiscountCouponIsExcluded) { radFollowing.Checked = false; radExcept.Checked = true; } } } } // Init selector uniSelector.IconPath = GetObjectIconUrl("ecommerce.sku", "object.png"); uniSelector.OnSelectionChanged += uniSelector_OnSelectionChanged; uniSelector.WhereCondition = GetWhereCondition(); lblApplies.Text = GetString("Discount_Product.Applies"); radExcept.Text = GetString("Discount_Product.radExcept"); radFollowing.Text = GetString("Discount_Product.radFollowing"); }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void gridElem_OnAction(string actionName, object actionArgument) { if (actionName == "edit") { // Discount coupon detail url var redirectURL = UIContextHelper.GetElementUrl(ModuleName.ECOMMERCE, "EditDiscountCouponProperties", false, actionArgument.ToInteger(0)); redirectURL = URLHelper.AddParameterToUrl(redirectURL, "siteid", SiteContext.CurrentSiteID.ToString()); URLHelper.Redirect(redirectURL); } else if (actionName == "delete") { int id = ValidationHelper.GetInteger(actionArgument, 0); DiscountCouponInfo discountCouponInfoObj = DiscountCouponInfoProvider.GetDiscountCouponInfo(id); // Nothing to delete if (discountCouponInfoObj == null) { return; } // Check module permissions if (!ECommerceContext.IsUserAuthorizedToModifyDiscountCoupon(discountCouponInfoObj)) { if (discountCouponInfoObj.IsGlobal) { RedirectToAccessDenied(ModuleName.ECOMMERCE, EcommercePermissions.ECOMMERCE_MODIFYGLOBAL); } else { RedirectToAccessDenied(ModuleName.ECOMMERCE, "EcommerceModify OR ModifyDiscounts"); } } if (discountCouponInfoObj.Generalized.CheckDependencies()) { ShowError(ECommerceHelper.GetDependencyMessage(discountCouponInfoObj)); return; } // Delete DiscountCouponInfo object from database DiscountCouponInfoProvider.DeleteDiscountCouponInfo(discountCouponInfoObj); } }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void gridElem_OnAction(string actionName, object actionArgument) { if (actionName == "edit") { URLHelper.Redirect("DiscountCoupon_Edit_Frameset.aspx?discountid=" + Convert.ToString(actionArgument) + "&siteId=" + SelectSite.SiteID); } else if (actionName == "delete") { int id = ValidationHelper.GetInteger(actionArgument, 0); DiscountCouponInfo discountCouponInfoObj = DiscountCouponInfoProvider.GetDiscountCouponInfo(id); // Nothing to delete if (discountCouponInfoObj == null) { return; } // Check module permissions if (!ECommerceContext.IsUserAuthorizedToModifyDiscountCoupon(discountCouponInfoObj)) { if (discountCouponInfoObj.IsGlobal) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify"); } else { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyDiscounts"); } } if (DiscountCouponInfoProvider.CheckDependencies(id)) { lblError.Visible = true; lblError.Text = GetString("Ecommerce.DeleteDisabled"); return; } // Delete DiscountCouponInfo object from database DiscountCouponInfoProvider.DeleteDiscountCouponInfo(discountCouponInfoObj); } }
/// <summary> /// Returns total price of products in current shopping cart. /// </summary> private object GetTotalShoppingCart(MacroResolver resolver) { string currentOrderId = QueryHelper.GetInteger("orderID", 0).ToString(); double totalpriceht = 0; CMS.Ecommerce.ShoppingCartInfo totalPriceHtShoppingCartInfo = resolver.SourceObject as CMS.Ecommerce.ShoppingCartInfo; CMS.Ecommerce.CurrencyInfo currentTotalPriceHtCurrency = null; DiscountCouponInfo currentDiscountCouponInfo = GetDiscountByOrderId(int.Parse(currentOrderId)); if (totalPriceHtShoppingCartInfo != null) { currentTotalPriceHtCurrency = totalPriceHtShoppingCartInfo.Currency; totalpriceht = Convert.ToDouble(totalPriceHtShoppingCartInfo.TotalItemsPriceInMainCurrency); if (currentDiscountCouponInfo != null && currentDiscountCouponInfo.DiscountCouponValidTo < DateTime.Now) { totalpriceht = totalPriceHtShoppingCartInfo.TotalPrice; } } return(CMS.Ecommerce.CurrencyInfoProvider.GetFormattedValue(totalpriceht, currentTotalPriceHtCurrency).ToString()); }
private static IEnumerable <DiscountCouponInfo> MockDiscountCoupons(int count) { var rand = new Random(); var coupon = new DiscountCouponInfo { Code = "ABC123DEF", CreationDate = "2016-03-24 05:51:53", Discount = 18, DiscountType = "ABS_AND_SHIPPING", LaunchDate = "2016-03-25 05:51:53", ExpirationDate = "2017-03-25 05:51:53", Name = "Test Coupon", RepeatCustomerOnly = false, UsesLimit = "UNLIMITED", Status = "ACTIVE", Id = 100000 + rand.Next(101), OrderCount = 0, TotalLimit = 18 }; return(Enumerable.Range(0, count).Select(_ => coupon)); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check module permissions bool global = (editedSiteId <= 0); if (!ECommerceContext.IsUserAuthorizedToModifyDiscountCoupon(global)) { if (global) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify"); } else { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyDiscounts"); } } string errorMessage = new Validator().NotEmpty(txtDiscountCouponDisplayName.Text.Trim(), GetString("DiscounCoupon_Edit.errorDisplay")) .NotEmpty(txtDiscountCouponCode.Text.Trim(), GetString("DiscounCoupon_Edit.errorCode")) .IsCodeName(txtDiscountCouponCode.Text.Trim(), GetString("DiscounCoupon_Edit.errorCodeFormat")).Result; // Discount value validation if (errorMessage == "") { // Relative if (this.radPercentage.Checked && !ValidationHelper.IsInRange(0, 100, ValidationHelper.GetDouble(this.txtDiscountCouponValue.Text.Trim(), -1))) { errorMessage = GetString("Com.Error.RelativeDiscountValue"); } // Absolute else if (this.radFixed.Checked && !ValidationHelper.IsPositiveNumber(ValidationHelper.GetDouble(this.txtDiscountCouponValue.Text.Trim(), -1))) { errorMessage = GetString("Com.Error.AbsoluteDiscountValue"); } } // From/to date validation if (errorMessage == "") { if ((!dtPickerDiscountCouponValidFrom.IsValidRange()) || (!dtPickerDiscountCouponValidTo.IsValidRange())) { errorMessage = GetString("general.errorinvaliddatetimerange"); } if ((dtPickerDiscountCouponValidFrom.SelectedDateTime != DateTime.MinValue) && (dtPickerDiscountCouponValidTo.SelectedDateTime != DateTime.MinValue) && (dtPickerDiscountCouponValidFrom.SelectedDateTime >= dtPickerDiscountCouponValidTo.SelectedDateTime)) { errorMessage = GetString("General.DateOverlaps"); } } if (errorMessage == "") { // DiscountCoupon code name must to be unique DiscountCouponInfo discountCouponObj = null; string siteWhere = (editedSiteId > 0) ? " AND (DiscountCouponSiteID = " + editedSiteId + " OR DiscountCouponSiteID IS NULL)" : ""; DataSet ds = DiscountCouponInfoProvider.GetDiscountCoupons("DiscountCouponCode = '" + txtDiscountCouponCode.Text.Trim().Replace("'", "''") + "'" + siteWhere, null, 1, null); if (!DataHelper.DataSourceIsEmpty(ds)) { discountCouponObj = new DiscountCouponInfo(ds.Tables[0].Rows[0]); } // If discountCouponCode value is unique if ((discountCouponObj == null) || (discountCouponObj.DiscountCouponID == mDiscountId)) { // If discountCouponCode value is unique -> determine whether it is update or insert if ((discountCouponObj == null)) { // Get DiscountCouponInfo object by primary key discountCouponObj = DiscountCouponInfoProvider.GetDiscountCouponInfo(mDiscountId); if (discountCouponObj == null) { // Create new item -> insert discountCouponObj = new DiscountCouponInfo(); discountCouponObj.DiscountCouponSiteID = editedSiteId; } } discountCouponObj.DiscountCouponValue = ValidationHelper.GetDouble(txtDiscountCouponValue.Text.Trim(), 0.0); discountCouponObj.DiscountCouponCode = txtDiscountCouponCode.Text.Trim(); discountCouponObj.DiscountCouponIsFlatValue = true; if (radPercentage.Checked) { discountCouponObj.DiscountCouponIsFlatValue = false; } discountCouponObj.DiscountCouponDisplayName = txtDiscountCouponDisplayName.Text.Trim(); discountCouponObj.DiscountCouponValidFrom = dtPickerDiscountCouponValidFrom.SelectedDateTime; discountCouponObj.DiscountCouponValidTo = dtPickerDiscountCouponValidTo.SelectedDateTime; DiscountCouponInfoProvider.SetDiscountCouponInfo(discountCouponObj); URLHelper.Redirect("DiscountCoupon_Edit_General.aspx?discountid=" + Convert.ToString(discountCouponObj.DiscountCouponID) + "&saved=1&siteId=" + SiteID); } else { lblError.Visible = true; lblError.Text = GetString("DiscounCoupon_Edit.DiscountCouponCodeExists"); } } else { lblError.Visible = true; lblError.Text = errorMessage; } }
/// <summary> /// Resolves custom macros. /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Event arguments representing the resolved macro</param> private void MacroResolver_OnResolveCustomMacro(object sender, MacroEventArgs e) { var ev = new EventLogProvider(); string discountValue = null; string orderId = QueryHelper.GetInteger("orderID", 0).ToString(); MacroResolver shoppingCartInfoObMacroResolver = (MacroResolver)sender; // Checks that the macro is not resolved yet. if (!e.Match) { // Defines the return values of specific custom macro expressions. switch (e.Expression.ToLower()) { // Handles the {#CustomExpression#} macro. case "firstletter": string firstletter = CMS.MacroEngine.MacroContext.CurrentResolver.ResolveMacros("{%CurrentUser.LastName%}"); string substr = string.Empty; if (!string.IsNullOrEmpty(firstletter)) { substr = firstletter.Substring(0, 1); } e.Match = true; e.Result = substr; break; case "priceht": //Get Shopping Cart Object from resolver MacroResolver test = (MacroResolver)sender; CMS.Ecommerce.ShoppingCartInfo cartObj = test.SourceObject as CMS.Ecommerce.ShoppingCartInfo; CMS.Ecommerce.CurrencyInfo currentCurrency = null; currentCurrency = cartObj.Currency; double tax = Convert.ToDouble(cartObj.TotalTax); double price = Convert.ToDouble(cartObj.TotalPrice); double resultat = price - tax; e.Match = true; e.Result = CMS.Ecommerce.CurrencyInfoProvider.GetFormattedValue(resultat, currentCurrency).ToString(); break; case "taxe": MacroResolver test1 = (MacroResolver)sender; CMS.Ecommerce.ShoppingCartInfo cartObj1 = test1.SourceObject as CMS.Ecommerce.ShoppingCartInfo; double taxe = Convert.ToDouble(cartObj1.TotalTax); currentCurrency = cartObj1.Currency; e.Match = true; e.Result = CMS.Ecommerce.CurrencyInfoProvider.GetFormattedValue(taxe, currentCurrency).ToString(); break; case "invoice": int num1 = 0; var cn = ConnectionHelper.GetConnection(); DataSet orders = cn.ExecuteQuery("Ecommerce.Transformations.invoice", null, null); //CMS.Ecommerce.OrderInfoProvider.GetOrders(null, null); // DataSet orders = cn.ExecuteQuery("Ecommerce.Transformations.invoice", null, null, null, 1);//CMS.Ecommerce.OrderInfoProvider.GetOrders(null, null); if (!DataHelper.DataSourceIsEmpty(orders)) { num1 = Convert.ToInt32(orders.Tables[0].Rows[0]["max"]) + 1; // int nb = orders.Tables[0].Rows.Count; //// Create object from DataRow //// ev.LogEvent("E", DateTime.Now, "nb", nb.ToString()); ////78 // for (int i = 0; i < nb; i++) // { // CMS.Ecommerce.OrderInfo order = new CMS.Ecommerce.OrderInfo(orders.Tables[0].Rows[i]); // // ev.LogEvent("E", DateTime.Now, "nb", order.OrderInvoiceNumber); // if (order.OrderInvoiceNumber != null) // { // num = int.Parse(order.OrderInvoiceNumber) + 1; // // i = nb + 1; // break; // } // ev.LogEvent("E", DateTime.Now, "nb1", num.ToString()); // } CMS.EventLog.EventLogProvider.LogEvent("E", "", "", num1.ToString(), "CMSModuleLoader.GetSkuidByUserId", 0, "", 0, "", "", 0, "", "", "", DateTime.Now); // ev.LogEvent("E", DateTime.Now, "nb1", num1.ToString()); } e.Match = true; e.Result = num1.ToString(); break; case "value1": //string orderID = CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros("{%Order.OrderID%}"); // string wherc="OrderID ="+orderID; // DataSet ordersitem = CMS.Ecommerce.OrderItemInfoProvider.GetOrderItems(wherc, null); // string value1 = string.Empty; // string orderID = CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros("{%OrderID%}"); // if (!DataHelper.DataSourceIsEmpty(ordersitem)) // { // foreach (DataRow orderItemDr in ordersitem.Tables[0].Rows) // { // Create object from DataRow // CMS.Ecommerce.OrderItemInfo orderItem = new CMS.Ecommerce.OrderItemInfo(ordersitem.Tables[0].Rows[0]); // value1 = orderItem.OrderItemPrice.ToString(); // ev.LogEvent("E", DateTime.Now, "TVA", value1); // } // } e.Match = true; e.Result = ""; break; case "titreinvoice": string value = string.Empty; string facture = CMS.MacroEngine.MacroContext.CurrentResolver.ResolveMacros("{%Order.facture%}"); string commande = CMS.MacroEngine.MacroContext.CurrentResolver.ResolveMacros("{%Order.OrderID%}"); if (string.IsNullOrEmpty(facture)) { value = "Commande N° " + commande; } else { value = "Facture N° " + facture; } e.Match = true; e.Result = value; break; case "six": double taxe6 = 0; MacroResolver test6 = (MacroResolver)sender; CMS.Ecommerce.ShoppingCartInfo cartObj6 = test6.SourceObject as CMS.Ecommerce.ShoppingCartInfo; foreach (CMS.Ecommerce.ShoppingCartItemInfo ci in cartObj6.CartItems) { DataTable t = ci.TaxesTable; foreach (DataRow drow in t.Rows) { //double theTax = Convert.ToDouble(drow["TaxValue"]); double theTax = (double)drow["TaxValue"]; if (theTax == 6) { taxe6 += ci.TotalPrice - ci.TotalTax; break; } } } e.Match = true; //e.Result = CMS.Ecommerce.CurrencyInfoProvider.GetFormattedValue(taxe6, currentCurrency).ToString(); e.Result = taxe6; break; case "unsix": double taxe7 = 0; MacroResolver test7 = (MacroResolver)sender; CMS.Ecommerce.ShoppingCartInfo cartObj7 = test7.SourceObject as CMS.Ecommerce.ShoppingCartInfo; foreach (CMS.Ecommerce.ShoppingCartItemInfo ci in cartObj7.CartItems) { DataTable t = ci.TaxesTable; foreach (DataRow drow in t.Rows) { //double theTax = Convert.ToDouble(drow["TaxValue"]); double theTax = (double)drow["TaxValue"]; if (theTax != 6) { taxe7 += ci.TotalPrice - ci.TotalTax; break; } } } e.Match = true; //e.Result = CMS.Ecommerce.CurrencyInfoProvider.GetFormattedValue(taxe6, currentCurrency).ToString(); e.Result = taxe7; break; case "hastax": double taxe8 = 0; MacroResolver test8 = (MacroResolver)sender; CMS.Ecommerce.ShoppingCartInfo cartObj8 = test8.SourceObject as CMS.Ecommerce.ShoppingCartInfo; foreach (CMS.Ecommerce.ShoppingCartItemInfo ci in cartObj8.CartItems) { DataTable t = ci.TaxesTable; foreach (DataRow drow in t.Rows) { //double theTax = Convert.ToDouble(drow["TaxValue"]); double theTax = (double)drow["TaxValue"]; if (theTax > 0) { taxe8 = 1; break; } } } e.Match = true; //e.Result = CMS.Ecommerce.CurrencyInfoProvider.GetFormattedValue(taxe6, currentCurrency).ToString(); e.Result = taxe8; break; case "infoeproduct": e.Match = true; string txt = string.Empty; var bdResolver = (MacroResolver)sender; CMS.EventLog.EventLogProvider.LogEvent("I", "", "", "", "infoeproduct", 0, "", 0, "", "", 0, "", "", "", DateTime.Now); // ev.LogEvent("I", DateTime.Now, "infoeproduct", ""); if (bdResolver != null) { CMS.EventLog.EventLogProvider.LogEvent("I", "", "", "", "bdResolver not null", 0, "", 0, "", "", 0, "", "", "", DateTime.Now); // ev.LogEvent("I", DateTime.Now, "bdResolver not null", ""); var sCart = (ShoppingCartInfo)bdResolver.SourceObject; if (sCart != null) { CMS.EventLog.EventLogProvider.LogEvent("I", "", "", "", "sCart not null", 0, "", 0, "", "", 0, "", "", "", DateTime.Now); // ev.LogEvent("I", DateTime.Now, "sCart not null", ""); CMS.EventLog.EventLogProvider.LogEvent("I", "", "", "", "OrderId : " + sCart.ShoppingCartCustomerID.ToString(), 0, "", 0, "", "", 0, "", "", "", DateTime.Now); // ev.LogEvent("I", DateTime.Now, "OrderId : " + sCart.ShoppingCartCustomerID.ToString(), ""); if (sCart.ShoppingCartCustomerID > 0) { List <int> skuids = GetSkuidByCustomerId(sCart.ShoppingCartCustomerID); foreach (var skuid in skuids) { string typeproduct = GetSkuProductTypeBySkuId(skuid); if (typeproduct != string.Empty && typeproduct == "EPRODUCT") { txt = "Vous allez recevoir le code de téléchargement par courriel séparé d’ici un instant."; break; } } } } } e.Result = txt; break; case "freebundle": string bundle = string.Empty, bundledString = string.Empty; MacroResolver bundleResolver = (MacroResolver)sender; ShoppingCartInfo sc = bundleResolver.SourceObject as ShoppingCartInfo; if (sc != null) { bundledString = sc.GetStringValue("ShoppingCartBundleData", string.Empty); if (string.IsNullOrEmpty(bundledString)) { OrderInfo oi = OrderInfoProvider.GetOrderInfo(sc.OrderId); if (oi != null) { bundledString = oi.GetStringValue("OrderBundleData", string.Empty); } } if (!string.IsNullOrEmpty(bundledString)) { bundle = string.Format("<b><u>Liste de vos produits gratuits:</u></b><br/> {0}", CustomBundle.TranslateBundle(bundledString)); } } e.Match = true; e.Result = bundle; break; case "discountvalue": if (!string.IsNullOrEmpty(orderId)) { discountValue = GetDiscountValueById(int.Parse(orderId)); } e.Match = true; e.Result = discountValue; break; case "totalitemspriceinmaincurrency": double discountvaluepercent = 0; CMS.Ecommerce.ShoppingCartInfo shoppingCartInfo = shoppingCartInfoObMacroResolver.SourceObject as CMS.Ecommerce.ShoppingCartInfo; if (shoppingCartInfo != null) { discountvaluepercent = shoppingCartInfo.TotalItemsPriceInMainCurrency; } e.Match = true; e.Result = discountvaluepercent; break; case "getdiscountvalue": double discountCoupon = 0; CMS.Ecommerce.ShoppingCartInfo cartInfo = shoppingCartInfoObMacroResolver.SourceObject as CMS.Ecommerce.ShoppingCartInfo; if (!string.IsNullOrEmpty(orderId)) { DiscountCouponInfo currentDiscountCouponInfo = GetDiscountByOrderId(int.Parse(orderId)); discountCoupon = CalculateDiscount(currentDiscountCouponInfo, cartInfo.TotalItemsPriceInMainCurrency); } e.Match = true; e.Result = discountCoupon; break; } } }
/// <summary> /// Page load. /// </summary> protected void Page_Load(object sender, EventArgs e) { this.lblTitle.Text = GetString("ShoppingCart.CartContent"); //bool currencySelected = false; if ((ShoppingCartInfoObj != null) && (ShoppingCartInfoObj.CountryID == 0) && (CMSContext.CurrentSite != null)) { string countryName = ECommerceSettings.DefaultCountryName(CMSContext.CurrentSite.SiteName); CountryInfo ci = CountryInfoProvider.GetCountryInfo(countryName); ShoppingCartInfoObj.CountryID = (ci != null) ? ci.CountryID : 0; // Set currency selectors site ID selectCurrency.SiteID = this.ShoppingCartInfoObj.ShoppingCartSiteID; } // Initialization imgNewItem.ImageUrl = GetImageUrl("Objects/Ecommerce_OrderItem/add.png"); lblCurrency.Text = GetString("Ecommerce.ShoppingCartContent.Currency"); lblCoupon.Text = GetString("Ecommerce.ShoppingCartContent.Coupon"); lnkNewItem.Text = GetString("Ecommerce.ShoppingCartContent.AddItem"); imgNewItem.AlternateText = lnkNewItem.Text; btnUpdate.Text = GetString("Ecommerce.ShoppingCartContent.BtnUpdate"); btnEmpty.Text = GetString("Ecommerce.ShoppingCartContent.BtnEmpty"); btnEmpty.OnClientClick = "return confirm(" + ScriptHelper.GetString(GetString("Ecommerce.ShoppingCartContent.EmptyConfirm")) + ");"; //this.TitleText = GetString("order_new.cartcontent.title"); lnkNewItem.OnClientClick = "OpenAddProductDialog('" + GetCMSDeskShoppingCartSessionName() + "');return false;"; gridData.Columns[4].HeaderText = GetString("general.remove"); gridData.Columns[5].HeaderText = GetString("Ecommerce.ShoppingCartContent.SKUName"); gridData.Columns[6].HeaderText = GetString("Ecommerce.ShoppingCartContent.SKUUnits"); gridData.Columns[7].HeaderText = GetString("Ecommerce.ShoppingCartContent.UnitPrice"); gridData.Columns[8].HeaderText = GetString("Ecommerce.ShoppingCartContent.UnitDiscount"); gridData.Columns[9].HeaderText = GetString("Ecommerce.ShoppingCartContent.Tax"); gridData.Columns[10].HeaderText = GetString("Ecommerce.ShoppingCartContent.Subtotal"); this.gridData.RowDataBound += new GridViewRowEventHandler(gridData_RowDataBound); // Registre product price detail javascript StringBuilder script = new StringBuilder(); script.Append("function ShowProductPriceDetail(cartItemGuid, sessionName){"); script.Append("if (sessionName != \"\"){sessionName = \"&cart=\" + sessionName;}"); string detailUrl = "~/CMSModules/Ecommerce/Controls/ShoppingCart/ShoppingCartSKUPriceDetail.aspx"; if (this.IsLiveSite) { detailUrl = "~/CMSModules/Ecommerce/CMSPages/ShoppingCartSKUPriceDetail.aspx"; } script.Append("modalDialog('" + ResolveUrl(detailUrl) + "?itemguid=' + cartItemGuid + sessionName, 'ProductPriceDetail', 750, 500);}"); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ProductPriceDetail", ScriptHelper.GetScript(script.ToString())); script = new StringBuilder(); script.Append("function OpenOrderItemDialog(cartItemGuid, sessionName){"); script.Append("if (sessionName != \"\"){sessionName = \"&cart=\" + sessionName;}"); script.Append("modalDialog('" + ResolveUrl("~/CMSModules/Ecommerce/Controls/ShoppingCart/OrderItemEdit.aspx") + "?itemguid=' + cartItemGuid + sessionName, 'OrderItemEdit', 500, 350);}"); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "OrderItemEdit", ScriptHelper.GetScript(script.ToString())); // Hide "add product" link if it is live site order if (!this.ShoppingCartControl.IsInternalOrder) { pnlNewItem.Visible = false; this.ShoppingCartControl.ButtonBack.Text = GetString("Ecommerce.CartContent.ButtonBackText"); this.ShoppingCartControl.ButtonBack.CssClass = "LongButton"; this.ShoppingCartControl.ButtonNext.Text = GetString("Ecommerce.CartContent.ButtonNextText"); if (!this.ShoppingCartControl.IsCurrentStepPostBack) { // Get shopping cart item parameters from URL ShoppingCartItemParameters itemParams = ShoppingCartItemParameters.GetShoppingCartItemParameters(); // Set item in the shopping cart AddProducts(itemParams); } } // Set sending order notification when editing existing order according to the site settings if (this.ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems) { if (!this.ShoppingCartControl.IsCurrentStepPostBack) { SiteInfo si = SiteInfoProvider.GetSiteInfo(this.ShoppingCartInfoObj.ShoppingCartSiteID); if (si != null) { chkSendEmail.Checked = ECommerceSettings.SendOrderNotification(si.SiteName); } } chkSendEmail.Visible = true; chkSendEmail.Text = GetString("ShoppingCartContent.SendEmail"); } if (this.ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems) { this.ShoppingCartControl.ButtonBack.Visible = false; this.ShoppingCartInfoObj.CheckAvailableItems = false; if ((!ExistAnotherStepsExceptPayment) && (this.ShoppingCartControl.PaymentGatewayProvider == null)) { this.ShoppingCartControl.ButtonNext.Text = GetString("General.OK"); } else { this.ShoppingCartControl.ButtonNext.Text = GetString("general.next"); } } // Fill dropdownlist if (!this.ShoppingCartControl.IsCurrentStepPostBack) { if ((this.ShoppingCartInfoObj.CartItems.Count > 0) || this.ShoppingCartControl.IsInternalOrder) { if (this.ShoppingCartInfoObj != null) { if (ShoppingCartInfoObj.ShoppingCartCurrencyID == 0) { // Select customer preferred currency if (ShoppingCartInfoObj.CustomerInfoObj != null) { CustomerInfo customer = ShoppingCartInfoObj.CustomerInfoObj; ShoppingCartInfoObj.ShoppingCartCurrencyID = (customer.CustomerUser != null) ? customer.CustomerUser.GetUserPreferredCurrencyID(CMSContext.CurrentSiteName) : 0; } } if (ShoppingCartInfoObj.ShoppingCartCurrencyID == 0) { if (CMSContext.CurrentSite != null) { ShoppingCartInfoObj.ShoppingCartCurrencyID = CMSContext.CurrentSite.SiteDefaultCurrencyID; } } selectCurrency.CurrencyID = ShoppingCartInfoObj.ShoppingCartCurrencyID; if (ShoppingCartInfoObj.ShoppingCartDiscountCouponID > 0) { // fill textbox with discount coupon code DiscountCouponInfo dci = DiscountCouponInfoProvider.GetDiscountCouponInfo(ShoppingCartInfoObj.ShoppingCartDiscountCouponID); if (dci != null) { if (this.ShoppingCartInfoObj.IsCreatedFromOrder || dci.IsValid) { txtCoupon.Text = dci.DiscountCouponCode; } else { this.ShoppingCartInfoObj.ShoppingCartDiscountCouponID = 0; } } } } } ReloadData(); } // Turn on available items checking after content is loaded ShoppingCartInfoObj.CheckAvailableItems = true; }
/// <summary> /// Gets and bulk updates discount coupons. Called when the "Get and bulk update coupons" button is pressed. /// Expects the CreateDiscountCoupon method to be run first. /// </summary> private bool GetAndBulkUpdateDiscountCoupons() { // Prepare the parameters string where = "DiscountCouponCode LIKE N'MyNewCoupon%'"; // Get the data DataSet coupons = DiscountCouponInfoProvider.GetDiscountCoupons(where, null); if (!DataHelper.DataSourceIsEmpty(coupons)) { // Loop through the individual items foreach (DataRow couponDr in coupons.Tables[0].Rows) { // Create object from DataRow DiscountCouponInfo modifyCoupon = new DiscountCouponInfo(couponDr); // Update the properties modifyCoupon.DiscountCouponDisplayName = modifyCoupon.DiscountCouponDisplayName.ToUpper(); // Update the discount coupon DiscountCouponInfoProvider.SetDiscountCouponInfo(modifyCoupon); } return true; } return false; }
protected override void OnLoad(EventArgs e) { lblTitle.Text = GetString("shoppingcart.cartcontent"); if ((ShoppingCart != null) && (ShoppingCart.CountryID == 0) && (SiteContext.CurrentSite != null)) { string countryName = ECommerceSettings.DefaultCountryName(SiteContext.CurrentSite.SiteName); CountryInfo ci = CountryInfoProvider.GetCountryInfo(countryName); ShoppingCart.CountryID = (ci != null) ? ci.CountryID : 0; // Set currency selectors site ID selectCurrency.SiteID = ShoppingCart.ShoppingCartSiteID; } imgNewItem.ImageUrl = GetImageUrl("Objects/Ecommerce_OrderItem/add.png"); lblCurrency.Text = GetString("ecommerce.shoppingcartcontent.currency"); lblCoupon.Text = GetString("ecommerce.shoppingcartcontent.coupon"); lnkNewItem.Text = GetString("ecommerce.shoppingcartcontent.additem"); imgNewItem.AlternateText = lnkNewItem.Text; btnUpdate.Text = GetString("ecommerce.shoppingcartcontent.btnupdate"); btnEmpty.Text = GetString("ecommerce.shoppingcartcontent.btnempty"); btnEmpty.OnClientClick = string.Format("return confirm({0});", ScriptHelper.GetString(GetString("ecommerce.shoppingcartcontent.emptyconfirm"))); lnkNewItem.OnClientClick = string.Format("OpenAddProductDialog('{0}');return false;", GetCMSDeskShoppingCartSessionName()); gridData.Columns[4].HeaderText = GetString("general.remove"); gridData.Columns[5].HeaderText = GetString("ecommerce.shoppingcartcontent.actions"); gridData.Columns[6].HeaderText = GetString("ecommerce.shoppingcartcontent.skuname"); gridData.Columns[7].HeaderText = GetString("ecommerce.shoppingcartcontent.skuunits"); gridData.Columns[8].HeaderText = GetString("ecommerce.shoppingcartcontent.unitprice"); gridData.Columns[9].HeaderText = GetString("ecommerce.shoppingcartcontent.unitdiscount"); gridData.Columns[10].HeaderText = GetString("ecommerce.shoppingcartcontent.tax"); gridData.Columns[11].HeaderText = GetString("ecommerce.shoppingcartcontent.subtotal"); gridData.RowDataBound += new GridViewRowEventHandler(gridData_RowDataBound); // Register product price detail dialog script StringBuilder script = new StringBuilder(); script.Append("function ShowProductPriceDetail(cartItemGuid, sessionName) {"); script.Append("if (sessionName != \"\"){sessionName = \"&cart=\" + sessionName;}"); string detailUrl = (IsLiveSite) ? "~/CMSModules/Ecommerce/CMSPages/ShoppingCartSKUPriceDetail.aspx" : "~/CMSModules/Ecommerce/Controls/ShoppingCart/ShoppingCartSKUPriceDetail.aspx"; script.Append(string.Format("modalDialog('{0}?itemguid=' + cartItemGuid + sessionName, 'ProductPriceDetail', 750, 500); }}", ResolveUrl(detailUrl))); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ProductPriceDetail", ScriptHelper.GetScript(script.ToString())); // Register add order item dialog script script = new StringBuilder(); script.Append("function OpenOrderItemDialog(cartItemGuid, sessionName) {"); script.Append("if (sessionName != \"\"){sessionName = \"&cart=\" + sessionName;}"); script.Append(string.Format("modalDialog('{0}?itemguid=' + cartItemGuid + sessionName, 'OrderItemEdit', 500, 350); }}", ResolveUrl("~/CMSModules/Ecommerce/Controls/ShoppingCart/OrderItemEdit.aspx"))); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "OrderItemEdit", ScriptHelper.GetScript(script.ToString())); script = new StringBuilder(); string addProductUrl = AuthenticationHelper.ResolveDialogUrl("~/CMSModules/Ecommerce/Pages/Tools/Orders/Order_Edit_AddItems.aspx"); script.AppendFormat("var addProductDialogURL = '{0}'", URLHelper.GetAbsoluteUrl(addProductUrl)); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "AddProduct", ScriptHelper.GetScript(script.ToString())); // Hide "add product" action for live site order if (!ShoppingCartControl.IsInternalOrder) { pnlNewItem.Visible = false; ShoppingCartControl.ButtonBack.Text = GetString("ecommerce.cartcontent.buttonbacktext"); ShoppingCartControl.ButtonBack.CssClass = "LongButton"; ShoppingCartControl.ButtonNext.Text = GetString("ecommerce.cartcontent.buttonnexttext"); if (!ShoppingCartControl.IsCurrentStepPostBack) { // Get shopping cart item parameters from URL ShoppingCartItemParameters itemParams = ShoppingCartItemParameters.GetShoppingCartItemParameters(); // Set item in the shopping cart AddProducts(itemParams); } } // Set sending order notification when editing existing order according to the site settings if (ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems) { if (!ShoppingCartControl.IsCurrentStepPostBack) { if (!string.IsNullOrEmpty(ShoppingCart.SiteName)) { chkSendEmail.Checked = ECommerceSettings.SendOrderNotification(ShoppingCart.SiteName); } } // Show send email checkbox chkSendEmail.Visible = true; chkSendEmail.Text = GetString("shoppingcartcontent.sendemail"); // Setup buttons ShoppingCartControl.ButtonBack.Visible = false; ShoppingCart.CheckAvailableItems = false; ShoppingCartControl.ButtonNext.Text = GetString("general.next"); if ((!ExistAnotherStepsExceptPayment) && (ShoppingCartControl.PaymentGatewayProvider == null)) { ShoppingCartControl.ButtonNext.Text = GetString("general.ok"); } } // Fill dropdownlist if (!ShoppingCartControl.IsCurrentStepPostBack) { if ((ShoppingCart.CartItems.Count > 0) || ShoppingCartControl.IsInternalOrder) { if (ShoppingCart.ShoppingCartCurrencyID == 0) { // Select customer preferred currency if (ShoppingCart.Customer != null) { CustomerInfo customer = ShoppingCart.Customer; ShoppingCart.ShoppingCartCurrencyID = (customer.CustomerUser != null) ? customer.CustomerUser.GetUserPreferredCurrencyID(SiteContext.CurrentSiteName) : 0; } } if (ShoppingCart.ShoppingCartCurrencyID == 0) { if (SiteContext.CurrentSite != null) { ShoppingCart.ShoppingCartCurrencyID = SiteContext.CurrentSite.SiteDefaultCurrencyID; } } selectCurrency.CurrencyID = ShoppingCart.ShoppingCartCurrencyID; if (ShoppingCart.ShoppingCartDiscountCouponID > 0) { // Fill textbox with discount coupon code DiscountCouponInfo dci = DiscountCouponInfoProvider.GetDiscountCouponInfo(ShoppingCart.ShoppingCartDiscountCouponID); if (dci != null) { if (ShoppingCart.IsCreatedFromOrder || dci.IsValid) { txtCoupon.Text = dci.DiscountCouponCode; } else { ShoppingCart.ShoppingCartDiscountCouponID = 0; } } } } ReloadData(); } // Check if customer is enabled if ((ShoppingCart.Customer != null) && (!ShoppingCart.Customer.CustomerEnabled)) { HideCartContent(GetString("ecommerce.cartcontent.customerdisabled")); } // Turn on available items checking after content is loaded ShoppingCart.CheckAvailableItems = true; base.OnLoad(e); }
protected void Page_Load(object sender, EventArgs e) { if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Ecommerce", "DiscountCoupons.General")) { RedirectToCMSDeskUIElementAccessDenied("CMS.Ecommerce", "DiscountCoupons.General"); } rfvCouponCode.ErrorMessage = GetString("DiscounCoupon_Edit.errorCode"); rfvDisplayName.ErrorMessage = GetString("DiscounCoupon_Edit.errorDisplay"); // Control initializations lblDiscountCouponValue.Text = GetString("DiscounCoupon_Edit.DiscountCouponAbsoluteValueLabel"); lblDiscountCouponValidTo.Text = GetString("DiscounCoupon_Edit.DiscountCouponValidToLabel"); lblDiscountCouponCode.Text = GetString("DiscounCoupon_Edit.DiscountCouponCodeLabel"); lblDiscountCouponDisplayName.Text = GetString("DiscounCoupon_Edit.DiscountCouponDisplayNameLabel"); lblDiscountCouponValidFrom.Text = GetString("DiscounCoupon_Edit.DiscountCouponValidFromLabel"); radFixed.Text = GetString("DiscounCoupon_Edit.radFixed"); radPercentage.Text = GetString("DiscounCoupon_Edit.radPercentage"); btnOk.Text = GetString("General.OK"); dtPickerDiscountCouponValidTo.SupportFolder = "~/CMSAdminControls/Calendar"; dtPickerDiscountCouponValidFrom.SupportFolder = "~/CMSAdminControls/Calendar"; // Get discountCoupon id from querystring mDiscountId = QueryHelper.GetInteger("discountid", 0); editedSiteId = ConfiguredSiteID; if (mDiscountId > 0) { DiscountCouponInfo discountCouponObj = DiscountCouponInfoProvider.GetDiscountCouponInfo(mDiscountId); EditedObject = discountCouponObj; if (discountCouponObj != null) { editedSiteId = discountCouponObj.DiscountCouponSiteID; // Check if edited object belongs to configured site CheckEditedObjectSiteID(editedSiteId); // Fill editing form if (!RequestHelper.IsPostBack()) { LoadData(discountCouponObj); // Show that the discountCoupon was created or updated successfully if (QueryHelper.GetString("saved", "") == "1") { lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); } } } } currencyCode = HTMLHelper.HTMLEncode(CurrencyInfoProvider.GetMainCurrencyCode(editedSiteId)); // Check presence of main currency string currencyErr = CheckMainCurrency(ConfiguredSiteID); if (!string.IsNullOrEmpty(currencyErr)) { // Show message lblError.Text = currencyErr; lblError.Visible = true; } radFixed.Attributes["onclick"] = "jQuery('span[id*=\"lblCurrency\"]').html(" + ScriptHelper.GetString("(" + currencyCode + ")") + ")"; radPercentage.Attributes["onclick"] = "jQuery('span[id*=\"lblCurrency\"]').html('(%)')"; }
/// <inheritdoc /> public Task <DeleteStatus> DeleteDiscountCouponAsync(DiscountCouponInfo coupon) => DeleteDiscountCouponAsync(coupon.Code);
/// <inheritdoc /> public Task <DiscountCouponCreateStatus> CreateDiscountCouponAsync(DiscountCouponInfo coupon) => CreateDiscountCouponAsync(coupon, CancellationToken.None);
/// <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 (IsShippingNeeded && ShoppingCart.ShoppingCartBillingAddressID <= 0) { ShoppingCartControl.LoadStep(0); return(false); } // Check if customer is enabled if ((ShoppingCart.Customer != null) && (!ShoppingCart.Customer.CustomerEnabled)) { lblError.Text = GetString("ecommerce.cartcontent.customerdisabled"); return(false); } // Deal with order note ShoppingCartControl.SetTempValue(ORDER_NOTE, null); ShoppingCart.ShoppingCartNote = txtNote.Text.Trim(); try { // Set order culture ShoppingCart.ShoppingCartCulture = LocalizationContext.PreferredCultureCode; // Update customer preferences CustomerInfoProvider.SetCustomerPreferredSettings(ShoppingCart); // Create order ShoppingCartInfoProvider.SetOrder(ShoppingCart); ShoppingCart.Order.SetValue("OrderBundleData", ShoppingCart.GetStringValue("ShoppingCartBundleData", string.Empty)); } catch (Exception ex) { // Show error lblError.Text = GetString("Ecommerce.OrderPreview.ErrorOrderSave"); // Log exception EventLogProvider.LogException("Shopping cart", "SAVEORDER", ex, ShoppingCart.ShoppingCartSiteID, null); return(false); } // Track order items conversions ECommerceHelper.TrackOrderItemsConversions(ShoppingCart); // Track order conversion string name = ShoppingCartControl.OrderTrackConversionName; ECommerceHelper.TrackOrderConversion(ShoppingCart, name); // Track order activity string siteName = SiteContext.CurrentSiteName; if (LogActivityForCustomer) { ShoppingCartControl.TrackActivityPurchasedProducts(ShoppingCart, siteName, ContactID); ShoppingCartControl.TrackActivityPurchase(ShoppingCart.OrderId, ContactID, SiteContext.CurrentSiteName, RequestContext.CurrentRelativePath, ShoppingCart.TotalPriceInMainCurrency, CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.TotalPriceInMainCurrency, CurrencyInfoProvider.GetMainCurrency(CMSContext.CurrentSiteID))); } // Raise finish order event ShoppingCartControl.RaiseOrderCompletedEvent(); string currentCultureCode = DocumentContext.CurrentDocument.DocumentCulture; string template = "Ecommerce.OrderNotificationToCustomer" + currentCultureCode; // When in CMSDesk if (ShoppingCartControl.IsInternalOrder) { if (chkSendEmail.Checked) { // Send order notification emails OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart); OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart, template); } } // When on the live site else if (ECommerceSettings.SendOrderNotification(SiteContext.CurrentSite.SiteName)) { // Send order notification emails OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart); OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart, template); } /*desactiver le coupon code*/ if (Session["CouponValue"] != null) { DiscountCouponInfo dci = DiscountCouponInfoProvider.GetDiscountCouponInfo(Session["CouponValue"].ToString(), ShoppingCart.SiteName); if ((dci != null) && (((ShoppingCart.IsCreatedFromOrder) && (ShoppingCart.ShoppingCartDiscountCouponID == dci.DiscountCouponID)) || dci.IsValid)) { DateTime d = DateTime.Now; d = d.AddMinutes(5); dci.DiscountCouponValidTo = d; Session["CouponValue"] = null; } } /**/ return(true); }
/// <inheritdoc /> public Task <DiscountCouponCreateStatus> CreateDiscountCouponAsync(DiscountCouponInfo coupon, CancellationToken cancellationToken) { return(PostJsonApiAsync <DiscountCouponCreateStatus>(GetUrl(DiscountCouponsUrl), coupon, cancellationToken)); }
/// <summary> /// Creates discount coupon. Called when the "Create coupon" button is pressed. /// </summary> private bool CreateDiscountCoupon() { // Create new discount coupon object DiscountCouponInfo newCoupon = new DiscountCouponInfo(); // Set the properties newCoupon.DiscountCouponDisplayName = "My new coupon"; newCoupon.DiscountCouponCode = "MyNewCoupon"; newCoupon.DiscountCouponIsExcluded = true; newCoupon.DiscountCouponIsFlatValue = true; newCoupon.DiscountCouponValue = 200; newCoupon.DiscountCouponValidFrom = DateTime.Now; newCoupon.DiscountCouponSiteID = CMSContext.CurrentSiteID; // Create the discount coupon DiscountCouponInfoProvider.SetDiscountCouponInfo(newCoupon); return true; }