Imports BVSoftware.BVC.Core Imports System.Text Public Class cart Inherits BaseStorePage Protected WithEvents lblSubTotal As System.Web.UI.WebControls.Label Protected WithEvents btnContinueShopping As System.Web.UI.WebControls.ImageButton Protected WithEvents btnCheckout As System.Web.UI.WebControls.ImageButton Private sItemClass = "Item" Protected WithEvents EditButton As System.Web.UI.WebControls.ImageButton Protected WithEvents MetaDescriptionControl As BVSoftware.WebControls.MetaTag Protected WithEvents MetaKeywordsControl As BVSoftware.WebControls.MetaTag Protected WithEvents TitleLabel As System.Web.UI.WebControls.Label Protected WithEvents lblcart As System.Web.UI.WebControls.Label Protected WithEvents btnUpdateTotals As System.Web.UI.WebControls.ImageButton Protected WithEvents tblItems As System.Web.UI.WebControls.Table Protected WithEvents lblMakeChanges As System.Web.UI.WebControls.Label Protected WithEvents lblGiftWrapCharge As System.Web.UI.WebControls.Label Protected WithEvents lblWishList As System.Web.UI.WebControls.Label Protected WithEvents dgWishList As System.Web.UI.WebControls.DataGrid Protected WithEvents CSSTag1 As BVSoftware.WebControls.CSSTag Protected WithEvents msg As BVSoftware.WebControls.WebPageMessage Private sAlternateItemClass = "AlternateItem" #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 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 btnCheckout.ImageUrl = ImageHelper.GetThemedButton("Checkout.gif") btnContinueShopping.ImageUrl = ImageHelper.GetThemedButton("KeepShopping.gif") btnUpdateTotals.ImageUrl = ImageHelper.GetThemedButton("Update.gif") Me.lblMakeChanges.Text = Content.SiteTerms.GetTerm("MakeAnyChangesAbove") Me.TitleLabel.Text = Content.SiteTerms.GetTerm("ShoppingCart") PageTitle = Content.SiteTerms.GetTerm("ShoppingCart") End If ' Forward to Checkout if requested If Request.Params("FTC") <> Nothing Then If Request.Params("FTC") = "1" Then ForwardToCheckout() End If End If If Request.Params("QTYERR") <> Nothing Then ShowQtyError() End If LoadCartItems() If Not Page.IsPostBack Then LoadWishList() End If End Sub Private Sub ShowQtyError() msg.ShowInformation("You have requested more of an item than the store has available. The maximum available quantity has been added to your cart.") End Sub Private Sub LoadCartItems() tblItems.Rows.Clear() AddHeaderRow() If BVC2004Store.UserHasCart = True Then ' Set up connection to Biz Objects Dim thisOrder As Orders.Order = BVC2004Store.GetCurrentShoppingCart() Pipelines.CartPipeline.Run(thisOrder) ' Print Number of Results If thisOrder.ItemCount > 0 Then If thisOrder.ItemCount = 1 Then lblcart.Text = "1 " & Content.SiteTerms.GetTerm("Product") Else lblcart.Text = thisOrder.ItemCount & " " & Content.SiteTerms.GetTerm("Products") End If btnCheckout.Visible = True Else SetEmptyCartMode() End If Dim totalItems As Integer = 0 Dim i As Integer = 0 For Each o As Orders.OrderItem In thisOrder.Items i += 1 AddItemRow(o, i) totalItems += o.Qty Next ' Order Limits and Minimums Dim limitError As String = "" If OrderServices.CheckOrderMinimumsAndMaximums(thisOrder, limitError) = False Then msg.ShowWarning(limitError) btnCheckout.Visible = False End If If thisOrder.GiftWrapCharge > 0 Then Me.lblGiftWrapCharge.Visible = True Me.lblGiftWrapCharge.Text = "Gift Wrap: " & String.Format("{0:c}", thisOrder.GiftWrapCharge) Else Me.lblGiftWrapCharge.Visible = False End If If thisOrder.OrderDiscountsTotal > 0 Then lblSubTotal.Text = "" lblSubTotal.Text += "Order Discounts: " & String.Format("{0:c}", thisOrder.OrderDiscountsTotal) lblSubTotal.Text += "" lblSubTotal.Text += "
Subtotal: " & String.Format("{0:c}", thisOrder.SubTotal) Else lblSubTotal.Text = "Subtotal: " & String.Format("{0:c}", thisOrder.SubTotal) End If thisOrder = Nothing Else ' No Cart ID so set to empty cart SetEmptyCartMode() End If End Sub Private Sub SetEmptyCartMode() lblcart.Text = Content.SiteTerms.GetTerm("EmptyCart") btnCheckout.Visible = False Me.btnUpdateTotals.Visible = False End Sub Private Sub AddHeaderRow() Dim tr As New TableRow Dim tcImage As New TableCell Dim tcProduct As New TableCell Dim tcGift As New TableCell Dim tcPrice As New TableCell Dim tcQty As New TableCell Dim tcTotal As New TableCell Dim tcDelete As New TableCell tcImage.CssClass = "Header" tcImage.Text = " " tcProduct.CssClass = "Header" tcProduct.Text = "Product" tcGift.CssClass = "Header" tcGift.Text = "Gift" tcPrice.CssClass = "Header" tcPrice.Text = "Price" tcQty.CssClass = "Header" tcQty.Text = "Qty" tcTotal.CssClass = "Header" tcTotal.Text = "Total" tcDelete.CssClass = "Header" tcDelete.Text = " " If WebAppSettings.ShowImagesInCart = True Then tr.Cells.Add(tcImage) End If tr.Cells.Add(tcProduct) If WebAppSettings.GiftWrapEnabled = True Then tr.Cells.Add(tcGift) End If tr.Cells.Add(tcPrice) tr.Cells.Add(tcQty) tr.Cells.Add(tcTotal) tr.Cells.Add(tcDelete) tblItems.Rows.Add(tr) End Sub Private Sub AddItemRow(ByVal o As Orders.OrderItem, ByVal rowindex As Integer) Dim tr As New TableRow Dim tcImage As New TableCell Dim tcProduct As New TableCell Dim tcGift As New TableCell Dim tcPrice As New TableCell tcPrice.HorizontalAlign = HorizontalAlign.Right Dim tcQty As New TableCell Dim tcTotal As New TableCell tcTotal.HorizontalAlign = HorizontalAlign.Right Dim tcDelete As New TableCell If rowindex Mod 2 > 0 Then tcImage.CssClass = "CartItem" tcProduct.CssClass = "CartItem" tcGift.CssClass = "CartItem" tcPrice.CssClass = "CartItem" tcQty.CssClass = "CartItem" tcTotal.CssClass = "CartItem" tcDelete.CssClass = "CartItem" Else tcImage.CssClass = "CartAlternateItem" tcProduct.CssClass = "CartAlternateItem" tcGift.CssClass = "CartAlternateItem" tcPrice.CssClass = "CartAlternateItem" tcQty.CssClass = "CartAlternateItem" tcTotal.CssClass = "CartAlternateItem" tcDelete.CssClass = "CartAlternateItem" End If 'Image field If o.ImageURL.Length > 0 Then Dim sb As New StringBuilder sb.Append("") tcImage.Text = sb.ToString Else tcImage.Text = " " End If ' Product Field Dim description As String = "" & o.DisplayName & "" description += o.DisplayDescription tcProduct.Text = description ' Gift Field If o.GiftWrapAllowed = True Then Dim chk As New CheckBox chk.ID = "chkGiftWrap" & o.ID chk.Checked = o.GiftWrap tcGift.Controls.Add(chk) Else tcGift.Controls.Add(New LiteralControl(" ")) End If ' Price Field If o.OriginalBasePrice > o.AdjustedSitePrice Then tcPrice.Text = "" & String.Format("{0:c}", o.OriginalBasePrice) & "
" tcPrice.Text += String.Format("{0:c}", o.AdjustedSitePrice) Else tcPrice.Text = String.Format("{0:c}", o.AdjustedSitePrice) End If ' Qty Field Dim t As New TextBox t.ID = "EditQty" & o.ID t.CssClass = "FormInput" t.Columns = 4 t.MaxLength = 4 If Not Page.IsPostBack Then t.Text = o.Qty End If '2004.7 If o.ShipSeparately = True Then t.ReadOnly = True End If tcQty.Controls.Add(t) ' Total Field tcTotal.Text = String.Format("{0:c}", o.LineTotal) ' Delete Button Dim delButton As New ImageButton delButton.ImageUrl = ImageHelper.GetThemedButton("Delete.gif") delButton.AlternateText = "Delete" delButton.CommandArgument = o.ID delButton.ID = "DeleteButton" & o.ID AddHandler delButton.Click, AddressOf Me.btnDelete_Click tcDelete.Controls.Add(delButton) ' Add Cells If WebAppSettings.ShowImagesInCart = True Then tr.Cells.Add(tcImage) End If tr.Cells.Add(tcProduct) If WebAppSettings.GiftWrapEnabled = True Then tr.Cells.Add(tcGift) End If tr.Cells.Add(tcPrice) tr.Cells.Add(tcQty) tr.Cells.Add(tcTotal) tr.Cells.Add(tcDelete) ' Add Row tblItems.Rows.Add(tr) End Sub Sub ForwardToCheckout() Dim c As Orders.Order c = BVC2004Store.GetCurrentShoppingCart If Not c Is Nothing Then c.AffiliateID = ContactServices.Affiliates.GetCurrentAffiliateID OrderServices.SaveOrder(c) 'Force Shipping Recalculation ShippingServices.ClearAllShippingMethodsFromOrder(c) End If c = Nothing ' Pass Credentials for authenticated users across SSL Dim Crypto As New BVSoftware.Encryption.DesEncryption Dim sURL As String = "" sURL = WebAppSettings.CheckoutRoot & "Checkout_Login.aspx" sURL += "?CID=" & Server.UrlEncode(Crypto.Encode(Session("cartID"))) If BVC2004Store.IsUserAuthenticated = True Then Dim thisUser As Membership.UserAccount = BVC2004Store.GetCurrentUser If Not thisUser Is Nothing Then sURL += "&AUID=" & Server.UrlEncode(Crypto.Encode(thisUser.ID)) End If Else Dim checkCookie As HttpCookie checkCookie = Request.Cookies(WebAppSettings.UserCookieName) If Not checkCookie Is Nothing Then sURL += "&UN=" & Server.UrlEncode(Crypto.Encode(checkCookie.Value)) End If checkCookie = Nothing End If Page.SmartNavigation = False Response.Redirect(sURL) End Sub Private Sub btnUpdateTotals_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnUpdateTotals.Click If UpdateCart() = False Then Response.Redirect("cart.aspx?QTYERR=1") Else Response.Redirect("cart.aspx") End If End Sub Private Function UpdateCart() As Boolean Dim result As Boolean = True Dim currentCart As Orders.Order currentCart = BVC2004Store.GetCurrentShoppingCart For i As Integer = 0 To currentCart.Items.Length - 1 With currentCart.Items(i) '2004.6 Dim oldQty As Integer = .Qty ' QTY Dim qtyBox As TextBox = tblItems.FindControl("EditQty" & .ID) If Not qtyBox Is Nothing Then Try Dim newQty As Integer = Integer.Parse(qtyBox.Text) ' Check to make sure product still exists and is active Dim productGone As Boolean = False Dim p As Catalog.Product = CatalogServices.Products.GetProductHeavy(.ProductID, False) If Not p Is Nothing Then If p.ID <> .ProductID Then productGone = True End If If p.Status = Catalog.ProductStatus.Disabled Then qtyBox.Text = 0 newQty = 0 msg.ShowWarning("Some of the products you requested are no longer available and have been removed from your cart.") result = False End If Else productGone = True End If ' Ignore Gift Certificates for product gone check If .ProductID = "GIFTCERTIFICATE" Then productGone = False End If If productGone = True Then qtyBox.Text = 0 newQty = 0 msg.ShowWarning("Some of the products you requested are no longer available and have been removed from your cart.") result = False End If If newQty = 0 Then '2004.6 If WebAppSettings.DisableStrictInventory = False Then OrderServices.OrderItems.Delete(.ID, True) Else OrderServices.OrderItems.Delete(.ID, False) End If Else If newQty < .MinimumQty Then newQty = .MinimumQty End If If newQty > 0 Then ' INVENTORY CHECKS ' Set available to requested in case anything else fails ' Better to receive the order and correct than deny a possible order ' NOTE: can be set to zero instead to deny first instead Dim availableInventoryQty As Integer = 0 ' Find out how many of the item are available If WebAppSettings.DisableInventory = False Then Dim productDoesNotTrackInventory As Boolean = False If Not p Is Nothing Then If (Not p.InventoryNotAvailableStatus = Catalog.ProductInventoryStatus.Available) And (Not p.InventoryNotAvailableStatus = Catalog.ProductInventoryStatus.BackOrderedAllowPurchase) Then If .InventoryKey <> "0" Then If Not p.InventoryKeys Is Nothing Then For q As Integer = 0 To p.InventoryKeys.Length - 1 If p.InventoryKeys(q).InventoryKey = .InventoryKey Then availableInventoryQty = p.InventoryKeys(q).Qty End If Next End If Else ' Need old quantity in the comparison if strict, but since it's added in later don't put in available Dim adjustStrict As Integer = 0 If WebAppSettings.DisableStrictInventory = False Then adjustStrict = oldQty End If If ((p.InventoryAvailableQty + adjustStrict) - p.InventoryLowStockNotice) < newQty Then availableInventoryQty = (p.InventoryAvailableQty - p.InventoryLowStockNotice) Else availableInventoryQty = newQty End If End If Else ' Allow sale regardless of inventory. productDoesNotTrackInventory = True availableInventoryQty = newQty End If End If ' Check to see if additional items are requested If productDoesNotTrackInventory = False Then If WebAppSettings.DisableStrictInventory = False Then ' Strict inventory is already enabled If oldQty < newQty Then ' items in cart have already been accounted for in inventory adjustments ' so add old quantity to available quantity for checks availableInventoryQty = oldQty + availableInventoryQty Else ' Inventory already adjusted, don't worry about subtractions availableInventoryQty = newQty End If End If End If Else 'Inventory Disabled, ignore available qty. availableInventoryQty = newQty End If If availableInventoryQty < newQty Then .Qty = availableInventoryQty qtyBox.Text = .Qty 'qtyBox.CssClass = "FormInputError" ShowQtyError() .LineTotal = availableInventoryQty * .SitePrice result = False Else .Qty = newQty .LineTotal = newQty * .SitePrice End If ' 2004.6 If WebAppSettings.DisableStrictInventory = False Then If WebAppSettings.DisableInventory = False Then If .Qty <> oldQty Then If .InventoryKey <> "0" Then CatalogServices.ProductInventory.AdjustProductKeyInventory(.ProductID, .InventoryKey, oldQty - .Qty) Else CatalogServices.ProductInventory.AdjustProductInventory(.ProductID, oldQty - .Qty) End If End If End If End If p = Nothing End If End If Catch ex As Exception End Try End If 'Gift Checkboxes Dim chkGift As CheckBox = tblItems.FindControl("chkGiftWrap" & .ID) If Not chkGift Is Nothing Then Try .GiftWrap = chkGift.Checked Catch ex As Exception End Try End If End With Next Pipelines.CartPipeline.Run(currentCart) Return result End Function Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) UpdateCart() Try Dim deleteID As Integer = CType(sender, ImageButton).CommandArgument ' 2004.6 If WebAppSettings.DisableStrictInventory = False Then OrderServices.OrderItems.Delete(deleteID, True) Else OrderServices.OrderItems.Delete(deleteID, False) End If Catch ex As Exception End Try BVC2004Store.GetCurrentShoppingCart.CleanUnusedPackages() Response.Redirect("cart.aspx") End Sub Private Sub btnCheckout_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnCheckout.Click If UpdateCart() = True Then ForwardToCheckout() End If End Sub Private Sub KeepShopping() UpdateCart() 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 btnContinueShopping_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnContinueShopping.Click KeepShopping() End Sub Private Sub LoadWishList() Me.lblWishList.Visible = False Me.dgWishList.Visible = False If WebAppSettings.WishListShowOnCart = True Then If BVC2004Store.IsUserAuthenticated = True Then ViewState("UserID") = BVC2004Store.GetCurrentUser.ID Dim dt As DataTable = MembershipServices.GetWishListForUser(BVC2004Store.GetCurrentUser) If Not dt Is Nothing Then If dt.Rows.Count > 0 Then Me.lblWishList.Visible = True lblWishList.Text = Content.SiteTerms.GetTerm("WishList") Me.dgWishList.Visible = True Me.dgWishList.DataSource = dt Me.dgWishList.DataBind() End If End If End If End If End Sub Private Sub btnContinueShopping2_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) KeepShopping() End Sub Public Sub dgItems_Delete(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgWishList.DeleteCommand Dim deleteID As String = dgWishList.DataKeys(e.Item.ItemIndex) MembershipServices.WishListRemove(ViewState("UserID"), deleteID) LoadWishList() End Sub Public Sub dgItems_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgWishList.ItemDataBound If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then Dim DeleteButton As System.Web.UI.WebControls.ImageButton DeleteButton = e.Item.FindControl("DeleteButton") If Not DeleteButton Is Nothing Then DeleteButton.ImageUrl = ImageHelper.GetThemedButton("Delete.gif") End If Dim editID As String = dgWishList.DataKeys(e.Item.ItemIndex) Dim spd As New UIControls.DetailProductDisplay spd.LoadProduct(editID) e.Item.Cells(0).Controls.Add(spd) End If End Sub End Class