public void BindData() { CustomerRoleCollection customerRoles = CustomerManager.GetAllCustomerRoles(); divDealer.Attributes.CssStyle.Add("display", "none"); foreach (CustomerRole customerRole in customerRoles) { ListItem item = new ListItem(customerRole.Name, customerRole.CustomerRoleId.ToString()); if (this.selectedCustomerRoleIds.Contains(customerRole.CustomerRoleId)) { item.Selected = true; if (customerRole.CustomerRoleId == 5) { divDealer.Attributes.CssStyle.Remove("display"); divDealer.Attributes.CssStyle.Add("display", "block"); } } if (customerRole.CustomerRoleId == 5) { item.Attributes.Add("class", "dealerClick"); } this.cblCustomerRoles.Items.Add(item); } this.cblCustomerRoles.DataBind(); }
private void BindData() { Discount discount = DiscountManager.GetDiscountByID(this.DiscountID); if (discount != null) { CommonHelper.SelectListItem(this.ddlDiscountType, discount.DiscountTypeID); CommonHelper.SelectListItem(this.ddlDiscountRequirement, discount.DiscountRequirementID); this.txtName.Text = discount.Name; this.cbUsePercentage.Checked = discount.UsePercentage; this.txtDiscountPercentage.Value = discount.DiscountPercentage; this.txtDiscountAmount.Value = discount.DiscountAmount; this.cStartDateButtonExtender.SelectedDate = discount.StartDate; this.cEndDateButtonExtender.SelectedDate = discount.EndDate; this.cbRequiresCouponCode.Checked = discount.RequiresCouponCode; this.txtCouponCode.Text = discount.CouponCode; CustomerRoleCollection customerRoles = discount.CustomerRoles; List <int> _customerRoleIDs = new List <int>(); foreach (CustomerRole customerRole in customerRoles) { _customerRoleIDs.Add(customerRole.CustomerRoleID); } CustomerRoleMappingControl.SelectedCustomerRoleIDs = _customerRoleIDs; CustomerRoleMappingControl.BindData(); } else { List <int> _customerRoleIDs = new List <int>(); CustomerRoleMappingControl.SelectedCustomerRoleIDs = _customerRoleIDs; CustomerRoleMappingControl.BindData(); } }
/// <summary> /// Checks customer role requirement for customer /// </summary> /// <param name="CustomerID">Customer identifier</param> /// <returns></returns> public bool CheckCustomerRoleRequirement(int CustomerID) { if (this.DiscountRequirement != DiscountRequirementEnum.MustBeAssignedToCustomerRole) { return(true); } //rewrite logic. Load customer roles by discount id (and not discounts by customer role id) //CustomerRoleCollection customerRoles = CustomerManager.GetCustomerRolesByCustomerID(CustomerID); //foreach (CustomerRole _customerRole in customerRoles) // foreach (Discount _discount in _customerRole.Discounts) // { // if (_discount.Name == this.Name) // { // return true; // } // } CustomerRoleCollection customerRoles = CustomerManager.GetCustomerRolesByCustomerID(CustomerID); CustomerRoleCollection assignedRoles = this.CustomerRoles; foreach (CustomerRole _customerRole in customerRoles) { foreach (CustomerRole _assignedRole in assignedRoles) { if (_customerRole.Name == _assignedRole.Name) { return(true); } } } return(false); }
void BindGrid() { CustomerRoleCollection customerRoleCollection = CustomerManager.GetAllCustomerRoles(); gvCustomerRoles.DataSource = customerRoleCollection; gvCustomerRoles.DataBind(); }
/// <summary> /// Gets a value indicating whether tax is free /// </summary> /// <param name="productVariant">Product variant</param> /// <param name="customer">Customer</param> /// <returns>A value indicating whether tax is free</returns> protected static bool IsFreeTax(ProductVariant productVariant, Customer customer) { if (customer != null) { if (customer.IsTaxExempt) { return(true); } CustomerRoleCollection customerRoles = customer.CustomerRoles; foreach (CustomerRole customerRole in customerRoles) { if (customerRole.TaxExempt) { return(true); } } } if (productVariant == null) { return(false); } if (productVariant.IsTaxExempt) { return(true); } return(false); }
/// <summary> /// Resets cached values for an instance /// </summary> public void ResetCachedValues() { _customerAttributesCache = null; _customerRolesCache = null; _billingAddressCache = null; _shippingAddressCache = null; _rewardPointsHistoryCache = null; }
/// <summary> /// Gets a value indicating whether shipping is free /// </summary> /// <param name="Cart">Cart</param> /// <param name="customer">Customer</param> /// <returns>A value indicating whether shipping is free</returns> protected static bool IsFreeShipping(ShoppingCart Cart, Customer customer) { if (customer != null) { CustomerRoleCollection customerRoles = customer.CustomerRoles; foreach (CustomerRole customerRole in customerRoles) { if (customerRole.FreeShipping) { return(true); } } } bool shoppingCartRequiresShipping = ShoppingCartRequiresShipping(Cart); if (!shoppingCartRequiresShipping) { return(true); } decimal orderSubTotalDiscount; decimal orderSubTotal = ShoppingCartManager.GetShoppingCartSubTotal(Cart, customer, out orderSubTotalDiscount); if (SettingManager.GetSettingValueBoolean("Shipping.FreeShippingOverX.Enabled")) { decimal freeShippingOverX = SettingManager.GetSettingValueDecimalNative("Shipping.FreeShippingOverX.Value"); if (orderSubTotal > freeShippingOverX) { return(true); } } bool allItemsAreFreeShipping = true; foreach (ShoppingCartItem sc in Cart) { if (!sc.IsFreeShipping) { allItemsAreFreeShipping = false; break; } } if (allItemsAreFreeShipping) { return(true); } return(false); }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { try { CustomerRoleCollection roles = CustomerManager.GetAllCustomerRoles(); if (roles.Count == 0) { lblMessage.Text = GetLocaleResourceString("Admin.ACL.NoRolesDefined"); return; } SettingManager.SetParam("ACL.Enabled", cbACLEnabled.Checked.ToString()); foreach (GridViewRow row in gvACL.Rows) { foreach (CustomerRole cr in roles) { CheckBox cbAllow = row.FindControl(string.Format("cbAllow_{0}", cr.CustomerRoleId)) as CheckBox; HiddenField hfCustomerActionId = row.FindControl(string.Format("hfCustomerActionId_{0}", cr.CustomerRoleId)) as HiddenField; if (cbAllow == null || hfCustomerActionId == null || String.IsNullOrEmpty(hfCustomerActionId.Value)) { return; } bool allow = cbAllow.Checked; int customerActionId = int.Parse(hfCustomerActionId.Value); ACLCollection acls = ACLManager.GetAllAcl(customerActionId, cr.CustomerRoleId, null); if (acls.Count > 0) { ACL acl = acls[0]; ACLManager.UpdateAcl(acl.AclId, customerActionId, cr.CustomerRoleId, allow); } else { ACL acl = ACLManager.InsertAcl(customerActionId, cr.CustomerRoleId, allow); } } } Response.Redirect("ACL.aspx"); } catch (Exception exc) { ProcessException(exc); } } }
public void BindData() { CustomerRoleCollection customerRoles = CustomerManager.GetAllCustomerRoles(); foreach (CustomerRole customerRole in customerRoles) { ListItem item = new ListItem(customerRole.Name, customerRole.CustomerRoleId.ToString()); if (this.selectedCustomerRoleIds.Contains(customerRole.CustomerRoleId)) { item.Selected = true; } this.cblCustomerRoles.Items.Add(item); } this.cblCustomerRoles.DataBind(); }
private void BindData() { Customer customer = CustomerManager.GetCustomerByID(this.CustomerID); if (customer != null) { CustomerRoleCollection customerRoles = customer.CustomerRoles; List <int> _customerRoleIDs = new List <int>(); foreach (CustomerRole customerRole in customerRoles) { _customerRoleIDs.Add(customerRole.CustomerRoleID); } CustomerRoleMappingControl.SelectedCustomerRoleIDs = _customerRoleIDs; CustomerRoleMappingControl.BindData(); } }
protected void BindGrid() { CustomerActionCollection actions = ACLManager.GetAllCustomerActions(); if (actions.Count == 0) { lblMessage.Text = GetLocaleResourceString("Admin.ACL.NoActionDefined"); return; } CustomerRoleCollection roles = CustomerManager.GetAllCustomerRoles(); if (roles.Count == 0) { lblMessage.Text = GetLocaleResourceString("Admin.ACL.NoRolesDefined"); return; } List <CustomerActionACLMappingHelperClass> dt = new List <CustomerActionACLMappingHelperClass>(); foreach (CustomerAction ca in actions) { CustomerActionACLMappingHelperClass map1 = new CustomerActionACLMappingHelperClass(); map1.CustomerActionId = ca.CustomerActionId; map1.CustomerActionName = ca.Name; map1.Allow = new Dictionary <int, bool>(); foreach (CustomerRole cr in roles) { ACLCollection acls = ACLManager.GetAllAcl(ca.CustomerActionId, cr.CustomerRoleId, null); if (acls.Count > 0) { ACL acl = acls[0]; map1.Allow.Add(cr.CustomerRoleId, acl.Allow); } else { map1.Allow.Add(cr.CustomerRoleId, false); } } dt.Add(map1); } gvACL.DataSource = dt; gvACL.DataBind(); }
protected void BuildColumnsDynamically() { gvACL.Columns.Clear(); TemplateField tfAction = new TemplateField(); tfAction.ItemTemplate = new NopGridViewCustomTemplate(DataControlRowType.DataRow, "CustomerActionName", "String"); tfAction.HeaderTemplate = new NopGridViewCustomTemplate(DataControlRowType.Header, GetLocaleResourceString("Admin.ACL.Grid.CustomerAction"), "String"); gvACL.Columns.Add(tfAction); CustomerRoleCollection roles = CustomerManager.GetAllCustomerRoles(); foreach (CustomerRole cr in roles) { TemplateField tf = new TemplateField(); tf.ItemTemplate = new NopGridViewCustomTemplate(DataControlRowType.DataRow, "Allow", "Checkbox", cr.CustomerRoleId); tf.HeaderTemplate = new NopGridViewCustomTemplate(DataControlRowType.Header, cr.Name, "String"); gvACL.Columns.Add(tf); } }
private void BindData() { Discount discount = DiscountManager.GetDiscountById(this.DiscountId); if (discount != null) { CommonHelper.SelectListItem(this.ddlDiscountType, discount.DiscountTypeId); CommonHelper.SelectListItem(this.ddlDiscountRequirement, discount.DiscountRequirementId); this.txtRestrictedProductVariants.Text = GenerateListOfRestrictedProductVariants(ProductManager.GetProductVariantsRestrictedByDiscountId(discount.DiscountId)); CommonHelper.SelectListItem(this.ddlDiscountLimitation, discount.DiscountLimitationId); this.txtName.Text = discount.Name; this.cbUsePercentage.Checked = discount.UsePercentage; this.txtDiscountPercentage.Value = discount.DiscountPercentage; this.txtDiscountAmount.Value = discount.DiscountAmount; this.ctrlStartDatePicker.SelectedDate = discount.StartDate; this.ctrlEndDatePicker.SelectedDate = discount.EndDate; this.cbRequiresCouponCode.Checked = discount.RequiresCouponCode; this.txtCouponCode.Text = discount.CouponCode; CustomerRoleCollection customerRoles = discount.CustomerRoles; List <int> _customerRoleIds = new List <int>(); foreach (CustomerRole customerRole in customerRoles) { _customerRoleIds.Add(customerRole.CustomerRoleId); } CustomerRoleMappingControl.SelectedCustomerRoleIds = _customerRoleIds; CustomerRoleMappingControl.BindData(); } else { List <int> _customerRoleIds = new List <int>(); CustomerRoleMappingControl.SelectedCustomerRoleIds = _customerRoleIds; CustomerRoleMappingControl.BindData(); this.pnlUsageHistory.Visible = false; } }
/// <summary> /// Checks requirements for customer /// </summary> /// <param name="customer">Customer</param> /// <returns>Value indicating whether all requirements are met</returns> public bool CheckDiscountRequirements(Customer customer) { switch (this.DiscountRequirement) { case DiscountRequirementEnum.None: { return(true); } break; case DiscountRequirementEnum.MustBeAssignedToCustomerRole: { if (customer != null) { CustomerRoleCollection customerRoles = customer.CustomerRoles; CustomerRoleCollection assignedRoles = this.CustomerRoles; foreach (CustomerRole _customerRole in customerRoles) { foreach (CustomerRole _assignedRole in assignedRoles) { if (_customerRole.Name == _assignedRole.Name) { return(true); } } } } } break; case DiscountRequirementEnum.HadPurchasedAllOfTheseProductVariants: { if (customer != null) { ProductVariantCollection restrictedProductVariants = ProductManager.GetProductVariantsRestrictedByDiscountId(this.DiscountId); OrderProductVariantCollection purchasedProductVariants = OrderManager.GetAllOrderProductVariants(null, customer.CustomerId, null, null, OrderStatusEnum.Complete, null, null); bool allFound = true; foreach (ProductVariant restrictedPV in restrictedProductVariants) { bool found1 = false; foreach (OrderProductVariant purchasedPV in purchasedProductVariants) { if (restrictedPV.ProductVariantId == purchasedPV.ProductVariantId) { found1 = true; break; } } if (!found1) { allFound = false; break; } } if (allFound) { return(true); } } } break; case DiscountRequirementEnum.HadPurchasedOneOfTheseProductVariants: { if (customer != null) { ProductVariantCollection restrictedProductVariants = ProductManager.GetProductVariantsRestrictedByDiscountId(this.DiscountId); OrderProductVariantCollection purchasedProductVariants = OrderManager.GetAllOrderProductVariants(null, customer.CustomerId, null, null, OrderStatusEnum.Complete, null, null); bool found = false; foreach (ProductVariant restrictedPV in restrictedProductVariants) { foreach (OrderProductVariant purchasedPV in purchasedProductVariants) { if (restrictedPV.ProductVariantId == purchasedPV.ProductVariantId) { found = true; break; } } if (found) { break; } } if (found) { return(true); } } } break; default: break; } return(false); }