/// <summary> /// Fetches the associated attributes by product id. /// </summary> /// <param name="productId">The product id.</param> /// <returns></returns> public AssociatedAttributeCollection FetchAssociatedAttributesByProductId(int productId) { IDataReader reader = SPs.FetchAssociatedAttributesByProductId(productId).GetReader(); AssociatedAttributeCollection associatedAttributeCollection = new AssociatedAttributeCollection(); associatedAttributeCollection.Load(reader); reader.Close(); reader.Dispose(); return associatedAttributeCollection; }
/// <summary> /// Handles the Click event of the btnPostSimilar control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void btnCopy_Click(object sender, EventArgs e) { this.btnSave_Click(null, EventArgs.Empty); //Save any changes first Product newProduct = new Product(); newProduct.ProductGuid = Guid.NewGuid(); newProduct.BaseSku = string.Empty; newProduct.Name = product.Name = txtName.Text.Trim() + " - Copy"; newProduct.ShortDescription = product.ShortDescription; newProduct.OurPrice = product.OurPrice; newProduct.RetailPrice = product.RetailPrice; newProduct.ManufacturerId = product.ManufacturerId; newProduct.ProductStatusDescriptorId = product.ProductStatusDescriptorId; newProduct.ProductTypeId = product.ProductTypeId; newProduct.TaxRateId = product.TaxRateId; newProduct.ShippingEstimateId = product.ShippingEstimateId; newProduct.Weight = product.Weight; newProduct.Length = product.Length; newProduct.Height = product.Height; newProduct.Width = product.Width; newProduct.TotalRatingVotes = product.TotalRatingVotes; newProduct.RatingSum = product.RatingSum; newProduct.Save(WebUtility.GetUserName()); if (newProduct.ProductId > 0) { foreach (Category cat in product.GetCategoryCollection()) { ProductCategoryMap map = new ProductCategoryMap(); map.CategoryId = cat.CategoryId; map.ProductId = newProduct.ProductId; map.Save(WebUtility.GetUserName()); Store.Caching.ProductCache.RemoveProductsByCategoryIdFromCache(cat.CategoryId); } AssociatedAttributeCollection productAttributes = Store.Caching.ProductCache.GetAssociatedAttributeCollectionByProduct(product.ProductId); foreach (AssociatedAttribute at in productAttributes) { int sortOrder = 0; ProductAttributeMap map = new ProductAttributeMap(); map.AttributeId = at.AttributeId; map.ProductId = newProduct.ProductId; map.SortOrder = sortOrder++; map.IsRequired = at.IsRequired; map.Save(WebUtility.GetUserName()); } Response.Redirect(string.Format("~/admin/productedit.aspx?view=g&productId={0}", newProduct.ProductId.ToString()), false); } else { base.MasterPage.MessageCenter.DisplayFailureMessage(LocalizationUtility.GetText("lblProductNotSaved")); } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { try { productId = Utility.GetIntParameter("productId"); view = Utility.GetParameter("view"); if (view.Equals("s")) { SetSkuProperties(); product = new Product(productId); associatedAttributeCollection = new ProductController().FetchAssociatedAttributesByProductId(productId); if (!Page.IsPostBack) { chkAllowNegativeInventories.Checked = product.AllowNegativeInventories; SkuCollection skuCollection = LoadSkuCollection(productId); if (skuCollection.Count > 0) { pnlSkuList.Visible = false; } else { pnlSkuInventory.Visible = false; string tempSku = product.BaseSku; if (associatedAttributeCollection.Count > 0) { CreateSkus(associatedAttributeCollection[0], 0, tempSku); lblTotalSkuCount.Text = skus.Count.ToString(); } else { skus.Add(tempSku); lblTotalSkuCount.Text = skus.Count.ToString(); } skus.TrimExcess(); dlSkus.DataSource = skus; dlSkus.DataBind(); } } } } catch (Exception ex) { Logger.Error(typeof(sku).Name + ".Page_Load", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { if (_product != null) { associatedAttributeCollection = Store.Caching.ProductCache.GetAssociatedAttributeCollectionByProduct(_product.ProductId); if (associatedAttributeCollection.Count > 0) { Label lblAttributeName; TextBox textBox; AttributeItemCollection attributeItemCollection; foreach (AssociatedAttribute associatedAttribute in associatedAttributeCollection) { lblAttributeName = new Label(); lblAttributeName.CssClass = "attributeLabel"; lblAttributeName.Text = associatedAttribute.Label; pnlProductAttributes.Controls.Add(lblAttributeName); pnlProductAttributes.Controls.Add(new LiteralControl(" ")); Label label = new Label(); label.ID = associatedAttribute.Name; label.CssClass = "attribute"; ThisPage.UpdatePanel.ContentTemplateContainer.Controls.Add(label); AsyncPostBackTrigger trigger = new AsyncPostBackTrigger(); trigger.ControlID = associatedAttribute.Name; trigger.EventName = "OnSelectedIndexChanged"; ThisPage.UpdatePanel.Triggers.Add(trigger); switch (associatedAttribute.AttributeTypeId) { case 1:// Single Select List DropDownList dropDownList = new DropDownList(); dropDownList.ID = associatedAttribute.Name; dropDownList.CssClass = "attributeDropdownList"; attributeItemCollection = associatedAttribute.AttributeItemCollection; attributeItemCollection.Sort("SortOrder", true); dropDownList.DataSource = attributeItemCollection; dropDownList.DataTextField = "FormattedAmount"; dropDownList.DataValueField = "SkuSuffix"; dropDownList.DataBind(); dropDownList.SelectedIndexChanged += new EventHandler(dropDownList_SelectedIndexChanged); dropDownList.AutoPostBack = true; dropDownList.Items.Insert(0, new ListItem(LocalizationUtility.GetText("lblSelect"), string.Empty)); //CMC: ?? Sku's are not made up of just BaseSku + 1 attribute, it's the combination of //BaseSku and ALL attributes. //foreach (AttributeItem item in associatedAttribute.AttributeItemCollection) { // if (!_product.AllowNegativeInventories) { // Sku sku = ProductCache.GetSKU(_product.BaseSku + "-" + item.SkuSuffix); // if (sku.SkuId > 0 && sku.Inventory > 0) // dropDownList.Items.Add(new ListItem(item.FormattedAmount, item.SkuSuffix)); // } // else // dropDownList.Items.Add(new ListItem(item.FormattedAmount, item.SkuSuffix)); //} if (associatedAttribute.IsRequired) { RequiredFieldValidator rfv = new RequiredFieldValidator(); rfv.ControlToValidate = dropDownList.ID; rfv.Display = ValidatorDisplay.None; rfv.ErrorMessage = string.Format(LocalizationUtility.GetText("lblPleaseSelect"), associatedAttribute.Name); pnlProductAttributes.Controls.Add(rfv); } pnlProductAttributes.Controls.Add(dropDownList); break; case 2: //Singleline Input textBox = new TextBox(); textBox.ID = associatedAttribute.AttributeItemCollection[0].SkuSuffix; textBox.TextMode = TextBoxMode.SingleLine; textBox.CssClass = "textbox"; if (associatedAttribute.IsRequired) { RequiredFieldValidator rfv = new RequiredFieldValidator(); rfv.ControlToValidate = textBox.ID; rfv.Display = ValidatorDisplay.None; rfv.ErrorMessage = string.Format(LocalizationUtility.GetText("lblPleaseSupply"), associatedAttribute.Name); pnlProductAttributes.Controls.Add(rfv); } pnlProductAttributes.Controls.Add(textBox); break; case 3: //Multiline Input textBox = new TextBox(); textBox.ID = associatedAttribute.AttributeItemCollection[0].SkuSuffix; textBox.TextMode = TextBoxMode.MultiLine; textBox.CssClass = "multilinetextbox"; if (associatedAttribute.IsRequired) { RequiredFieldValidator rfv = new RequiredFieldValidator(); rfv.ControlToValidate = textBox.ID; rfv.Display = ValidatorDisplay.None; rfv.ErrorMessage = string.Format(LocalizationUtility.GetText("lblPleaseSupply"), associatedAttribute.Name); pnlProductAttributes.Controls.Add(rfv); } pnlProductAttributes.Controls.Add(textBox); break; } pnlProductAttributes.Controls.Add(new LiteralControl("<br/>")); } } else { if (!Page.IsPostBack) { GetInventory(_product.BaseSku); } } } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { if (_product != null) { associatedAttributeCollection = Store.Caching.ProductCache.GetAssociatedAttributeCollectionByProduct(_product.ProductId); if (associatedAttributeCollection.Count > 0) { Label lblAttributeName; TextBox textBox; AttributeItemCollection attributeItemCollection; foreach (AssociatedAttribute associatedAttribute in associatedAttributeCollection) { lblAttributeName = new Label(); lblAttributeName.CssClass = "attributeLabel"; lblAttributeName.Text = associatedAttribute.Label; pnlProductAttributes.Controls.Add(lblAttributeName); pnlProductAttributes.Controls.Add(new LiteralControl(" ")); Label label = new Label(); label.ID = associatedAttribute.Name; label.CssClass = "attribute"; ThisPage.UpdatePanel.ContentTemplateContainer.Controls.Add(label); AsyncPostBackTrigger trigger = new AsyncPostBackTrigger(); trigger.ControlID = associatedAttribute.Name; trigger.EventName = "OnSelectedIndexChanged"; ThisPage.UpdatePanel.Triggers.Add(trigger); switch (associatedAttribute.AttributeTypeId) { case 1:// Single Select List DropDownList dropDownList = new DropDownList(); dropDownList.ID = associatedAttribute.Name; dropDownList.CssClass = "attributeDropdownList"; attributeItemCollection = associatedAttribute.AttributeItemCollection; attributeItemCollection.Sort("SortOrder", true); dropDownList.DataSource = attributeItemCollection; dropDownList.DataTextField = "FormattedAmount"; dropDownList.DataValueField = "SkuSuffix"; dropDownList.DataBind(); dropDownList.SelectedIndexChanged += new EventHandler(dropDownList_SelectedIndexChanged); dropDownList.AutoPostBack = true; dropDownList.Items.Insert(0, new ListItem(LocalizationUtility.GetText("lblSelect"), string.Empty)); //CMC: ?? Sku's are not made up of just BaseSku + 1 attribute, it's the combination of //BaseSku and ALL attributes. //foreach (AttributeItem item in associatedAttribute.AttributeItemCollection) { // if (!_product.AllowNegativeInventories) { // Sku sku = ProductCache.GetSKU(_product.BaseSku + "-" + item.SkuSuffix); // if (sku.SkuId > 0 && sku.Inventory > 0) // dropDownList.Items.Add(new ListItem(item.FormattedAmount, item.SkuSuffix)); // } // else // dropDownList.Items.Add(new ListItem(item.FormattedAmount, item.SkuSuffix)); //} if (associatedAttribute.IsRequired) { RequiredFieldValidator rfv = new RequiredFieldValidator(); rfv.ControlToValidate = dropDownList.ID; rfv.Display = ValidatorDisplay.None; rfv.ErrorMessage = string.Format(LocalizationUtility.GetText("lblPleaseSelect"), associatedAttribute.Name); pnlProductAttributes.Controls.Add(rfv); } pnlProductAttributes.Controls.Add(dropDownList); break; case 2: //Singleline Input textBox = new TextBox(); textBox.ID = associatedAttribute.AttributeItemCollection[0].SkuSuffix; textBox.TextMode = TextBoxMode.SingleLine; textBox.CssClass = "textbox"; if (associatedAttribute.IsRequired) { RequiredFieldValidator rfv = new RequiredFieldValidator(); rfv.ControlToValidate = textBox.ID; rfv.Display = ValidatorDisplay.None; rfv.ErrorMessage = string.Format(LocalizationUtility.GetText("lblPleaseSupply"), associatedAttribute.Name); pnlProductAttributes.Controls.Add(rfv); } pnlProductAttributes.Controls.Add(textBox); break; case 3: //Multiline Input textBox = new TextBox(); textBox.ID = associatedAttribute.AttributeItemCollection[0].SkuSuffix; textBox.TextMode = TextBoxMode.MultiLine; textBox.CssClass = "multilinetextbox"; if (associatedAttribute.IsRequired) { RequiredFieldValidator rfv = new RequiredFieldValidator(); rfv.ControlToValidate = textBox.ID; rfv.Display = ValidatorDisplay.None; rfv.ErrorMessage = string.Format(LocalizationUtility.GetText("lblPleaseSupply"), associatedAttribute.Name); pnlProductAttributes.Controls.Add(rfv); } pnlProductAttributes.Controls.Add(textBox); break; } pnlProductAttributes.Controls.Add(new LiteralControl("<br/>")); } } else { if (!Page.IsPostBack) { GetInventory(_product.BaseSku); } } } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { try { productId = Utility.GetIntParameter("productId"); view = Utility.GetParameter("view"); if (view.Equals("s")) { SetSkuProperties(); product = new Product(productId); associatedAttributeCollection = new ProductController().FetchAssociatedAttributesByProductId(productId); if(!Page.IsPostBack) { chkAllowNegativeInventories.Checked = product.AllowNegativeInventories; SkuCollection skuCollection = LoadSkuCollection(productId); if (skuCollection.Count > 0) { pnlSkuList.Visible = false; } else { pnlSkuInventory.Visible = false; string tempSku = product.BaseSku; if (associatedAttributeCollection.Count > 0) { CreateSkus(associatedAttributeCollection[0], 0, tempSku); lblTotalSkuCount.Text = skus.Count.ToString(); } else { skus.Add(tempSku); lblTotalSkuCount.Text = skus.Count.ToString(); } skus.TrimExcess(); dlSkus.DataSource = skus; dlSkus.DataBind(); } } } } catch (Exception ex) { Logger.Error(typeof(sku).Name + ".Page_Load", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }