protected void AddComponentSaveButton_Click(object sender, EventArgs e) { if (_Kit == null) { // WE MUST HAVE KIT TO HAVE KIT COMPONENTS _Kit = new Kit(_Product, false); _Kit.Save(); } // CREATE THE KIT COMPONENT KitComponent component = new KitComponent(); component.Name = AddComponentName.Text; component.InputTypeId = (short)(AddComponentInputTypeId.SelectedIndex); //component.HeaderOption = HeaderOption.Text; component.Save(); // ASSOCIATE KIT COMPONENT TO THE PRODUCT _Product.ProductKitComponents.Add(new ProductKitComponent(_Product, component)); _Product.Save(); // RESET THE ADD COMPONENT DIALOG AddComponentName.Text = string.Empty; AddComponentInputTypeId.SelectedIndex = 1; }
protected void GetSelectedKitOptions(Product product) { _SelectedKitProducts = new List <int>(); //COLLECT ANY KIT VALUES foreach (ProductKitComponent pkc in product.ProductKitComponents) { // FIND THE CONTROL KitComponent component = pkc.KitComponent; if (component.InputType == KitInputType.IncludedHidden) { foreach (KitProduct choice in component.KitProducts) { _SelectedKitProducts.Add(choice.Id); } } else { System.Web.UI.WebControls.WebControl inputControl = (System.Web.UI.WebControls.WebControl)AbleCommerce.Code.PageHelper.RecursiveFindControl(phOptions, component.UniqueId); if (inputControl != null) { IList <int> kitProducts = component.GetControlValue(inputControl); foreach (int selectedKitProductId in kitProducts) { _SelectedKitProducts.Add(selectedKitProductId); } } } } }
protected void SearchResultsGrid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Attach")) { EnsureKit(); int index = AlwaysConvert.ToInt(e.CommandArgument); int kitComponentId = (int)SearchResultsGrid.DataKeys[index].Value; KitComponent kitComponent = KitComponentDataSource.Load(kitComponentId); if (kitComponent != null) { _Product.ProductKitComponents.Add(new ProductKitComponent(_Product, kitComponent)); _Product.Save(); CancelButton_Click(sender, e); } } else if (e.CommandName.Equals("Copy")) { EnsureKit(); int index = AlwaysConvert.ToInt(e.CommandArgument); int kitComponentId = (int)SearchResultsGrid.DataKeys[index].Value; KitComponent kitComponent = KitComponentDataSource.Load(kitComponentId); if (kitComponent != null) { // copy the component KitComponent branchedComponent = kitComponent.Copy(true); branchedComponent.Name = "Copy of " + kitComponent.Name; branchedComponent.Save(); // attach to the product _Product.ProductKitComponents.Add(new ProductKitComponent(_Product, branchedComponent)); _Product.Save(); CancelButton_Click(sender, e); } } }
protected void SaveButton_Click(object sender, EventArgs e) { //CREATE THE KIT COMPONENT KitComponent.Name = Name.Text; KitComponent.InputTypeId = (short)(InputTypeId.SelectedIndex); KitComponent.HeaderOption = HeaderOption.Text; KitComponent.Save(); Response.Redirect(string.Format("EditKit.aspx?CategoryId={0}&ProductId={1}", this.CategoryId, this.ProductId)); }
protected void Page_Init(object sender, EventArgs e) { //INITIALIZE VARIABLES _CategoryId = AbleCommerce.Code.PageHelper.GetCategoryId(); _Category = CategoryDataSource.Load(_CategoryId); _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]); _Product = ProductDataSource.Load(_ProductId); if (_Product == null) { Response.Redirect(AbleCommerce.Code.NavigationHelper.GetAdminUrl("Catalog/Browse.aspx?CategoryId=" + _CategoryId.ToString())); } _KitComponentId = AlwaysConvert.ToInt(Request.QueryString["KitComponentId"]); _KitComponent = KitComponentDataSource.Load(_KitComponentId); if (_KitComponent == null) { Response.Redirect("EditKit.aspx?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString()); } CancelLink.NavigateUrl += "?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString(); Caption.Text = string.Format(Caption.Text, _KitComponent.Name); InstructionText.Text = string.Format(InstructionText.Text, _KitComponent.Name, _Product.Name); int categoryCount = CategoryDataSource.CountAll(); StoreSettingsManager settings = AbleContext.Current.Store.Settings; _DisplayCategorySearch = settings.CategorySearchDisplayLimit > 0 && categoryCount >= settings.CategorySearchDisplayLimit; // INITIALIZE DROP DOWN LISTS if (!_DisplayCategorySearch) { InitializeCategoryTree(); } else { // DISPLAY AUTO COMPLETE FOR CATEGORY SEARCH OPTION string js = PageHelper.GetAutoCompleteScript(Page.ResolveClientUrl("~/CategorySuggest.ashx"), CategoryAutoComplete, HiddenSelectedCategoryId, "Key", "Value"); ScriptManager.RegisterStartupScript(PageAjax, this.GetType(), "CATEGORY_SUGGEST", js, true); CategoryAutoComplete.Visible = true; CategoryFilter.Visible = false; } ManufacturerFilter.DataSource = ManufacturerDataSource.LoadAll("Name"); ManufacturerFilter.DataBind(); VendorFilter.DataSource = VendorDataSource.LoadAll("Name"); VendorFilter.DataBind(); // LOAD CUSTOM VIEWSTATE VARIABLES LoadCustomViewState(); if (_SelectedProducts.Count > 0) { // REBIND THE REPEATER BindSelectedProducts(_SelectedProducts); } AbleCommerce.Code.PageHelper.SetDefaultButton(NameFilter, SearchButton.ClientID); AbleCommerce.Code.PageHelper.SetDefaultButton(SkuFilter, SearchButton.ClientID); }
private static List <int> GetKitProductIds(KitComponent comp) { List <int> optionIds = new List <int>(); foreach (KitProduct choice in comp.KitProducts) { optionIds.Add(choice.Id); } return(optionIds); }
protected void ComponentList_ItemCommand(object source, RepeaterCommandEventArgs e) { int kitComponentId = AlwaysConvert.ToInt(e.CommandArgument); KitComponent kitComponent = KitComponentDataSource.Load(kitComponentId); if (kitComponent != null) { switch (e.CommandName) { case "Branch": // locate the product relationship ProductKitComponent pkc = _Product.ProductKitComponents.FirstOrDefault(x => x.KitComponentId == kitComponent.Id); if (pkc != null) { // create a copy of the component KitComponent branchedComponent = kitComponent.Copy(true); branchedComponent.Save(); // update the product relationship _Product.ProductKitComponents.Add(new ProductKitComponent(_Product, branchedComponent, pkc.OrderBy)); _Product.ProductKitComponents.DeleteAt(_Product.ProductKitComponents.IndexOf(pkc)); _Product.Save(); } break; case "Delete": AbleContext.Current.Database.BeginTransaction(); ProductKitComponent matchingComponent = _Product.ProductKitComponents.FirstOrDefault(x => x.KitComponentId == kitComponentId); if (matchingComponent != null) { int index = _Product.ProductKitComponents.IndexOf(matchingComponent); if (index > -1) { _Product.ProductKitComponents.RemoveAt(index); _Product.Save(); } } kitComponent.Delete(); // DELETE THE KIT RECORD IF NO COMPONENTS REMAINING if (_Product.ProductKitComponents.Count == 0) { Kit kit = _Product.Kit; _Product.Kit = null; _Product.Save(); kit.Delete(); } AbleContext.Current.Database.CommitTransaction(); ComponentList.DataBind(); break; } } }
protected void Page_Init(object sender, EventArgs e) { //INITIALIZE VARIABLES _CategoryId = AbleCommerce.Code.PageHelper.GetCategoryId(); _Category = CategoryDataSource.Load(_CategoryId); _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]); _Product = ProductDataSource.Load(_ProductId); if (_Product == null) Response.Redirect(AbleCommerce.Code.NavigationHelper.GetAdminUrl("Catalog/Browse.aspx")); _KitComponentId = AlwaysConvert.ToInt(Request.QueryString["KitComponentId"]); _KitComponent = KitComponentDataSource.Load(_KitComponentId); if (_KitComponent == null) Response.Redirect("EditKit.aspx?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString()); //INITIALIZE PAGE ELEMENTS Caption.Text = string.Format(Caption.Text, _KitComponent.Name); BindKitList(); }
public static bool RequiredKitOptionsSelected(Product product, List <int> selectedKitProductIds) { if (product.KitStatus != KitStatus.Master) { return(true); } Dictionary <int, List <int> > requiredIdsTable = new Dictionary <int, List <int> >(); foreach (ProductKitComponent pkc in product.ProductKitComponents) { KitComponent component = pkc.KitComponent; if (string.IsNullOrEmpty(component.HeaderOption) && (component.InputType == KitInputType.DropDown || component.InputType == KitInputType.RadioButton)) { requiredIdsTable.Add(component.Id, GetKitProductIds(component)); } } bool optionsSelected = true; foreach (int compId in requiredIdsTable.Keys) //for (int i = 0; i < requiredIdsTable.Count; i++) { List <int> optionIds = requiredIdsTable[compId]; //selected kipt option ids must have one of the option ids bool found = false; foreach (int optionId in optionIds) { if (selectedKitProductIds.Exists(delegate(int val) { return(val == optionId); })) { found = true; break; } } if (!found) { optionsSelected = false; break; } } return(optionsSelected); }
protected void MoveKitProduct(KitProduct kitProduct, int direction) { //MAKE SURE ALL KIT PRODUCTS ARE IN CORRECT ORDER short orderBy = -1; int index = -1; KitComponent kitComponent = kitProduct.KitComponent; foreach (KitProduct kp in kitComponent.KitProducts) { orderBy += 1; kp.OrderBy = orderBy; if (kp.Id.Equals(kitProduct.Id)) { index = orderBy; } } //LOCATE THE DESIRED ITEM if (index > -1) { KitProduct temp = null; if (direction < 0 && index > 0) { //MOVE UP temp = kitComponent.KitProducts[index]; temp.OrderBy -= 1; kitComponent.KitProducts[index] = kitComponent.KitProducts[index - 1]; kitComponent.KitProducts[index].OrderBy += 1; kitComponent.KitProducts[index - 1] = temp; kitComponent.KitProducts.Save(); } else if (direction > 0 && index < kitComponent.KitProducts.Count - 1) { //MOVEDOWN temp = kitComponent.KitProducts[index]; temp.OrderBy += 1; kitComponent.KitProducts[index] = kitComponent.KitProducts[index + 1]; kitComponent.KitProducts[index].OrderBy -= 1; kitComponent.KitProducts[index + 1] = temp; kitComponent.KitProducts.Save(); } } }
protected void Page_Init(object sender, EventArgs e) { //INITIALIZE VARIABLES _CategoryId = AbleCommerce.Code.PageHelper.GetCategoryId(); _Category = CategoryDataSource.Load(_CategoryId); _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]); _Product = ProductDataSource.Load(_ProductId); if (_Product == null) { Response.Redirect(AbleCommerce.Code.NavigationHelper.GetAdminUrl("Catalog/Browse.aspx")); } _KitProductId = AlwaysConvert.ToInt(Request.QueryString["KitProductId"]); _KitProduct = KitProductDataSource.Load(_KitProductId); if (_KitProduct == null) { Response.Redirect("EditKit.aspx?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString()); } _KitComponentId = _KitProduct.KitComponentId; _KitComponent = _KitProduct.KitComponent; //INITIALIZE PAGE ELEMENTS Caption.Text = string.Format(Caption.Text, _KitComponent.Name); KitName.Text = _Product.Name; KitComponentName.Text = _KitComponent.Name; SelectedProductName.Text = _KitProduct.Product.Name; DisplayName.Text = _KitProduct.Name; KitQuantity.Text = _KitProduct.Quantity.ToString(); ProductPrice.Text = _KitProduct.Product.Price.LSCurrencyFormat("lc"); PriceMode.SelectedIndex = (int)_KitProduct.PriceMode; PriceMode_SelectedIndexChanged(sender, e); Price.Text = string.Format("{0:F2}", _KitProduct.Price); ProductWeight.Text = string.Format("{0:F2}", _KitProduct.Product.Weight); WeightMode.SelectedIndex = (int)_KitProduct.WeightMode; WeightMode_SelectedIndexChanged(sender, e); Weight.Text = string.Format("{0:F2}", _KitProduct.Weight); phOptions.Controls.Clear(); selectedOptions = AbleCommerce.Code.ProductHelper.BuildProductOptions(_KitProduct, phOptions); IsSelected.Checked = _KitProduct.IsSelected; WeightUnit.Text = AbleContext.Current.Store.WeightUnit.ToString(); }
public static List <int> BuildKitOptions(Product product, PlaceHolder phOptions, bool ignoreInventory) { List <int> selectedChoices = new List <int>(); foreach (ProductKitComponent pkc in product.ProductKitComponents) { KitComponent component = pkc.KitComponent; if (component.InputType != KitInputType.IncludedHidden && component.KitProducts.Count > 0) { // CREATE A LABEL FOR THE ATTRIBUTE phOptions.Controls.Add(new LiteralControl("<tr><th class=\"rowHeader\">" + component.Name + ":</th>")); // ADD THE CONTROL TO THE PLACEHOLDER phOptions.Controls.Add(new LiteralControl("<td align=\"left\">")); WebControl o = component.GetControl(ignoreInventory); if (o != null) { Type oType = o.GetType(); if (oType.Equals(typeof(RadioButtonList))) { ((RadioButtonList)o).AutoPostBack = true; } else if (oType.Equals(typeof(DropDownList))) { ((DropDownList)o).AutoPostBack = true; } else if (oType.Equals(typeof(CheckBoxList))) { ((CheckBoxList)o).AutoPostBack = true; } phOptions.Controls.Add(o); // SEE WHETHER A VALID VALUE FOR THIS FIELD IS PRESENT IN FORM POST IList <int> theseOptions = component.GetControlValue(o); selectedChoices.AddRange(theseOptions); } phOptions.Controls.Add(new LiteralControl("</td></tr>")); } } return(selectedChoices); }
protected void Page_Load(object sender, EventArgs e) { _CategoryId = AbleCommerce.Code.PageHelper.GetCategoryId(); _Category = CategoryDataSource.Load(_CategoryId); _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]); _Product = ProductDataSource.Load(_ProductId); if (_Product == null) { Response.Redirect(AbleCommerce.Code.NavigationHelper.GetAdminUrl("Catalog/Browse.aspx")); } _KitComponentId = AlwaysConvert.ToInt(Request.QueryString["KitComponentId"]); _KitComponent = KitComponentDataSource.Load(_KitComponentId); if (_KitComponent == null) { Response.Redirect("Default.aspx?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString()); } Caption.Text = string.Format(Caption.Text, _KitComponent.Name); if (!Page.IsPostBack) { KitParts.DataSource = _KitComponent.KitProducts; KitParts.DataBind(); } }
protected void BindComponentList() { List <KitComponent> components = new List <KitComponent>(); foreach (ProductKitComponent pkc in _Product.ProductKitComponents) { KitComponent kc = pkc.KitComponent; if (kc != null) { kc.RemoveInvalidKitProducts(); components.Add(kc); } } if (components.Count > 0) { if (_Kit == null) { // WE MUST HAVE KIT TO BIND COMPONENTS _Kit = new Kit(_Product, false); _Kit.Save(); } ComponentList.DataSource = components; ComponentList.DataBind(); SortComponents.Visible = (components.Count > 1); PriceRange.Text = string.Format("{0} - {1}", _Kit.MinPrice.LSCurrencyFormat("lc"), _Kit.MaxPrice.LSCurrencyFormat("lc")); DefaultPrice.Text = _Kit.DefaultPrice.LSCurrencyFormat("lc"); WeightRange.Text = string.Format("{0:F2} - {1:F2}", _Kit.MinWeight, _Kit.MaxWeight); DefaultWeight.Text = string.Format("{0:F2}", _Kit.DefaultWeight); ExistingKitPanel.Visible = true; NewKitPanel.Visible = false; } else { ExistingKitPanel.Visible = false; NewKitPanel.Visible = true; } }
protected string GetDeleteSharedComponentLink(object dataItem) { KitComponent kc = (KitComponent)dataItem; return(string.Format("DeleteSharedComponent.aspx?CategoryId={0}&ProductId={1}&KitComponentId={2}", _CategoryId, _ProductId, kc.Id)); }