Imports BVSoftware.BVC.Core Imports System.Text Imports System.IO Imports System.Globalization Public Class productinfo1 Inherits BaseStorePage Protected WithEvents lblName As System.Web.UI.WebControls.Label Protected WithEvents inQty As System.Web.UI.WebControls.TextBox Protected WithEvents valQty As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents val2Qty As System.Web.UI.WebControls.RegularExpressionValidator Protected WithEvents valSummary As System.Web.UI.WebControls.ValidationSummary Protected WithEvents btnAddButton As System.Web.UI.WebControls.ImageButton Public sZoomImageHREF As String = "" Protected WithEvents MetaDescriptionControl As BVSoftware.WebControls.MetaTag Protected WithEvents MetaKeywordsControl As BVSoftware.WebControls.MetaTag Protected WithEvents WishListButton As System.Web.UI.WebControls.ImageButton Protected WithEvents MainImage As System.Web.UI.WebControls.Image Protected WithEvents lblSitePriceName As System.Web.UI.WebControls.Label Protected WithEvents lblSitePrice As System.Web.UI.WebControls.Label Protected WithEvents lblListPriceName As System.Web.UI.WebControls.Label Protected WithEvents lblListPrice As System.Web.UI.WebControls.Label Protected WithEvents tblProperties As System.Web.UI.WebControls.Table Protected WithEvents tblOptions As System.Web.UI.WebControls.Table Protected WithEvents lstProperties As System.Web.UI.HtmlControls.HtmlGenericControl Protected WithEvents lblYouSaveLabel As System.Web.UI.WebControls.Label Protected WithEvents lblYouSave As System.Web.UI.WebControls.Label Protected WithEvents trListPrice As System.Web.UI.HtmlControls.HtmlTableRow Protected WithEvents trYouSave As System.Web.UI.HtmlControls.HtmlTableRow Protected WithEvents lblQuantity As System.Web.UI.WebControls.Label Protected WithEvents pnlVolumeDiscounts As System.Web.UI.WebControls.Panel Protected WithEvents lblVolumeDiscounts As System.Web.UI.WebControls.Label Protected WithEvents dgVolumeDiscounts As System.Web.UI.WebControls.DataGrid Protected WithEvents ZoomLink As System.Web.UI.HtmlControls.HtmlAnchor Protected WithEvents lblDescription As System.Web.UI.WebControls.Label Protected WithEvents imgZoom As System.Web.UI.WebControls.Image Protected WithEvents tdWishList As System.Web.UI.HtmlControls.HtmlTableCell Protected WithEvents msg As BVSoftware.WebControls.WebPageMessage Protected WithEvents AmazonBuyLink As System.Web.UI.WebControls.Literal Protected WithEvents ProductPageContainer As System.Web.UI.HtmlControls.HtmlTable Protected WithEvents lblSKU As System.Web.UI.WebControls.Label Protected WithEvents lblSKUTitle As System.Web.UI.WebControls.Label Protected WithEvents CSSTag1 As BVSoftware.WebControls.CSSTag #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private p As Catalog.Product Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then MetaKeywordsControl.Content = WebAppSettings.MetaKeywords MetaDescriptionControl.Content = WebAppSettings.MetaDescription CSSTag1.StyleSheetURL = PersonalizationServices.GetPersonalizedStyleSheet PageTitle = "Product Details" Me.lblListPriceName.Text = Content.SiteTerms.GetTerm("ListPrice") Me.lblSitePriceName.Text = Content.SiteTerms.GetTerm("SitePrice") Me.lblSKUTitle.Text = Content.SiteTerms.GetTerm("SKU") Me.imgZoom.ImageUrl = ImageHelper.GetThemedButton("MorePictures.gif") btnAddButton.ImageUrl = ImageHelper.GetThemedButton("AddToCart.gif") WishListButton.ImageUrl = ImageHelper.GetThemedButton("AddToWishList.gif") If BVC2004Store.IsUserAuthenticated = True Then Me.tdWishList.Visible = True Me.WishListButton.Visible = True Else Me.tdWishList.Visible = False Me.WishListButton.Visible = False End If viewstate("ProductID") = Request.Params("ProductID") If viewstate("ProductID") = "GIFTCERTIFICATE" Then Response.Redirect("GiftCertificate.aspx") End If Me.val2Qty.Text = ImageHelper.GetErrorIconTag Me.valQty.Text = ImageHelper.GetErrorIconTag End If ' Load Product p = New Catalog.Product If Request.Params("QuickAddProductID") Is Nothing Then p = CatalogServices.Products.GetProductHeavy(ViewState("ProductID"), True) Else p = CatalogServices.Products.GetProductHeavy(Request.Params("QuickAddProductID"), True) End If If p Is Nothing Then msg.ShowError("The requested product could not be loaded") Me.ProductPageContainer.Visible = False Else If p.ID = String.Empty Then msg.ShowError("The requested product could not be loaded") Me.ProductPageContainer.Visible = False Else If p.Status = Catalog.ProductStatus.Disabled Then msg.ShowWarning("The requested product could not be found or is inactive.") Me.ProductPageContainer.Visible = False Else If p.InventoryStatus = Catalog.ProductInventoryStatus.NotAvailable Then msg.ShowWarning("This product is currently not available.") Me.ProductPageContainer.Visible = False Else Pipelines.ProductPricingPipeline.Run(p) ' Amazon If p.ProductTypeID = -100 Then Me.btnAddButton.Visible = False Me.WishListButton.Visible = False Me.AmazonBuyLink.Text = "" LoadAmazonProduct() Else Me.AmazonBuyLink.Text = "" If Not Page.IsPostBack Then If Request.Params("QuickAddProductID") Is Nothing Then LoadProductInfo() Else Dim iQty As Integer = 1 If Not Request.Params("QuickAddQty") Is Nothing Then iQty = Request.Params("QuickAddQty") End If QuickAddProduct(Request.Params("QuickAddProductID"), iQty, True) End If End If LoadProductProperties() LoadProductChoices() End If End If End If UpdateBreadCrumbTrail(p.ID) End If End If End Sub Private Sub UpdateBreadCrumbTrail(ByVal productID As String) ' Thanks to Al from Jeepaholics... ' Fix to force a CategoryID to the Session for breadcrumbs. This category ID is determined ' by taking the first Category found for a particular product. It will also verify that ' the existing Category Breadcrumb matches the Product being viewed. Dim _dt As DataTable _dt = CatalogServices.Products.GetCategories(productID) If Not _dt Is Nothing Then ' Assure that at least one Category was returned for this product before proceding If _dt.Rows.Count > 0 Then ' If no category ID exists in the session, apply the first found for the product. If Session("LastCategoryID") Is Nothing Then Session("LastCategoryID") = _dt.Rows(0).Item("ID") Else ' Assure the product exists in this category Dim _match As Boolean = False For Each _row As DataRow In _dt.Rows If _row.Item("ID") = Session("LastCategoryID") Then _match = True Exit For End If Next ' If no match, apply first found If Not _match Then Session("LastCategoryID") = _dt.Rows(0).Item("ID") End If End If End If End If End Sub Sub LoadProductInfo() Try If Not p Is Nothing Then If p.MinimumQty > 0 Then inQty.Text = p.MinimumQty Else inQty.Text = 1 End If lblName.Text = p.ProductName lblSKU.Text = p.ID If p.LongDescription.Trim.Length > 0 Then Me.lblDescription.Text = p.LongDescription Else Me.lblDescription.Text = "" End If If p.InventoryStatus = Catalog.ProductInventoryStatus.BackOrderedAllowPurchase Or p.InventoryStatus = Catalog.ProductInventoryStatus.BackOrderedDoNotAllowPurchase Then Me.lblDescription.Text = "

" & p.InventoryNotAvailableMessage & "

" & Me.lblDescription.Text End If lblListPrice.Text = String.Format("{0:c}", p.ListPrice) lblSitePrice.Text = String.Format("{0:c}", p.SitePrice) If p.ListPrice > p.SitePrice Then trListPrice.Visible = True trYouSave.Visible = True Me.lblSitePrice.CssClass = "SitePriceDiscounted" Dim savings As Double = 0.0 savings = p.ListPrice - p.SitePrice Me.lblYouSave.Text = String.Format("{0:c}", savings) Else trListPrice.Visible = False trYouSave.Visible = False Me.lblSitePrice.CssClass = "SitePrice" End If ' Load Product Specific Meta Tags If p.MetaKeywords.Trim.Length > 0 Then Me.MetaKeywordsControl.Content = p.MetaKeywords End If If p.MetaDescription.Trim.Length > 0 Then Me.MetaDescriptionControl.Content = p.MetaDescription End If If p.MetaTitle.Trim.Length > 0 Then PageTitle = p.MetaTitle.Trim Else PageTitle = p.ProductName End If ' Images Me.MainImage.ImageUrl = ImageHelper.GetValidImage(p.ImageFileMedium) Me.MainImage.AlternateText = p.ProductName ' Addition Images Link Dim additionalImages As DataTable additionalImages = CatalogServices.Products.GetAdditionalImagesForProduct(p.ID) If (Not additionalImages Is Nothing) And (additionalImages.Rows.Count() > 0) Then Me.ZoomLink.Style.Add("CURSOR", "pointer") Dim popInfo As ImageHelper.ImageInfo = ImageHelper.GetImageInformation(additionalImages.Rows(0).Item("FileName")) Dim w As Integer = popInfo.Width Dim h As Integer = popInfo.Height w += 100 h += 100 If w > 700 Then w = 700 End If If h > 600 Then h = 600 End If Me.ZoomLink.Attributes.Add("onclick", "JavaScript:window.open('ZoomImage.aspx?productID=" & Server.UrlEncode(p.ID) & "','Images','width=" & w & ", height=" & h & ", menubar=no, scrollbars=yes, resizable=yes, status=no, toolbar=no')") Me.imgZoom.Visible = True Else Me.ZoomLink.Style.Clear() Me.ZoomLink.Attributes.Add("onclick", "JavaScript:void(0)") Me.imgZoom.Visible = False End If LoadVolumePricingInfo(p.ID) If p.InventoryStatus = Catalog.ProductInventoryStatus.NotAvailable Or p.InventoryStatus = Catalog.ProductInventoryStatus.BackOrderedDoNotAllowPurchase Then Me.btnAddButton.Visible = False End If Else msg.ShowError("Error Loading Product") End If Catch Ex As Exception msg.ShowException(Ex) End Try End Sub Private Sub LoadAmazonProduct() Try If Not p Is Nothing Then Dim ap As BVSoftware.AmazonWebServices3.AmazonProduct ap = AmazonCache.GetAmazonProduct(p.ID) If Not ap Is Nothing Then If p.MinimumQty > 0 Then inQty.Text = p.MinimumQty Else inQty.Text = 1 End If lblName.Text = ap.ProductName lblSKU.Text = ap.Asin ' Load Amazon Specific Info Here lblListPrice.Text = String.Format("{0:c}", ap.ListPrice) lblSitePrice.Text = String.Format("{0:c}", ap.OurPrice) If ap.ListPrice > ap.OurPrice Then trListPrice.Visible = True trYouSave.Visible = True Me.lblSitePrice.CssClass = "SitePriceDiscounted" Dim savings As Double = 0.0 savings = ap.ListPrice - ap.OurPrice Me.lblYouSave.Text = String.Format("{0:c}", savings) Else trListPrice.Visible = False trYouSave.Visible = False Me.lblSitePrice.CssClass = "SitePrice" End If ' Load Product Specific Meta Tags If p.MetaKeywords.Trim.Length > 0 Then Me.MetaKeywordsControl.Content = p.MetaKeywords End If If p.MetaDescription.Trim.Length > 0 Then Me.MetaDescriptionControl.Content = p.MetaDescription End If If p.MetaTitle.Trim.Length > 0 Then PageTitle = p.MetaTitle.Trim Else PageTitle = p.ProductName End If Me.MainImage.ImageUrl = ap.ImageURLMedium Me.MainImage.AlternateText = ap.ProductName If ap.ImageURLLarge.Length > 0 Then Me.ZoomLink.Style.Clear() Dim w As Integer = 600 Dim h As Integer = 500 Me.ZoomLink.Attributes.Add("onclick", "JavaScript:window.open('ZoomImage.aspx?productID=" & Server.UrlEncode(p.ID) & "','Images','width=" & w & ", height=" & h & ", menubar=no, scrollbars=yes, resizable=yes, status=no, toolbar=no')") Me.imgZoom.Visible = True Else Me.ZoomLink.Style.Clear() Me.ZoomLink.Attributes.Add("onclick", "JavaScript:void(0)") Me.imgZoom.Visible = False End If Me.AmazonBuyLink.Text = ap.GetQuickBuyLink(WebAppSettings.AmazonAssociateID) Me.inQty.Enabled = False Me.lblVolumeDiscounts.Visible = False Dim sb As New StringBuilder sb.Append("") Me.lblDescription.Text = sb.ToString sb = Nothing Else msg.ShowWarning("Could not load Amazon product information") End If Else msg.ShowError("Error Loading Product") End If Catch Ex As Exception msg.ShowException(Ex) End Try End Sub Sub LoadVolumePricingInfo(ByVal productID As String) Me.pnlVolumeDiscounts.Visible = False Dim ds As DataSet = CatalogServices.ProductVolumeDiscounts.GetForProduct(productID) If Not ds Is Nothing Then If ds.Tables.Count > 0 Then If ds.Tables(0).Rows.Count > 0 Then Me.pnlVolumeDiscounts.Visible = True Me.dgVolumeDiscounts.DataSource = ds.Tables(0) Me.dgVolumeDiscounts.DataBind() End If End If End If ds = Nothing End Sub Private Sub LoadProductProperties() Me.lstProperties.InnerHtml = "" If Not p Is Nothing Then For i As Integer = 0 To p.Properties.Length - 1 With p.Properties(i) If .DisplayOnSite = True Then Select Case .TypeCode Case Catalog.ProductPropertyType.CurrencyField Dim c As CultureInfo = CultureInfo.CreateSpecificCulture(.CultureCode) If Not c Is Nothing Then AddPropertyRow(.DisplayName, String.Format(c, "{0:c}", Double.Parse(CatalogServices.Products.GetPropertyValue(p.ID, .ID)))) Else AddPropertyRow(.DisplayName, String.Format("{0:c}", Double.Parse(CatalogServices.Products.GetPropertyValue(p.ID, .ID)))) End If Case Catalog.ProductPropertyType.DateField Dim d As New Date d = d.Parse(CatalogServices.Products.GetPropertyValue(p.ID, .ID), System.Globalization.CultureInfo.CreateSpecificCulture("en-US")) AddPropertyRow(.DisplayName, String.Format("{0:d}", d)) d = Nothing Case Catalog.ProductPropertyType.MultipleChoiceField Dim choices As DataTable = CatalogServices.ProductProperties.GetChoices(.ID) Dim displayValue As String = "" For j As Integer = 0 To choices.Rows.Count - 1 If choices.Rows(j).Item("id") = CatalogServices.Products.GetPropertyValue(p.ID, .ID) Then displayValue = choices.Rows(j).Item("ChoiceName") End If Next AddPropertyRow(.DisplayName, displayValue) Case Catalog.ProductPropertyType.TextField AddPropertyRow(.DisplayName, CatalogServices.Products.GetPropertyValue(p.ID, .ID)) End Select End If End With Next End If End Sub Private Sub AddPropertyRow(ByVal propertyName As String, ByVal propertyValue As String) If propertyValue.Trim.Length > 0 Then Me.lstProperties.InnerHtml += "
  • " & propertyName & " " Me.lstProperties.InnerHtml += "" & propertyValue & "
  • " End If End Sub 'SP1A - Rewrote Private Sub LoadProductChoices() Me.inQty.Visible = True Me.lblSitePrice.Visible = True Me.lblSitePriceName.Visible = True Me.lblYouSave.Visible = True Me.lblYouSaveLabel.Visible = True Me.lblQuantity.Visible = True Me.lblListPrice.Visible = True Me.lblListPriceName.Visible = True Me.tblOptions.Rows.Clear() If Not p Is Nothing Then If Not p.Choices Is Nothing Then If p.Choices.Length > 0 Then Dim hasNonAccessoryChoices As Boolean = False For i As Integer = 0 To p.Choices.Length - 1 If p.Choices(i).TypeCode = Catalog.ProductChoiceType.MultipleChoiceField Or _ p.Choices(i).TypeCode = Catalog.ProductChoiceType.RadioButtonList Or _ p.Choices(i).TypeCode = Catalog.ProductChoiceType.TextField Then hasNonAccessoryChoices = True Exit For End If Next Select Case p.VariantDisplay Case Catalog.VariantDisplayMode.GridMultipleSelection, Catalog.VariantDisplayMode.GridSingleSelection If hasNonAccessoryChoices = True Then LoadProductChoices_Grid() Else LoadProductChoices_IndividualFields() End If Case Catalog.VariantDisplayMode.IndividualFields LoadProductChoices_IndividualFields() End Select End If End If End If End Sub 'SP1A - New Method Private Sub LoadProductChoices_IndividualFields() For i As Integer = 0 To p.Choices.Length - 1 With p.Choices(i) Select Case p.Choices(i).TypeCode Case Catalog.ProductChoiceType.TextField Dim tb As New TextBox tb.ID = "Choice" & .ID tb.Rows = .TextRows tb.Columns = .TextColumns If .TextRows > 1 Then tb.TextMode = TextBoxMode.MultiLine Else tb.TextMode = TextBoxMode.SingleLine End If If .Html = "REQUIRED" Then Dim val As New RequiredFieldValidator val.ControlToValidate = tb.ID val.Display = ValidatorDisplay.Static val.ErrorMessage = .DisplayName & " is required" val.Text = "*" AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {tb, val}) Else AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {tb}) End If tb = Nothing Case Catalog.ProductChoiceType.MultipleChoiceField Dim ddl As New DropDownList ddl.ID = "Choice" & .ID For k As Integer = 0 To .Items.Length - 1 Dim li As New ListItem li.Text = .Items(k).DisplayText If .Items(k).NullItem = False Then If .Items(k).PriceAdjustment > 0 Then li.Text += " +" & String.Format("{0:c}", .Items(k).PriceAdjustment) ElseIf .Items(k).PriceAdjustment < 0 Then li.Text += " -" & String.Format("{0:c}", .Items(k).PriceAdjustment) End If End If li.Value = .Items(k).ID If .Items(k).Selected = True Then li.Selected = True End If ddl.Items.Add(li) li = Nothing Next AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {ddl}) ddl = Nothing Case Catalog.ProductChoiceType.RadioButtonList Dim rbl As New RadioButtonList rbl.ID = "Choice" & .ID rbl.RepeatColumns = .TextColumns rbl.CssClass = "Formlabel" rbl.RepeatDirection = RepeatDirection.Vertical For j As Integer = 0 To .Items.Length - 1 Dim li As New ListItem If .Items(j).ImageURL.Trim.Length > 0 Then li.Text = "" & .Items(j).DisplayText Else li.Text = .Items(j).DisplayText End If If .Items(j).NullItem = False Then If .Items(j).PriceAdjustment > 0 Then li.Text += " +" & String.Format("{0:c}", .Items(j).PriceAdjustment) ElseIf .Items(j).PriceAdjustment < 0 Then li.Text += " -" & String.Format("{0:c}", .Items(j).PriceAdjustment) End If End If li.Value = .Items(j).ID If .Items(j).Selected = True Then li.Selected = True End If rbl.Items.Add(li) li = Nothing Next AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {rbl}) rbl = Nothing Case Catalog.ProductChoiceType.HtmlArea Dim htm As New Label htm.ID = "Choice" & .ID htm.Text = .Html AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {htm}) htm = Nothing Case Catalog.ProductChoiceType.AccessoryCheckBox Dim cbl As New CheckBoxList cbl.ID = "Choice" & .ID cbl.RepeatColumns = .TextColumns cbl.CssClass = "Formlabel" cbl.RepeatDirection = RepeatDirection.Vertical For j As Integer = 0 To .Items.Length - 1 Dim listP As New Catalog.Product listP = CatalogServices.Products.GetProduct(.Items(j).DisplayValue) If Not listP Is Nothing Then If listP.InventoryStatus = Catalog.ProductInventoryStatus.Available Or listP.InventoryStatus = Catalog.ProductInventoryStatus.BackOrderedAllowPurchase Then Dim li As New ListItem If .Items(j).ImageURL.Trim.Length > 0 Then li.Text = "" & .Items(j).DisplayText Else li.Text = .Items(j).DisplayText End If If .Items(j).NullItem = False Then li.Text += " " & String.Format("{0:c}", listP.SitePrice) End If li.Value = .Items(j).ID If .Items(j).Selected = True Then li.Selected = True End If cbl.Items.Add(li) li = Nothing End If End If Next AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {cbl}) cbl = Nothing Case Catalog.ProductChoiceType.AccessoryDropdownList Dim ddl As New DropDownList ddl.ID = "Choice" & .ID For k As Integer = 0 To .Items.Length - 1 Dim listP As New Catalog.Product listP = CatalogServices.Products.GetProduct(.Items(k).DisplayValue) If Not listP Is Nothing Then If listP.InventoryStatus = Catalog.ProductInventoryStatus.Available Or listP.InventoryStatus = Catalog.ProductInventoryStatus.BackOrderedAllowPurchase Then Dim li As New ListItem li.Text = .Items(k).DisplayText If .Items(k).NullItem = False Then li.Text += " " & String.Format("{0:c}", listP.SitePrice) End If li.Value = .Items(k).ID If .Items(k).Selected = True Then li.Selected = True End If ddl.Items.Add(li) li = Nothing End If End If Next AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {ddl}) ddl = Nothing Case Catalog.ProductChoiceType.AccessoryRadioButtonList Dim rbl As New RadioButtonList rbl.ID = "Choice" & .ID rbl.RepeatColumns = .TextColumns rbl.CssClass = "Formlabel" rbl.RepeatDirection = RepeatDirection.Vertical For j As Integer = 0 To .Items.Length - 1 Dim listP As New Catalog.Product listP = CatalogServices.Products.GetProduct(.Items(j).DisplayValue) If Not listP Is Nothing Then If listP.InventoryStatus = Catalog.ProductInventoryStatus.Available Or listP.InventoryStatus = Catalog.ProductInventoryStatus.BackOrderedAllowPurchase Then Dim li As New ListItem If .Items(j).ImageURL.Trim.Length > 0 Then li.Text = "" & .Items(j).DisplayText Else li.Text = .Items(j).DisplayText End If If .Items(j).NullItem = False Then li.Text += " " & String.Format("{0:c}", listP.SitePrice) End If li.Value = .Items(j).ID If .Items(j).Selected = True Then li.Selected = True End If rbl.Items.Add(li) li = Nothing End If End If Next AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {rbl}) rbl = Nothing End Select End With Next End Sub 'SP1A - New Method Private Sub LoadProductChoices_Grid() Me.lblSitePrice.Visible = False Me.lblSitePriceName.Visible = False Me.lblYouSave.Visible = False Me.lblYouSaveLabel.Visible = False Me.lblListPrice.Visible = False Me.lblListPriceName.Visible = False ' Display text fields and HTML outside grid LoadProductChoices_NonGridChoices() ' Create Table to hold grid Dim tblGrid As New Table tblGrid.CellPadding = 3 tblGrid.CellSpacing = 0 tblGrid.BorderStyle = BorderStyle.None tblGrid.GridLines = GridLines.None tblGrid.ID = "tblGrid" tblGrid.EnableViewState = False ' Add Header Columns to Grid LoadProductChoices_AddGridHeader(tblGrid) AddVariants(tblGrid) ' Add Grid table to options table Dim trGrid As New TableRow Dim tcGrid As New TableCell tcGrid.EnableViewState = False tcGrid.ColumnSpan = 2 tcGrid.Controls.Add(tblGrid) trGrid.Cells.Add(tcGrid) Me.tblOptions.Rows.Add(trGrid) End Sub 'SP1A - New method Private Sub LoadProductChoices_NonGridChoices() For i As Integer = 0 To p.Choices.Length - 1 With p.Choices(i) Select Case p.Choices(i).TypeCode Case Catalog.ProductChoiceType.TextField Dim tb As New TextBox tb.ID = "Choice" & .ID tb.Rows = .TextRows tb.Columns = .TextColumns If .TextRows > 1 Then tb.TextMode = TextBoxMode.MultiLine Else tb.TextMode = TextBoxMode.SingleLine End If If .Html = "REQUIRED" Then Dim val As New RequiredFieldValidator val.ControlToValidate = tb.ID val.Display = ValidatorDisplay.Static val.ErrorMessage = .DisplayName & " is required" val.Text = "*" AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {tb, val}) Else AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {tb}) End If tb = Nothing Case Catalog.ProductChoiceType.HtmlArea Dim htm As New Label htm.ID = "Choice" & .ID htm.Text = .Html AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {htm}) htm = Nothing Case Catalog.ProductChoiceType.AccessoryCheckBox Dim cbl As New CheckBoxList cbl.ID = "Choice" & .ID cbl.RepeatColumns = .TextColumns cbl.CssClass = "Formlabel" cbl.RepeatDirection = RepeatDirection.Vertical For j As Integer = 0 To .Items.Length - 1 Dim listP As New Catalog.Product listP = CatalogServices.Products.GetProduct(.Items(j).DisplayValue) If Not listP Is Nothing Then If listP.InventoryStatus = Catalog.ProductInventoryStatus.Available Or listP.InventoryStatus = Catalog.ProductInventoryStatus.BackOrderedAllowPurchase Then Dim li As New ListItem If .Items(j).ImageURL.Trim.Length > 0 Then li.Text = "" & .Items(j).DisplayText Else li.Text = .Items(j).DisplayText End If If .Items(j).NullItem = False Then li.Text += " " & String.Format("{0:c}", listP.SitePrice) End If li.Value = .Items(j).ID If .Items(j).Selected = True Then li.Selected = True End If cbl.Items.Add(li) li = Nothing End If End If Next AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {cbl}) cbl = Nothing Case Catalog.ProductChoiceType.AccessoryDropdownList Dim ddl As New DropDownList ddl.ID = "Choice" & .ID For k As Integer = 0 To .Items.Length - 1 Dim listP As New Catalog.Product listP = CatalogServices.Products.GetProduct(.Items(k).DisplayValue) If Not listP Is Nothing Then If listP.InventoryStatus = Catalog.ProductInventoryStatus.Available Or listP.InventoryStatus = Catalog.ProductInventoryStatus.BackOrderedAllowPurchase Then Dim li As New ListItem li.Text = .Items(k).DisplayText If .Items(k).NullItem = False Then li.Text += " " & String.Format("{0:c}", listP.SitePrice) End If li.Value = .Items(k).ID If .Items(k).Selected = True Then li.Selected = True End If ddl.Items.Add(li) li = Nothing End If End If Next AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {ddl}) ddl = Nothing Case Catalog.ProductChoiceType.AccessoryRadioButtonList Dim rbl As New RadioButtonList rbl.ID = "Choice" & .ID rbl.RepeatColumns = .TextColumns rbl.CssClass = "Formlabel" rbl.RepeatDirection = RepeatDirection.Vertical For j As Integer = 0 To .Items.Length - 1 Dim listP As New Catalog.Product listP = CatalogServices.Products.GetProduct(.Items(j).DisplayValue) If Not listP Is Nothing Then If listP.InventoryStatus = Catalog.ProductInventoryStatus.Available Or listP.InventoryStatus = Catalog.ProductInventoryStatus.BackOrderedAllowPurchase Then Dim li As New ListItem If .Items(j).ImageURL.Trim.Length > 0 Then li.Text = "" & .Items(j).DisplayText Else li.Text = .Items(j).DisplayText End If If .Items(j).NullItem = False Then li.Text += " " & String.Format("{0:c}", listP.SitePrice) End If li.Value = .Items(j).ID If .Items(j).Selected = True Then li.Selected = True End If rbl.Items.Add(li) li = Nothing End If End If Next AddChoiceRow(.DisplayName, New System.Web.UI.WebControls.WebControl() {rbl}) rbl = Nothing End Select End With Next End Sub 'SP1A - New Method Private Sub LoadProductChoices_AddGridHeader(ByRef t As Table) Dim tr As New TableRow If p.VariantDisplay = Catalog.VariantDisplayMode.GridSingleSelection Then ' Holds radio button Dim tcA As New TableCell tcA.EnableViewState = False tcA.CssClass = "Header" tcA.Text = " " tr.Cells.Add(tcA) tcA = Nothing End If ' Add title columns For q As Integer = 0 To p.Choices.Length - 1 If p.Choices(q).TypeCode = Catalog.ProductChoiceType.MultipleChoiceField Or p.Choices(q).TypeCode = Catalog.ProductChoiceType.RadioButtonList Then Dim tc As New TableCell tc.EnableViewState = False tc.CssClass = "Header" tc.Text = p.Choices(q).DisplayName tr.Cells.Add(tc) tc = Nothing End If Next ' Add Price Cell Dim tcB As New TableCell tcB.EnableViewState = False tcB.CssClass = "Header" tcB.Text = "Site Price" tr.Cells.Add(tcB) tcB = Nothing If p.VariantDisplay = Catalog.VariantDisplayMode.GridMultipleSelection Then ' Holds Quantity Box Me.inQty.Visible = False Me.lblQuantity.Visible = False Dim tcC As New TableCell tcC.EnableViewState = False tcC.CssClass = "Header" tcC.Text = "Qty" tr.Cells.Add(tcC) tcC = Nothing End If t.Rows.Add(tr) tr = Nothing End Sub 'SP1A - New Sub Private Sub AddVariants(ByRef t As Table) If Not p Is Nothing Then If Not p.Choices Is Nothing Then If p.Choices.Length > 0 Then Dim totalVariants As Integer = 0 ' Key is ChoiceID, Value is index in p.Choices Dim VariantChoices As New Hashtable For i As Integer = 0 To p.Choices.Length - 1 If p.Choices(i).TypeCode = Catalog.ProductChoiceType.MultipleChoiceField Or p.Choices(i).TypeCode = Catalog.ProductChoiceType.RadioButtonList Then VariantChoices.Add(VariantChoices.Count, i) End If Next Dim currentValues(VariantChoices.Count - 1) As String Dim currentItemIndexes(VariantChoices.Count - 1) As Integer Dim priceAdjustments(VariantChoices.Count - 1) As Double ProcessChoices(0, p, VariantChoices, t, currentValues, currentItemIndexes, totalVariants, priceAdjustments) End If ' choices length End If ' choices is nothing End If ' p is nothing End Sub 'SP1A - New Sub Private Sub ProcessChoices(ByVal currentIndex As Integer, ByVal p As Catalog.Product, ByRef variants As Hashtable, ByRef t As Table, ByRef currentValues() As String, ByRef currentIndexes() As Integer, ByRef totalRows As Integer, ByRef priceAdjustments() As Double) For i As Integer = 0 To p.Choices(variants(currentIndex)).Items.Length - 1 If p.Choices(variants(currentIndex)).Items(i).NullItem = False Then If currentValues.Length < 1 Then Exit For End If If currentIndexes.Length < 1 Then Exit For End If If priceAdjustments.Length < 1 Then Exit For End If If currentIndex < currentValues.Length Then currentValues(currentIndex) = p.Choices(variants(currentIndex)).Items(i).DisplayText End If If currentIndex < currentIndexes.Length Then currentIndexes(currentIndex) = p.Choices(variants(currentIndex)).Items(i).ID End If If currentIndex < priceAdjustments.Length Then priceAdjustments(currentIndex) = p.Choices(variants(currentIndex)).Items(i).PriceAdjustment End If If currentIndex = variants.Count - 1 Then ' Last Item in chain so write out tables totalRows += 1 AddRowToTable(t, currentValues, currentIndexes, totalRows, priceAdjustments) Else ' More items in chain so add our value and continue on ProcessChoices(currentIndex + 1, p, variants, t, currentValues, currentIndexes, totalRows, priceAdjustments) End If End If Next End Sub ' SP1A - New Sub Private Sub AddRowToTable(ByRef t As Table, ByRef values() As String, ByRef indexes() As Integer, ByVal totalRows As Integer, ByRef prices() As Double) ' Determine CSS Class for Row Dim cellStyle As String = "" If totalRows Mod 2 = 0 Then cellStyle = "AlternateItem" Else cellStyle = "Item" End If ' Check Availability Dim inStock As Boolean = True Dim inventoryKey As String = CatalogServices.ProductChoices.GenerateInventoryKeyForItemIDs(indexes) inStock = IsInventoryKeyInStock(inventoryKey, 1) ' Check Inventory Levels for this variant If (WebAppSettings.DisableInventory = False) And (p.InventoryNotAvailableStatus = Catalog.ProductInventoryStatus.BackOrderedDoNotAllowPurchase Or p.InventoryNotAvailableStatus = Catalog.ProductInventoryStatus.NotAvailable) Then Dim pik As Catalog.ProductInventoryKey For i As Integer = 0 To p.InventoryKeys.Length - 1 If p.InventoryKeys(i).InventoryKey = inventoryKey Then pik = p.InventoryKeys(i) Exit For End If Next If Not pik Is Nothing Then If pik.Qty <= p.InventoryLowStockNotice Then inStock = False End If Else inStock = False End If End If Dim tr As New TableRow ' Add Radio Button if in Single Grid Mode If p.VariantDisplay = Catalog.VariantDisplayMode.GridSingleSelection Then Dim tcR As New TableCell tcR.EnableViewState = True tcR.CssClass = cellStyle Dim radio1 As New RadioButton radio1.ID = "VariantRadio" & inventoryKey radio1.Text = "" radio1.GroupName = "ProductVariantRadio" If inStock = True Then tcR.Controls.Add(radio1) Else tcR.Text = " " End If tr.Cells.Add(tcR) radio1 = Nothing tcR = Nothing End If Dim variantPrice As Double = 0 variantPrice = p.SitePrice ' Add Choice Text For i As Integer = 0 To values.Length - 1 Dim tc As New TableCell tc.Text = values(i) tc.EnableViewState = False tc.CssClass = cellStyle tr.Cells.Add(tc) tc = Nothing variantPrice += prices(i) Next ' Add Price Field variantPrice = Math.Round(variantPrice, 2) Dim tcPrice As New TableCell tcPrice.EnableViewState = False tcPrice.CssClass = cellStyle tcPrice.Text = String.Format("{0:c}", variantPrice) tr.Cells.Add(tcPrice) ' Add Qty Field if in Grid Multiple Mode If p.VariantDisplay = Catalog.VariantDisplayMode.GridMultipleSelection Then Dim tcQ As New TableCell tcQ.EnableViewState = True tcQ.CssClass = cellStyle Dim qtyTemp As New TextBox qtyTemp.ID = "VariantQty" & inventoryKey qtyTemp.CssClass = "FormInput" qtyTemp.Columns = 5 qtyTemp.Text = "0" If inStock = True Then tcQ.Controls.Add(qtyTemp) Else tcQ.Text = " " End If tr.Cells.Add(tcQ) qtyTemp = Nothing tcQ = Nothing End If t.Rows.Add(tr) End Sub 'SP1A - New Method Private Function IsInventoryKeyInStock(ByVal key As String, ByRef qty As Integer) As Boolean Dim result As Boolean = True If (WebAppSettings.DisableInventory = False) And (p.InventoryNotAvailableStatus = Catalog.ProductInventoryStatus.BackOrderedDoNotAllowPurchase Or p.InventoryNotAvailableStatus = Catalog.ProductInventoryStatus.NotAvailable) Then Dim pik As Catalog.ProductInventoryKey For i As Integer = 0 To p.InventoryKeys.Length - 1 If p.InventoryKeys(i).InventoryKey = key Then pik = p.InventoryKeys(i) Exit For End If Next If Not pik Is Nothing Then ' Don't let the customer order more than is available. If qty > pik.Qty Then qty = pik.Qty End If If pik.Qty <= p.InventoryLowStockNotice Then result = False End If Else result = False End If End If Return result End Function Private Sub AddChoiceRow(ByVal propertyName As String, ByVal variantControl() As System.Web.UI.WebControls.WebControl) Dim tr As New TableRow Dim tc1 As New TableCell Dim tc2 As New TableCell tc1.CssClass = "ProductPropertyLabel" tc1.Text = propertyName tc1.VerticalAlign = VerticalAlign.Top tc1.HorizontalAlign = HorizontalAlign.Right tc2.CssClass = "ProductProperty" For i As Integer = 0 To variantControl.Length - 1 tc2.Controls.Add(variantControl(i)) Next tc2.HorizontalAlign = HorizontalAlign.Left tc2.VerticalAlign = VerticalAlign.Top tr.Cells.Add(tc1) tr.Cells.Add(tc2) Me.tblOptions.Rows.Add(tr) tc1 = Nothing tc2 = Nothing tr = Nothing End Sub Private Sub btnContinue_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) If Not Session("LastCategoryID") Is Nothing Then Response.Redirect("category.aspx?categoryid=" & Session("LastCategoryID")) Else Response.Redirect(WebAppSettings.SiteStandardRoot) End If End Sub Private Sub btnAddButton_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnAddButton.Click msg.Clear() Dim bUpdatesOkay As Boolean = True Dim qtyError As Boolean = False Dim hasNonAccessoryChoices As Boolean = False For i As Integer = 0 To p.Choices.Length - 1 If p.Choices(i).TypeCode = Catalog.ProductChoiceType.MultipleChoiceField Or _ p.Choices(i).TypeCode = Catalog.ProductChoiceType.RadioButtonList Or _ p.Choices(i).TypeCode = Catalog.ProductChoiceType.TextField Then hasNonAccessoryChoices = True Exit For End If Next Select Case p.VariantDisplay Case Catalog.VariantDisplayMode.GridMultipleSelection If hasNonAccessoryChoices = True Then bUpdatesOkay = AddToCart_MultipleGrid(qtyError) Else bUpdatesOkay = AddToCart_IndividualFields(qtyError) End If Case Catalog.VariantDisplayMode.GridSingleSelection If hasNonAccessoryChoices = True Then bUpdatesOkay = AddToCart_SingleGrid(qtyError) Else bUpdatesOkay = AddToCart_IndividualFields(qtyError) End If Case Catalog.VariantDisplayMode.IndividualFields bUpdatesOkay = AddToCart_IndividualFields(qtyError) End Select If bUpdatesOkay = True Then AddAccessories() If ViewState("CategoryID") > 0 Then Page.SmartNavigation = False If qtyError = True Then Response.Redirect("cart.aspx?QTYERR=1&ContinueCategory=" & ViewState("CategoryID")) Else Response.Redirect("cart.aspx?ContinueCategory=" & ViewState("CategoryID")) End If Else Page.SmartNavigation = False If qtyError = True Then Response.Redirect("cart.aspx?QTYERR=1") Else Response.Redirect("cart.aspx") End If End If End If End Sub 'SP1A - Rewrote Function Private Function AddToCart_MultipleGrid(ByRef qtyError As Boolean) As Boolean Dim Result As Boolean = True Dim inventoryKey As String = "" Dim iQty As Integer = 0 Dim tbl As Table tbl = Me.tblOptions.FindControl("tblGrid") If Not tbl Is Nothing Then ' Loop through and check minimum Qty For j As Integer = 0 To tbl.Rows.Count - 1 Dim con As TextBox If tbl.Rows(j).Cells(tbl.Rows(j).Cells.Count - 1).Controls.Count > 0 Then con = CType(tbl.Rows(j).Cells(tbl.Rows(j).Cells.Count - 1).Controls(0), TextBox) End If If Not con Is Nothing Then Try ' Calculate Total Quantity Dim requestedQty As Integer = Integer.Parse(con.Text) inventoryKey = con.ID inventoryKey = inventoryKey.Remove(0, 10) If IsInventoryKeyInStock(inventoryKey, requestedQty) = True Then iQty += requestedQty Else con.Text = 0 End If ' If less are available then requested, update text field ' and warn in cart If requestedQty <> Integer.Parse(con.Text) Then qtyError = True con.Text = requestedQty End If Catch ex As Exception End Try End If con = Nothing Next ' If minimum Qty is passed, make second pass to acutally add items to cart If iQty >= p.MinimumQty Then For i As Integer = 0 To tbl.Rows.Count - 1 Dim con As TextBox If tbl.Rows(i).Cells(tbl.Rows(i).Cells.Count - 1).Controls.Count > 0 Then con = CType(tbl.Rows(i).Cells(tbl.Rows(i).Cells.Count - 1).Controls(0), TextBox) End If If Not con Is Nothing Then Try ' Calculate Total Quantity Dim qtyToAdd As Integer = Integer.Parse(con.Text) inventoryKey = con.ID inventoryKey = inventoryKey.Remove(0, 10) If qtyToAdd > 0 Then ' Add Items Here If Me.AddToCart_InventoryKey(inventoryKey, qtyToAdd) = False Then Result = False End If End If Catch ex As Exception End Try End If con = Nothing Next Else msg.ShowWarning("Minimum quantity is " & p.MinimumQty) Result = False End If Else msg.ShowError("An error occured while attempting to add this product to the cart. Error Code: AddToCart_SingleGrid_NoGridFound") Result = False End If Return Result End Function 'SP1A - Rewrote Function Private Function AddToCart_SingleGrid(ByRef qtyError As Boolean) As Boolean Dim Result As Boolean = True Dim inventoryKey As String = "" Dim iQty As Integer = Convert.ToInt32(inQty.Text) If iQty >= p.MinimumQty Then Dim tbl As Table tbl = Me.tblOptions.FindControl("tblGrid") If Not tbl Is Nothing Then ' Loop through table and search for selected radio button For i As Integer = 0 To tbl.Rows.Count - 1 If tbl.Rows(i).Cells.Count > 0 Then If tbl.Rows(i).Cells(0).Controls.Count > 0 Then Dim rb As RadioButton rb = CType(tbl.Rows(i).Cells(0).Controls(0), RadioButton) If Not rb Is Nothing Then If rb.Checked = True Then inventoryKey = rb.ID inventoryKey = inventoryKey.Remove(0, 12) End If End If rb = Nothing End If End If Next If inventoryKey = "" Then msg.ShowWarning("Please select a product.") Result = False Else ' Variant Found, Check Available Qty Dim requestedQty As Integer = iQty If IsInventoryKeyInStock(inventoryKey, requestedQty) = True Then ' Not all requested were available so warn but add available to cart If requestedQty <> iQty Then qtyError = True End If If Me.AddToCart_InventoryKey(inventoryKey, requestedQty) = True Then Result = True Else Result = False End If Else msg.ShowWarning("The option you have selected is currently out of stock. Please make another selection.") Result = False End If End If Else msg.ShowError("An error occured while attempting to add this product to the cart. Error Code: AddToCart_SingleGrid_NoGridFound") Result = False End If Else msg.ShowWarning("Minimum quantity is " & p.MinimumQty) Result = False End If Return Result End Function 'SP1A - Replaced ByVariantIndex Method with ByInventoryKey Private Function AddToCart_InventoryKey(ByVal inventoryKey As String, ByVal qty As Integer) As Boolean Dim Result As Boolean = True Dim ShoppingCart As Orders.Order = BVC2004Store.GetCurrentShoppingCart ' Split inventory key into item IDs array so we can check price adjustments Dim itemIDs() As String = inventoryKey.Split("-") ' Add to Cart Try Dim NewItem As New Orders.OrderItem NewItem.ProductID = p.ID NewItem.DisplayName = p.ProductName NewItem.Qty = qty NewItem.Weight = p.ShippingWeight ' Store Product's adjusted price as the base order item price. ' This allows discounts,tax and coupons to make adjustments on the price ' of the item and the price of the attributes together. NewItem.OriginalBasePrice = p.SitePrice ' Add hidden properties to Extra Fields For q As Integer = 0 To p.Properties.Length - 1 If p.Properties(q).DisplayOnSite = False Then NewItem.ExtraInformation.ExtraInformationDictionary.AddExtraInformationDictionaryRow(p.Properties(q).DisplayName, CatalogServices.Products.GetPropertyValue(p.ID, p.Properties(q).ID)) End If Next ' Inventory Specific SKU If Not p.InventoryKeys Is Nothing Then For i As Integer = 0 To p.InventoryKeys.Length - 1 If p.InventoryKeys(i).InventoryKey = inventoryKey Then If p.InventoryKeys(i).SKU.Trim.Length > 0 Then NewItem.ExtraInformation.ExtraInformationDictionary.AddExtraInformationDictionaryRow("BVDISPLAYSKU", p.InventoryKeys(i).SKU) End If Exit For End If Next End If Dim priceAdjustments As Double = 0 Dim costAdjustments As Double = 0 Dim weightAdjustments As Decimal = 0 Dim shippingCostAdjustments As Decimal = 0 ' Add in Choice Selections For i As Integer = 0 To p.Choices.Length - 1 Select Case p.Choices(i).TypeCode Case Catalog.ProductChoiceType.HtmlArea ' Ignore Case Catalog.ProductChoiceType.TextField Dim tb As New System.Web.UI.WebControls.TextBox tb = Me.FindControl("Choice" & p.Choices(i).ID) If Not tb Is Nothing Then NewItem.DisplayDescription += "
    " & p.Choices(i).DisplayName & " " NewItem.DisplayDescription += HttpUtility.HtmlEncode(tb.Text) End If tb = Nothing Case Catalog.ProductChoiceType.MultipleChoiceField, Catalog.ProductChoiceType.RadioButtonList ' Loop through choice items For j As Integer = 0 To p.Choices(i).Items.Length - 1 ' Loop through inventory key for each item For k As Integer = 0 To itemIDs.Length - 1 If p.Choices(i).Items(j).ID = CInt(itemIDs(k)) Then ' This item in in the key NewItem.DisplayDescription += "
    " & p.Choices(i).DisplayName & " " NewItem.DisplayDescription += p.Choices(i).Items(j).DisplayValue priceAdjustments += p.Choices(i).Items(j).PriceAdjustment costAdjustments += p.Choices(i).Items(j).CostAdjustment weightAdjustments += p.Choices(i).Items(j).WeightAdjustment shippingCostAdjustments += p.Choices(i).Items(j).ShippingCostAdjustment End If Next Next End Select Next ' Adjust Site Price and Cost by Selected Choices NewItem.SitePrice = Math.Round(p.SitePrice + priceAdjustments, 2) NewItem.SiteCost = Math.Round(p.SiteCost + costAdjustments, 2) NewItem.Weight += weightAdjustments NewItem.ShippingCost = shippingCostAdjustments NewItem.ShippingCost += p.ExtraShipFee NewItem.InventoryKey = inventoryKey NewItem.LineTotal = NewItem.SitePrice * CDbl(NewItem.Qty) NewItem.LineTaxTotal = 0 NewItem.ShipSeparately = p.ShipSeparately NewItem.NonShipping = p.NonShipping Select Case p.DropShipMode Case Catalog.ProductDropShipMode.ShipFromManufacturer If p.ManufacturerID > 0 Then NewItem.DropShipAddressID = p.ManufacturerID Else NewItem.DropShipAddressID = WebAppSettings.ContactAddress.ID End If Case Catalog.ProductDropShipMode.ShipFromSite NewItem.DropShipAddressID = WebAppSettings.ContactAddress.ID Case Catalog.ProductDropShipMode.ShipFromVendor If p.VendorID > 0 Then NewItem.DropShipAddressID = p.VendorID Else NewItem.DropShipAddressID = WebAppSettings.ContactAddress.ID End If End Select NewItem.DropShipMode = p.DropShipMode NewItem.TaxClass = p.TaxClass NewItem.TaxExempt = p.TaxExempt NewItem.Height = p.ShippingHeight NewItem.Width = p.ShippingWidth NewItem.Length = p.ShippingLength NewItem.MinimumQty = p.MinimumQty NewItem.ImageURL = ImageHelper.ConvertLocalImageToURL(p.ImageFileSmall) NewItem.GiftWrap = False NewItem.GiftWrapMessage = "" NewItem.GiftWrapAllowed = p.GiftWrapAllowed OrderServices.AddItemToCart(NewItem, ShoppingCart.ID) Result = True Catch Ex As Exception msg.ShowException(Ex) Result = False End Try ShoppingCart = Nothing Return Result End Function 'SP1A - Added Improved Inventory Checks Private Function AddToCart_IndividualFields(ByRef qtyError As Boolean) As Boolean Dim Result As Boolean = True Dim ShoppingCart As Orders.Order = BVC2004Store.GetCurrentShoppingCart Dim iQty As Integer = Convert.ToInt32(inQty.Text) If iQty >= p.MinimumQty Then ' Add to Cart Try Dim NewItem As New Orders.OrderItem NewItem.ProductID = p.ID NewItem.DisplayName = p.ProductName NewItem.Qty = iQty NewItem.Weight = p.ShippingWeight NewItem.ShippingCost = 0 ' HOTFIXD uncommented ' Check actual available Qty unless product is set to ignore If (Not p.InventoryNotAvailableStatus = Catalog.ProductInventoryStatus.Available) And (Not p.InventoryNotAvailableStatus = Catalog.ProductInventoryStatus.BackOrderedAllowPurchase) Then If (p.InventoryAvailableQty - p.InventoryLowStockNotice) < iQty Then NewItem.Qty = (p.InventoryAvailableQty - p.InventoryLowStockNotice) qtyError = True End If End If ' Store Product's adjusted price as the base order item price. ' This allows discounts,tax and coupons to make adjustments on the price ' of the item and the price of the attributes together. NewItem.OriginalBasePrice = p.SitePrice NewItem.SitePrice = p.SitePrice ' Add hidden properties to Extra Fields For q As Integer = 0 To p.Properties.Length - 1 If p.Properties(q).DisplayOnSite = False Then NewItem.ExtraInformation.ExtraInformationDictionary.AddExtraInformationDictionaryRow(p.Properties(q).DisplayName, CatalogServices.Products.GetPropertyValue(p.ID, p.Properties(q).ID)) End If Next ' Check for no selection but user Dim missingSelection As Boolean = False ' Add in Choice Selections Dim inventoryChoices As New Hashtable '2004.6 Dim accessoryChoicesCount As Integer = 0 For i As Integer = 0 To p.Choices.Length - 1 Dim con As System.Web.UI.WebControls.WebControl con = Me.FindControl("Choice" & p.Choices(i).ID) If Not con Is Nothing Then NewItem.DisplayDescription += "
    " & p.Choices(i).DisplayName & " " Select Case p.Choices(i).TypeCode Case Catalog.ProductChoiceType.MultipleChoiceField If CType(con, System.Web.UI.WebControls.DropDownList).SelectedIndex < 0 Then missingSelection = True Exit For End If For j As Integer = 0 To p.Choices(i).Items.Length - 1 If p.Choices(i).Items(j).ID = CType(con, System.Web.UI.WebControls.DropDownList).SelectedValue Then If p.Choices(i).Items(j).NullItem = True Then missingSelection = True Exit For Else 'SP1A - Add this ID to choices for inventory key generation inventoryChoices.Add(inventoryChoices.Count, p.Choices(i).Items(j).ID) NewItem.DisplayDescription += p.Choices(i).Items(j).DisplayValue NewItem.SitePrice += p.Choices(i).Items(j).PriceAdjustment NewItem.SiteCost += p.Choices(i).Items(j).CostAdjustment NewItem.Weight += p.Choices(i).Items(j).WeightAdjustment NewItem.ShippingCost += p.Choices(i).Items(j).ShippingCostAdjustment Exit For End If End If Next Case Catalog.ProductChoiceType.RadioButtonList If CType(con, System.Web.UI.WebControls.RadioButtonList).SelectedIndex < 0 Then missingSelection = True Exit For End If For k As Integer = 0 To p.Choices(i).Items.Length - 1 If p.Choices(i).Items(k).ID = CType(con, System.Web.UI.WebControls.RadioButtonList).SelectedValue Then If p.Choices(i).Items(k).NullItem = True Then missingSelection = True Exit For Else 'SP1A - Add this ID to choices for inventory key generation inventoryChoices.Add(inventoryChoices.Count, p.Choices(i).Items(k).ID) NewItem.DisplayDescription += p.Choices(i).Items(k).DisplayValue NewItem.SitePrice += p.Choices(i).Items(k).PriceAdjustment NewItem.SiteCost += p.Choices(i).Items(k).CostAdjustment NewItem.Weight += p.Choices(i).Items(k).WeightAdjustment NewItem.ShippingCost += p.Choices(i).Items(k).ShippingCostAdjustment Exit For End If End If Next Case Catalog.ProductChoiceType.TextField ' Required Text Field Checks If p.Choices(i).Html = "REQUIRED" Then If CType(con, TextBox).Text.Trim.Length < 1 Then missingSelection = True Exit Select End If End If NewItem.DisplayDescription += HttpUtility.HtmlEncode(CType(con, TextBox).Text.Trim) Case Catalog.ProductChoiceType.AccessoryCheckBox, _ Catalog.ProductChoiceType.AccessoryDropdownList, _ Catalog.ProductChoiceType.AccessoryRadioButtonList '2004.6 accessoryChoicesCount += 1 End Select End If con = Nothing Next ' SP1A New code to get inventory Key Dim inventoryChoiceIds(inventoryChoices.Count - 1) As Integer For q As Integer = 0 To inventoryChoices.Count - 1 inventoryChoiceIds(q) = inventoryChoices(q) Next Dim inventoryKey As String = CatalogServices.ProductChoices.GenerateInventoryKeyForItemIDs(inventoryChoiceIds) ' Inventory Specific SKU If Not p.InventoryKeys Is Nothing Then For i As Integer = 0 To p.InventoryKeys.Length - 1 If p.InventoryKeys(i).InventoryKey = inventoryKey Then If p.InventoryKeys(i).SKU.Trim.Length > 0 Then NewItem.ExtraInformation.ExtraInformationDictionary.AddExtraInformationDictionaryRow("BVDISPLAYSKU", p.InventoryKeys(i).SKU) End If Exit For End If Next End If Dim requestedQty As Integer = iQty '2004.6 If ((p.Choices.Length - accessoryChoicesCount) > 0) Then If inventoryKey.Trim.Length > 0 Then If IsInventoryKeyInStock(inventoryKey, requestedQty) = False Then msg.ShowWarning("The combination of options you have selected is currently out of stock. Please make another selection.") Return False End If End If End If ' Less are available then requested so adjust quantity If requestedQty <> iQty Then qtyError = True NewItem.Qty = requestedQty End If NewItem.InventoryKey = inventoryKey ' HOTFIXD If NewItem.InventoryKey.Trim.Length < 1 Then NewItem.InventoryKey = "0" End If NewItem.SiteCost = p.SiteCost NewItem.LineTotal = NewItem.SitePrice * CDbl(NewItem.Qty) NewItem.LineTaxTotal = 0 NewItem.ShipSeparately = p.ShipSeparately NewItem.NonShipping = p.NonShipping Select Case p.DropShipMode Case Catalog.ProductDropShipMode.ShipFromManufacturer If p.ManufacturerID > 0 Then NewItem.DropShipAddressID = p.ManufacturerID Else NewItem.DropShipAddressID = WebAppSettings.ContactAddress.ID End If Case Catalog.ProductDropShipMode.ShipFromSite NewItem.DropShipAddressID = WebAppSettings.ContactAddress.ID Case Catalog.ProductDropShipMode.ShipFromVendor If p.VendorID > 0 Then NewItem.DropShipAddressID = p.VendorID Else NewItem.DropShipAddressID = WebAppSettings.ContactAddress.ID End If End Select NewItem.DropShipMode = p.DropShipMode NewItem.TaxClass = p.TaxClass NewItem.TaxExempt = p.TaxExempt NewItem.Height = p.ShippingHeight NewItem.Width = p.ShippingWidth NewItem.Length = p.ShippingLength NewItem.MinimumQty = p.MinimumQty NewItem.ImageURL = ImageHelper.ConvertLocalImageToURL(p.ImageFileSmall) NewItem.GiftWrap = False NewItem.GiftWrapMessage = "" NewItem.GiftWrapAllowed = p.GiftWrapAllowed NewItem.ShippingCost += p.ExtraShipFee If missingSelection = False Then If NewItem.Qty > 0 Then OrderServices.AddItemToCart(NewItem, ShoppingCart.ID) End If Result = True Else msg.ShowWarning("Please make a selection for all choices before attempting to add to your cart.") Result = False End If Catch Ex As Exception msg.ShowException(Ex) Result = False End Try Else msg.ShowWarning("Minimum quantity is " & p.MinimumQty) Result = False End If ShoppingCart = Nothing Return Result End Function Private Sub WishListButton_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles WishListButton.Click MembershipServices.WishListAdd(BVC2004Store.GetCurrentUser, ViewState("ProductID")) Response.Redirect("myaccount_WishList.aspx") End Sub Private Sub QuickAddProduct(ByVal productID As String, ByVal quantity As Integer, ByVal redirect As Boolean) Dim ShoppingCart As Orders.Order = BVC2004Store.GetCurrentShoppingCart Dim localP As Catalog.Product = CatalogServices.Products.GetProductHeavy(productID, True) BVSoftware.BVC.Core.Pipelines.ProductPricingPipeline.Run(localP) Dim qtyError As Boolean = False If quantity < localP.MinimumQty Then quantity = localP.MinimumQty End If ' Send products with choices to usual page instead of QuickAdd. If Not localP.Choices Is Nothing Then If localP.Choices.Length > 0 Then Response.Redirect("productinfo.aspx?productID=" & localP.ID) End If End If ' Add to Cart Try Dim NewItem As New Orders.OrderItem NewItem.ProductID = localP.ID NewItem.DisplayName = localP.ProductName NewItem.Qty = quantity ' Store Product's adjusted price as the base order item price. ' This allows discounts,tax and coupons to make adjustments on the price ' of the item and the price of the attributes together. ' Check actual available Qty unless product is set to ignore If (Not localP.InventoryNotAvailableStatus = Catalog.ProductInventoryStatus.Available) And (Not localP.InventoryNotAvailableStatus = Catalog.ProductInventoryStatus.BackOrderedAllowPurchase) Then '2004.6 If (localP.InventoryAvailableQty - localP.InventoryLowStockNotice) < quantity Then NewItem.Qty = (localP.InventoryAvailableQty - localP.InventoryLowStockNotice) qtyError = True End If End If NewItem.OriginalBasePrice = localP.SitePrice NewItem.SitePrice = localP.SitePrice ' Add hidden properties to Extra Fields For q As Integer = 0 To localP.Properties.Length - 1 If localP.Properties(q).DisplayOnSite = False Then NewItem.ExtraInformation.ExtraInformationDictionary.AddExtraInformationDictionaryRow(localP.Properties(q).DisplayName, CatalogServices.Products.GetPropertyValue(localP.ID, localP.Properties(q).ID)) End If Next ' Add in Choice Selections 'For i As Integer = 0 To p.Choices.Length - 1 ' Dim con As System.Web.UI.WebControls.WebControl ' con = Me.FindControl("Choice" & p.Choices(i).ID) ' If Not con Is Nothing Then ' NewItem.DisplayDescription += "
    " & p.Choices(i).DisplayName & " " ' Select Case p.Choices(i).TypeCode ' Case Catalog.ProductChoiceType.MultipleChoiceField ' For j As Integer = 0 To p.Choices(i).Items.Length - 1 ' If p.Choices(i).Items(j).ID = CType(con, System.Web.UI.WebControls.DropDownList).SelectedValue Then ' NewItem.DisplayDescription += p.Choices(i).Items(j).DisplayValue ' NewItem.SitePrice += p.Choices(i).Items(j).PriceAdjustment ' NewItem.SiteCost += p.Choices(i).Items(j).CostAdjustment ' Exit For ' End If ' Next ' Case Catalog.ProductChoiceType.RadioButtonList ' For k As Integer = 0 To p.Choices(i).Items.Length - 1 ' If p.Choices(i).Items(k).ID = CType(con, System.Web.UI.WebControls.RadioButtonList).SelectedValue Then ' NewItem.DisplayDescription += p.Choices(i).Items(k).DisplayValue ' NewItem.SitePrice += p.Choices(i).Items(k).PriceAdjustment ' NewItem.SiteCost += p.Choices(i).Items(k).CostAdjustment ' Exit For ' End If ' Next ' Case Catalog.ProductChoiceType.TextField ' NewItem.DisplayDescription += CType(con, TextBox).Text.Trim ' End Select ' End If ' con = Nothing 'Next ' HOTFIXD If NewItem.InventoryKey.Trim.Length < 1 Then NewItem.InventoryKey = "0" End If NewItem.SiteCost = localP.SiteCost NewItem.LineTotal = NewItem.SitePrice * CDbl(NewItem.Qty) NewItem.LineTaxTotal = 0 NewItem.ShipSeparately = localP.ShipSeparately NewItem.NonShipping = localP.NonShipping Select Case localP.DropShipMode Case Catalog.ProductDropShipMode.ShipFromManufacturer If localP.ManufacturerID > 0 Then NewItem.DropShipAddressID = localP.ManufacturerID Else NewItem.DropShipAddressID = WebAppSettings.ContactAddress.ID End If Case Catalog.ProductDropShipMode.ShipFromSite NewItem.DropShipAddressID = WebAppSettings.ContactAddress.ID Case Catalog.ProductDropShipMode.ShipFromVendor If localP.VendorID > 0 Then NewItem.DropShipAddressID = localP.VendorID Else NewItem.DropShipAddressID = WebAppSettings.ContactAddress.ID End If End Select NewItem.DropShipMode = localP.DropShipMode NewItem.TaxClass = localP.TaxClass NewItem.TaxExempt = localP.TaxExempt NewItem.Height = localP.ShippingHeight NewItem.Width = localP.ShippingWidth NewItem.Length = localP.ShippingLength NewItem.Weight = localP.ShippingWeight NewItem.MinimumQty = localP.MinimumQty NewItem.ImageURL = ImageHelper.ConvertLocalImageToURL(localP.ImageFileSmall) NewItem.GiftWrap = False NewItem.GiftWrapMessage = "" NewItem.GiftWrapAllowed = localP.GiftWrapAllowed NewItem.ShippingCost += localP.ExtraShipFee '2004.6 If NewItem.Qty > 0 Then OrderServices.AddItemToCart(NewItem, ShoppingCart.ID) End If Catch Ex As Exception msg.ShowException(Ex) End Try If redirect = True Then If qtyError = True Then Response.Redirect("cart.aspx?QTYERR=1") Else Response.Redirect("cart.aspx") End If End If End Sub Private Sub btnAmazon_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) End Sub Private Sub AddAccessories() If Not p Is Nothing Then For i As Integer = 0 To p.Choices.Length - 1 Select Case p.Choices(i).TypeCode Case Catalog.ProductChoiceType.AccessoryCheckBox Dim con As System.Web.UI.WebControls.CheckBoxList con = Me.FindControl("Choice" & p.Choices(i).ID) If Not con Is Nothing Then For k As Integer = 0 To con.Items.Count - 1 If con.Items(k).Selected = True Then For j As Integer = 0 To p.Choices(i).Items.Length - 1 If p.Choices(i).Items(j).ID = con.Items(k).Value Then If p.Choices(i).Items(j).NullItem = False Then Me.QuickAddProduct(p.Choices(i).Items(j).DisplayValue, p.Choices(i).Items(j).PriceAdjustment, False) End If Exit For End If Next End If Next End If Case Catalog.ProductChoiceType.AccessoryDropdownList Dim con As System.Web.UI.WebControls.DropDownList con = Me.FindControl("Choice" & p.Choices(i).ID) If Not con Is Nothing Then If con.SelectedItem Is Nothing Then Exit Select Else For j As Integer = 0 To p.Choices(i).Items.Length - 1 If p.Choices(i).Items(j).ID = con.SelectedValue Then If p.Choices(i).Items(j).NullItem = False Then Me.QuickAddProduct(p.Choices(i).Items(j).DisplayValue, p.Choices(i).Items(j).PriceAdjustment, False) End If Exit For End If Next End If End If Case Catalog.ProductChoiceType.AccessoryRadioButtonList Dim con As System.Web.UI.WebControls.RadioButtonList con = Me.FindControl("Choice" & p.Choices(i).ID) If Not con Is Nothing Then If con.SelectedItem Is Nothing Then Exit Select Else For j As Integer = 0 To p.Choices(i).Items.Length - 1 If p.Choices(i).Items(j).ID = con.SelectedValue Then If p.Choices(i).Items(j).NullItem = False Then Me.QuickAddProduct(p.Choices(i).Items(j).DisplayValue, p.Choices(i).Items(j).PriceAdjustment, False) End If Exit For End If Next End If End If End Select Next End If End Sub End Class