/// <summary> /// Page Pre-Initialization Event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_PreInit(object sender, EventArgs e) { // Default master page file path string masterPageFilePath = "~/themes/" + ZNode.Libraries.Framework.Business.ZNodeConfigManager.SiteConfig.Theme + "/product/Product.master"; // Get product id from querystring if (Request.Params["zpid"] != null) { _productId = int.Parse(Request.Params["zpid"]); } else { throw (new ApplicationException("Invalid Product Id")); } // Retrieve product data _product = ZNodeProduct.Create(_productId, ZNodeConfigManager.SiteConfig.PortalID); if (_product != null) { if (_product.MasterPage.Length > 0 && _product.MasterPage != "Default") { string masterFilePath = ZNodeConfigManager.EnvironmentConfig.DataPath + "MasterPages/product/" + _product.MasterPage + ".master"; if (System.IO.File.Exists(Server.MapPath(masterFilePath))) { // If template master page exists, then override default master page masterPageFilePath = masterFilePath; } } } else { Response.Redirect("~/default.aspx"); } // Set master page this.MasterPageFile = masterPageFilePath; // Add to http context so it can be shared with user controls HttpContext.Current.Items.Add("Product", _product); // Set SEO Properties ZNodeSEO seo = new ZNodeSEO(); // Set SEO default values to the product ZNodeMetaTags tags = new ZNodeMetaTags(); seo.SEOTitle = tags.ProductTitle(_product); seo.SEODescription = tags.ProductDescription(_product); seo.SEOKeywords = tags.ProductKeywords(_product); }
/// <summary> /// Page Pre-Initialization Event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_PreInit(object sender, EventArgs e) { this.MasterPageFile = "~/themes/" + ZNode.Libraries.Framework.Business.ZNodeConfigManager.SiteConfig.Theme + "/emailfriend/emailfriend.master"; //get product id from querystring if (Request.Params["zpid"] != null) { _productId = int.Parse(Request.Params["zpid"]); } else { throw (new ApplicationException("Invalid Product Id")); } //retrieve product data _product = ZNodeProduct.Create(_productId, ZNodeConfigManager.SiteConfig.PortalID); //add to http context so it can be shared with user controls HttpContext.Current.Items.Add("Product", _product); }
/// <summary> /// Bind edit data /// </summary> public void Bind() { _product = Product; if (_product.ProductID > 0) { BindQuantityList(); DisplayPrice(); tablerow.Visible = true; } else { ResetUI(); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void uxGrid_SelectedIndexChanged(object sender, EventArgs e) { // Retrieve Product Id Label lblId = uxGrid.Rows[uxGrid.SelectedIndex].FindControl("ui_CustomerIdSelect") as Label; if (lblId.Text != "0") { int productId = 0; int.TryParse(lblId.Text, out productId); if (productId > 0) { pnlProductDetails.Visible = true; pnlProductList.Visible = false; uxGrid.DataSource = null; uxGrid.DataBind(); uxGrid.Dispose(); // Clear resources int quantity = 1; int.TryParse(Qty.SelectedValue, out quantity); if (Product.ProductID != productId) { // Get a product object using create static method _product = ZNodeProduct.Create(productId, ZNodeConfigManager.SiteConfig.PortalID); quantity = 1; Product = _product; } else { _product = Product; } Quantity = quantity; CatalogItemImage.ImageUrl = _product.MediumImageFilePath; CatalogItemImage.Visible = ShowCatalogImage(_product.MediumImageFilePath); ProductDescription.Text = _product.Description; BindAddOnsAttributes(); if (_product.ZNodeAddOnCollection.Count > 0) { ValidateAddOns(sender, e); } else { Bind(); } if (_product.ZNodeAttributeTypeCollection.Count == 0) { //Enable stock validator EnableStockValidator(_product); } else { ValidateAttributes(sender, e); } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SelectorList_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (sender) as DropDownList; if (list.SelectedValue != "0") { int productId = int.Parse(list.SelectedValue); int quantity = 0; if (!int.TryParse(Qty.Text.Trim(), out quantity)) { quantity = 1; } if (Product.ProductID != productId) { //Get a product object using create static method _product = ZNodeProduct.Create(productId, ZNodeConfigManager.SiteConfig.PortalID); Product = _product; } else { _product = Product; } CatalogItemImage.ImageUrl = _product.MediumImageFilePath; CatalogItemImage.Visible = ShowCatalogImage(_product.MediumImageFilePath); ProductDescription.Text = _product.Description; BindAddOnsAttributes(); if (_product.ZNodeAddOnCollection.Count > 0) { ValidateAddOns(sender, e); } else { Bind(); } if (_product.ZNodeAttributeTypeCollection.Count == 0) { //Enable stock validator EnableStockValidator(_product); } else { ValidateAttributes(sender, e); } } else { Product = new ZNodeProduct(); Bind(); } }
/// <summary> /// Returns boolean value to enable Validator to check against the Quantity textbox /// It checks for AllowBackOrder and TrackInventory settings for this product,and returns the value /// </summary> /// <param name="Value"></param> /// <returns></returns> protected void EnableStockValidator(ZNodeProduct product) { _product = product; if (_product.ProductID > 0) { //Allow Back Order if (_product.AllowBackOrder && _product.TrackInventoryInd) { QuantityRangeValidator.Enabled = false; return; } // Don't track inventory else if ((!_product.AllowBackOrder) && (!_product.TrackInventoryInd)) { QuantityRangeValidator.Enabled = false; return; } // Enable validator CheckInventory(); QuantityRangeValidator.Enabled = true; } else { QuantityRangeValidator.Enabled = false; } }
/// <summary> /// /// </summary> protected void DisplayProductGrid(ZNodeProduct product) { if (product.ProductID > 0) { string[] attributeValues = product.SelectedSKU.AttributesValue.Split(new char[] { ',' }); if (attributeValues.Length > 1) { uxProductAttributeGrid.ShowInventoryLevels = true; uxProductAttributeGrid.ShowFooter = false; int attributeId = int.Parse(attributeValues[0]); uxProductAttributeGrid.AttributeId = attributeId; uxProductAttributeGrid.ProductTypeID = product.ProductTypeID; uxProductAttributeGrid.ProductID = product.ProductID; uxProductAttributeGrid.Bind(); uxProductAttributeGrid.Visible = true; string _imagePath = ZNodeConfigManager.EnvironmentConfig.MediumImagePath + uxProductAttributeGrid.Path; if (ShowCatalogImage(_imagePath)) { CatalogItemImage.ImageUrl = _imagePath; } else { CatalogItemImage.ImageUrl = _product.MediumImageFilePath; } ProductDescription.Text = _product.Description; } else { uxProductAttributeGrid.Visible = false; } } }
/// <summary> /// Returns Quantity on Hand (inventory stock value) /// </summary> /// <param name="Value"></param> /// <returns></returns> protected void CheckInventory() { _product = Product; if (_product.ProductID > 0) { QuantityRangeValidator.MaximumValue = _product.QuantityOnHand.ToString(); int CurrentQuantity = _product.QuantityOnHand; //Retreive shopping cart object from current session shoppingCart = ZNodeShoppingCart.CurrentShoppingCart(); if (shoppingCart != null) { ZNodeShoppingCartItem Item = new ZNodeShoppingCartItem(); Item.Product = _product; //Get Current Qunatity by Subtracting QunatityOrdered from Quantity On Hand(Inventory) CurrentQuantity -= shoppingCart.GetQuantityOrdered(Item); } if (CurrentQuantity <= 0) { CurrentQuantity = 0; } QuantityRangeValidator.MaximumValue = CurrentQuantity.ToString(); } else { QuantityRangeValidator.MaximumValue = "1"; } }
/// <summary> /// Creates attribute drop downlist controls dynamically for a product /// </summary> /// <param name="productId"></param> /// <param name="rowNum"></param> /// <param name="UpdateInd"></param> protected void BindAddOnsAttributes() { _product = Product; if (_product.ProductID > 0) { //Remove existing dynamic controls from the control place holder object ControlPlaceHolder.Controls.Clear(); //Find the placeholder control and Add the literal control to the Controls collection // of the PlaceHolder control. Literal literal = new Literal(); literal.Text = "<div class='Attributes'>"; ControlPlaceHolder.Controls.Add(literal); int counter = 0; # region Create list control for each product Attribute // if (_product.ZNodeAttributeTypeCollection.Count > 0) { foreach (ZNodeAttributeType AttributeType in _product.ZNodeAttributeTypeCollection) { System.Web.UI.WebControls.DropDownList lstControl = new DropDownList(); lstControl.ID = "lstAttribute" + AttributeType.AttributeTypeId.ToString(); lstControl.Attributes.Add("class", "ValueStyle"); lstControl.AutoPostBack = true; lstControl.SelectedIndexChanged += new System.EventHandler(ValidateAttributes); foreach (ZNodeAttribute Attribute in AttributeType.ZNodeAttributeCollection) { ListItem li1 = new ListItem(Attribute.Name, Attribute.AttributeId.ToString()); lstControl.Items.Add(li1); } string attributeValues = _product.SelectedSKU.AttributesValue; string[] attributes = new string[_product.ZNodeAttributeTypeCollection.Count]; if (attributeValues.Length > 0) { attributes = attributeValues.Split(new Char[] { ',' }, StringSplitOptions.None); } if (lstControl.Items.Count > 0) { if (attributes != null) lstControl.SelectedValue = attributes[counter++]; } // Add the Attribute dropdownlist control to the Controls collection // of the PlaceHolder control. ControlPlaceHolder.Controls.Add(lstControl); Literal ltrlSpacer = new Literal(); ltrlSpacer.Text = "<br />"; ControlPlaceHolder.Controls.Add(ltrlSpacer); } } # endregion # region Create list control for each product AddOns string addonValues = _product.SelectedAddOnItems.SelectedAddOnValues; string[] addonValueId = new string[_product.ZNodeAddOnCollection.Count]; if (addonValues.Length > 0) { addonValueId = addonValues.Split(new string[] { "," }, StringSplitOptions.None); } if (_product.ZNodeAddOnCollection.Count > 0) { foreach (ZNodeAddOn AddOn in _product.ZNodeAddOnCollection) { System.Web.UI.WebControls.DropDownList lstControl = new DropDownList(); lstControl.ID = "lstAddOn" + AddOn.AddOnID.ToString(); lstControl.AutoPostBack = true; lstControl.SelectedIndexChanged += new System.EventHandler(ValidateAddOns); lstControl.Attributes.Add("class", "ValueStyle"); //Don't display list box if there is no add-on values for AddOns if (AddOn.ZNodeAddOnValueCollection.Count > 0) { foreach (ZNodeAddOnValue AddOnValue in AddOn.ZNodeAddOnValueCollection) { string AddOnValueName = AddOnValue.Name; decimal decRetailPrice = AddOnValue.FinalPrice; if (decRetailPrice < 0) { //Price format string priceformat = "-" + ZNodeCurrencyManager.GetCurrencyPrefix() + "{0:0.00}" + ZNodeCurrencyManager.GetCurrencySuffix(); AddOnValueName += " : " + String.Format(priceformat, System.Math.Abs(decRetailPrice)) + ZNode.Libraries.ECommerce.Catalog.ZNodeCurrencyManager.GetCurrencySuffix(); } else if (decRetailPrice > 0) { AddOnValueName += " : " + decRetailPrice.ToString("c") + ZNode.Libraries.ECommerce.Catalog.ZNodeCurrencyManager.GetCurrencySuffix(); } //Added Inventory Message with the Addon Value Name in the dropdownlist AddOnValueName += " " + BindStatusMsg(AddOn, AddOnValue); ListItem li1 = new ListItem(AddOnValueName, AddOnValue.AddOnValueID.ToString()); lstControl.Items.Add(li1); if (AddOnValue.IsDefault) { lstControl.SelectedValue = AddOnValue.AddOnValueID.ToString(); } } //Check for Optional if (AddOn.OptionalInd) { ListItem OptionalItem = new ListItem("Optional", "-1"); lstControl.Items.Insert(0, OptionalItem); lstControl.SelectedValue = "-1"; } //Pre-select previous selected addon values in the list for (int i = 0; i < addonValueId.Length; i++) { if (addonValueId[i] != null) { lstControl.SelectedValue = addonValueId[i]; if (lstControl.SelectedValue == addonValueId[i]) { break; } } } ControlPlaceHolder.Controls.Add(lstControl); // Dropdown list control Literal literalSpacer = new Literal(); literalSpacer.Text = "<br />"; //Add controls to the place holder ControlPlaceHolder.Controls.Add(literalSpacer); } } } # endregion //Add the literal control to the Controls collection // of the PlaceHolder control. literal = new Literal(); literal.Text = "</div>"; ControlPlaceHolder.Controls.Add(literal); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { // get product sku from querystring if (Request.Params["sku"] != null) { SKU = Request.Params["sku"]; } // get product num # from querystring if (Request.QueryString["product_num"] != null) { _productNum = Request.QueryString["product_num"]; } // get quantity from querystring if (Request.Params["quantity"] != null) { if (!int.TryParse(Request.Params["quantity"],out _quantity)) { _quantity = 1; } } if (SKU.Length == 0 && _productNum.Length == 0) { Response.Redirect("~/error.aspx"); return; } if (!Page.IsPostBack) { ZNodeSKU productSKU = new ZNodeSKU(); if (SKU.Length > 0) { productSKU = ZNodeSKU.CreateBySKU(SKU); if (productSKU.SKUID == 0) { ProductService productService = new ProductService(); ProductQuery filters = new ProductQuery(); filters.AppendEquals(ProductColumn.SKU, SKU); TList<Product> productList = productService.Find(filters.GetParameters()); if (productList != null) { if (productList.Count == 0) { // If SKUID or Invalid SKU is Zero then Redirected to default page Response.Redirect("~/error.aspx"); } } else { // If SKUID or Invalid SKU is Zero then Redirected to default page Response.Redirect("~/error.aspx"); } ProductID = productList[0].ProductID; _product = ZNodeProduct.Create(ProductID, ZNodeConfigManager.SiteConfig.PortalID); } else { // If SKU parameter is supplied & it has value ProductID = productSKU.ProductID; _product = ZNodeProduct.Create(ProductID, ZNodeConfigManager.SiteConfig.PortalID); // Set product SKU _product.SelectedSKU = productSKU; } } else if (_productNum.Length > 0) { ProductService productService = new ProductService(); ProductQuery filters = new ProductQuery(); filters.AppendEquals(ProductColumn.ProductNum, _productNum); TList<Product> productList = productService.Find(filters.GetParameters()); if (productList != null) { if (productList.Count == 0) { // If SKUID or Invalid SKU is Zero then Redirected to default page Response.Redirect("~/error.aspx"); } } else { // If SKUID or Invalid SKU is Zero then Redirected to default page Response.Redirect("~/error.aspx"); } ProductID = productList[0].ProductID; _product = ZNodeProduct.Create(ProductID, ZNodeConfigManager.SiteConfig.PortalID); } else { // If SKUID or Invalid SKU is Zero then Redirected to default page Response.Redirect("~/error.aspx"); } // Check product attributes count if (_product.ZNodeAttributeTypeCollection.Count > 0 && productSKU.SKUID == 0) { Response.Redirect(_product.ViewProductLink); } // Loop through the product addons foreach (ZNodeAddOn _addOn in _product.ZNodeAddOnCollection) { if (!_addOn.OptionalInd) { Response.Redirect(_product.ViewProductLink); } } // Create shopping cart item ZNodeShoppingCartItem item = new ZNodeShoppingCartItem(); item.Product = new ZNodeProductBase(_product); item.Quantity = _quantity; // Add product to cart ZNodeShoppingCart shoppingCart = ZNodeShoppingCart.CurrentShoppingCart(); // If shopping cart is null, create in session if (shoppingCart == null) { shoppingCart = new ZNodeShoppingCart(); shoppingCart.AddToSession(ZNodeSessionKeyType.ShoppingCart); } // add item to cart if (shoppingCart.AddToCart(item)) { string link = "~/shoppingcart.aspx"; Response.Redirect(link); } else { // If Product is out of Stock - Redirected to Product Details page Response.Redirect("~/error.aspx"); } } }