Janise,
I apologize for the delay. I went out of town and got caught up in a project. Here is the code I promised. This contains functions associate with what we discussed.
For the sake of speed and the ability to use my companies database I had to make some COM components. However the functionality of the code is still there and should point you in the right direction.
Please feel free to ask me anything. If you do not understand a compiled function let me know and I will detail out the compiled part here.
I apologize for the delay again and will do better in the future.
Cassidy
-----------------------------------
Function Wishlist_Initialize()
'Is the B2C Module being loaded, if yes then load a wishlist based on whether the cookie has a valid wishlist ID
'and whether the wishlist has a customer id on it or not.
If Not Session("B2BModule") Then
'Since Cart_Initialize was called already, assume that the Wishlist ID has been loaded.
If Not IsBlank(Session("sWishlistID")) Then
'Is the User Logged in. If Not then simply check the current cart and then load a corresponding cart
If Not LoggedIn() Then
If Wishlist_HasOwner(Session("sWishlistID")) Then
Session("sWishlistID") = ""
End If
Call Wishlist_Load()
Else
'If the user is logged in then get the correct wishlist for this customer and merge the existing wishlist.
Session("sWishlistID") = Wishlist_MergeWishlists(Session("sWishlistID"))
Call Wishlist_Load()
End If
'First time user,load a blank cart and then save the cookie to the user's machine.
Else
Call Wishlist_Load()
End If
Else
'If logged in then load the default wishlist
If LoggedIn() Then
sWishListID = Wishlist_GetDefaultCustomerWishlist(Session("sCustomerID"),Session("nContactNO"))
If IsBlank(sWishListID) Then
Session("sWishListID") = ""
Else
Session("sWishListID") = sWishListID
End If
Wishlist_Load()
End If
End If
'Write the cookie back with the correct Wishlist ID.
SaveCookie()
End Function
'************************************************************************
' Wishlist_GetDefaultCustomerWishlist()
' This function grabs from the database a wishlist id for a given Customer ID and contact Number
Function Wishlist_GetDefaultCustomerWishlist(sCustID,nContactNo)
Dim WSObj, Rs,sWishlistID,sSql
If Session("PrimaryUser") Then
sSql = "Select * from WISHLIST where CUSTOMER_ID = '"& sCustID & "' and CONTACT_NO is null and NAME = 'PRIMARY_WISHLIST'"
Else
sSql = "Select * from WISHLIST where CUSTOMER_ID = '"& sCustID & "' and CONTACT_NO = '" & nContactNo & "' and NAME = 'PRIMARY_WISHLIST'"
End If
sWishlistID = null
Set WSObj = Server.CreateObject("VwebSls.Sales")
Set Rs = WSObj.Query(Session("VWEB"),sSql)
If Not Rs.EOF Then
sWishlistID = Rs("ID")
End If
Set WSObj = Nothing
Set Rs = Nothing
Wishlist_GetDefaultCustomerWishlist = sWishlistID
End Function
'************************************************************************
' Wishlist_Load()
' Loads a Wishlist for a given session via the session("sWishlistID") variable, if this variable is empty
' then it loads a brand new Wishlist. If the Session variable has a value and the Wishlist can not be found
' then it loads a new Wishlist too.
Function Wishlist_Load()
Dim WishlistObj, Rs
Set WishlistObj = Server.CreateObject("VwebSls.Wishlist")
'Check to see whether a Wishlist exists in the Session variable first
If Not IsBlank(Session("sWishlistID")) Then
Set Rs = WishlistObj.Load(Session("VWEB"), Session("sWishlistID"))
If Rs.EOF Then
'Wishlist exists but is not found in the database, load a brand new one and save its id to the session variable.
Rs.AddNew()
Rs("NAME") = "PRIMARY_WISHLIST"
Rs("CUSTOMER_ID") = Session("sCustomerID")
Rs("CONTACT_NO") = Session("nContactNO")
Rs.Update()
Set Rs = WishlistObj.Save(Session("VWEB"),Rs)
Session("sWishlistID") = Rs("ID")
End If
Else
Set Rs = WishlistObj.Load(Session("VWEB"),"")
If Rs.EOF Then
Rs.AddNew()
Rs("NAME") = "PRIMARY_WISHLIST"
Rs("CUSTOMER_ID") = Session("sCustomerID")
Rs("CONTACT_NO") = Session("nContactNO")
Rs.Update()
Set Rs = WishlistObj.Save(Session("VWEB"),Rs)
Session("sWishlistID") = Rs("ID")
End If
End If
Set WishlistObj = Nothing
Set Rs = Nothing
End Function
'************************************************************************
' Wishlist_Add()
' Add a part qty to the current Wishlist
Function Wishlist_Add(sPartID,sComments)
Dim Wishlist
Dim Rs, Rs2
' Get the shopping cart from session memory
Set Wishlist = Server.CreateObject("VwebSls.Wishlist")
If sComments = Null Then
Set Rs = Wishlist.Load(Session("VWEB"), Session("sWishlistID"))
Else
Set Rs = Wishlist.Load(Session("VWEB"), Session("sWishlistID"),"WITH_TEXT_DATA")
End If
' Add the parts to the Wishlist
If Not Rs.EOF Then
Set Rs2 = Rs("WISHLIST_LINE").Value
Rs2.Filter = "PART_ID = '" & sPartID & "'"
'If Part does not exist in the wishlist then add it else change the comments
If Rs2.EOF Then
Rs2.AddNew()
Rs2("PART_ID") = sPartID
If Not IsBlank(sComments) Then Rs2("COMMENTS_DATA") = sComments
Else
If Not IsBlank(sComments) Then Rs2("COMMENTS_DATA") = sComments
End If
Rs2.Update
Rs.Update
Set Rs = Wishlist.Save(Session("VWEB"), Rs)
End If
Set Wishlist = Nothing
Set Rs = Nothing
End Function
'************************************************************************
' Wishlist_HasOwner()
' This function will determine whether a wishlist which has been loaded has a Customer ID on it.
Function Wishlist_HasOwner(sWishlistID)
Dim Rs,WishlistObj, bExists
bExists = False
Set WishlistObj = Server.CreateObject("VwebSls.Wishlist")
Set Rs = WishlistObj.Load(Session("VWEB"), sWishlistID)
If Not Rs.EOF Then
If Not IsBlank(Rs("CUSTOMER_ID").value) Then
bExists = True
End If
End If
Set Rs = Nothing
Set WishlistObj = Nothing
Wishlist_HasOwner = bExists
End Function
'************************************************************************
' Wishlist_MergeWishlists(sCurrentWishlistID)
'This function is used when the user has logged in(under the B2C style website) and you merge the current wishlist with
'the default wishlist used by this customer
Function Wishlist_MergeWishlists(sCurrentWishlistID)
'The current wishlist does not belong to anyone. However the user might either have a wishlist in the system
'or you might have to create a wishlist.
'First check whether the user has a default wishlist.
Dim WishObj, RsWish,RsWishlist
Set WishObj = Server.CreateObject("VwebSls.Wishlist")
sDefaultWishlistID = Wishlist_GetDefaultCustomerWishlist(Session("sCustomerID"),Session("nContactNO"))
If Not IsBlank(sDefaultWishlistID) Then
Set RsWish = WishObj.Prepare(Session("VWEB"),"MERGE_WISHLISTS")
If RsWish.EOF Then
RsWish.AddNew()
RsWish("FROM_ID") = sCurrentWishlistID
RsWish("TO_ID") = sDefaultWishlistID
RsWish.Update
Set RsWish = WishObj.Save(Session("VWEB"),RsWish)
Wishlist_MergeWishlists = RsWish("TO_ID")
End If
'Customer does not have a default Wishlist, make the current one his since it does not belong to anyone.
Else
Set RsWishlist = WishObj.Load(Session("VWEB"),sCurrentWishlistID)
If Not RsWishlist.EOF Then
RsWishlist("NAME") = "PRIMARY_WISHLIST"
RsWishlist("CUSTOMER_ID") = Session("sCustomerID")
RsWishlist("CONTACT_NO") = Session("nContactNO")
RsWishlist.Update
Set RsWishlist = WishObj.Save(Session("VWEB"),RsWishlist)
End If
'Return the same Wishlist ID as the default Wishlist for this customer.
Wishlist_MergeWishlists = sCurrentWishlistID
End If
Set WishObj = Nothing
Set RsWish = Nothing
Set RsWishlist = Nothing
'Delete the wishlist which was just merged if there are no user's associated with it.
'If Not Wishlist_HasOwner(sCurrentWishlistID) Then
' Wishlist_DeleteWishlist(sCurrentWishlistID)
'End If
End Function
'************************************************************************
'Wishlist_DeleteWishlist(sCurrentWishlistID)
'This function deletes a wishlist from the system.
Function Wishlist_DeleteWishlist(sWishlistID)
Dim WishlistObj, Rs
Set WishlistObj = Server.CreateObject("VwebSls.Wishlist")
Set Rs = WishlistObj.Load(Session("VWEB"),sWishlistID)
If Not Rs.EOF Then
Rs("RECORD_IDENTITY") = "DELETE"
Rs.Update()
Set Rs = WishlistObj.Save(Session("VWEB"),Rs)
End If
Set WishlistObj = Nothing
Set Rs = Nothing
End Function
'************************************************************************
'Wishlist_DeleteItem(sPartID)
'This function deletes items from the wishlist
Function Wishlist_DeleteItem(sPartID)
Dim Obj, Rs,RsLine
Set Obj = Server.CreateObject("VwebSls.Wishlist")
Set Rs = Obj.Load(Session("VWEB"),Session("sWishlistID"))
If Not Rs.EOF Then
Set RsLine = Rs("WISHLIST_LINE").value
RsLine.Filter = "PART_ID = '"& sPartID & "'"
If Not RsLine.EOF Then
RsLine("RECORD_IDENTITY") = "DELETE"
RsLine.Update()
End If
Rs.Update()
Set Rs = Obj.Save(Session("VWEB"),Rs)
End If
Set Obj = Nothing
Set Rs = Nothing
Set RsLine = Nothing
End Function
'************************************************************************
'ValidWishlistName(sWishlistName)
'This function determines that the wishlist name being given does not already exist in the system
'for a given customer and contact no
Function ValidWishlistName(sWishlistName)
Dim QueryObj2,bSuccess, Rs,sSql
bSuccess = False
If Session("PrimaryUser") Then
sSql = "select * from WISHLIST where NAME = '" & sWishlistName & "' and CUSTOMER_ID = '" & Session("sCustomerID") & "' and CONTACT_NO is null "
Else
sSql = "select * from WISHLIST where NAME = '" & sWishlistName & "' and CUSTOMER_ID = '" & Session("sCustomerID") & "' and CONTACT_NO = " & Session("nContactNO")
End If
Set QueryObj2 = Server.CreateObject("VwebSls.Sales")
Set Rs = QueryObj2.Query(Session("VWEB"),sSql)
If Rs.EOF Then
bSuccess = True
End If
Set QueryObj2 = Nothing
Set Rs = Nothing
ValidWishlistName = bSuccess
End Function
'************************************************************************
'Create_NewWishlist(sWishlistName)
'Creates a new wishlist for a given customer and contact number and then resets the Current Wishlist being loaded to the new one.
Function Create_NewWishlist(sWishlistName)
Dim WishlistObj2, RsWishlist
Set WishlistObj2 = Server.CreateObject("VwebSls.Wishlist")
Set RsWishlist = WishlistObj2.Load(Session("VWEB"),"")
If RsWishlist.EOF Then
RsWishlist.AddNew()
RsWishlist("NAME") = sWishlistName
RsWishlist("CUSTOMER_ID") = Session("sCustomerID")
RsWishlist("CONTACT_NO") = Session("nContactNO")
RsWishlist.Update()
Set RsWishlist = WishlistObj2.Save(Session("VWEB"),RsWishlist)
Session("sWishlistID") = RsWishlist("ID")
End If
Set WishlistObj2 = Nothing
Set RsWishlist = Nothing
End Function
%>
---------------------------