In a BeerHouse website, I made a shopping cart a little different from the original one : the shoppingcart is not cleared after the order is passed (I won't explain why we did that but it feets our needs...).
I just deleted the line : "Me.Profile.ShoppingCart.Clear()" in the ShoppingCart.aspx code behind page.
Accordingly, the storekeeper should be able to clear all the shopping carts at a time (from an admin page, just clicking on a button).
I wrote this method in the admin page :
Private allProfiles As ProfileInfoCollection = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each info As ProfileInfo In allProfiles
Dim userProfile As ProfileCommon = Profile.GetProfile(info.UserName)
userProfile.ShoppingCart.Clear()
Next
End Sub
Running this code, no error appears but the shopping carts are not cleared...
Most of the time, when a profile property changes, ASP.NET can detect this and will save the profile automatically.
But this detection mechanism usually only works with simple types, like integers and strings. Sometimes when working with complex custom types (Like a ShoppingCart), ASP.NET has no reliable way of knowing when the property "changes". This means you might
have to call the Save() method explicitly on each profile after clearing the shopping cart.
This is just off the top of my head, mind you. Give it a go and let us know if it worked.
Talis
Member
5 Points
4 Posts
Clear all profiles shopping carts
Feb 15, 2009 10:09 AM|LINK
Hello,
In a BeerHouse website, I made a shopping cart a little different from the original one : the shoppingcart is not cleared after the order is passed (I won't explain why we did that but it feets our needs...).
I just deleted the line : "Me.Profile.ShoppingCart.Clear()" in the ShoppingCart.aspx code behind page.
Accordingly, the storekeeper should be able to clear all the shopping carts at a time (from an admin page, just clicking on a button).
I wrote this method in the admin page :Running this code, no error appears but the shopping carts are not cleared...Can anyone see what the problem is ?Lee Dumond
Contributor
6404 Points
1173 Posts
Re: Clear all profiles shopping carts
Feb 15, 2009 05:07 PM|LINK
Most of the time, when a profile property changes, ASP.NET can detect this and will save the profile automatically.
But this detection mechanism usually only works with simple types, like integers and strings. Sometimes when working with complex custom types (Like a ShoppingCart), ASP.NET has no reliable way of knowing when the property "changes". This means you might have to call the Save() method explicitly on each profile after clearing the shopping cart.
This is just off the top of my head, mind you. Give it a go and let us know if it worked.
Follow Me on Twitter
Talis
Member
5 Points
4 Posts
Re: Clear all profiles shopping carts
Feb 16, 2009 09:19 AM|LINK
You are right, it works fine now !
I would never have imagined that because in the ShoppingCart.aspx code behind the Save() method is not used after clearing the shopping cart...
Thanks a lot for your help, Lee.