Page 1 of 1

Unable to Create User Group (and possible fix)

Posted: Sat Sep 15, 2012 3:28 am
by Bert
Hi,
I'm trying out AC Gold, and find I'm unable to create a new User Group without the fix below.
Cheers,
Bert

Code: Select all

         
        protected void CreateGroup()
        {
            if (Page.IsValid)
            {
                Group group = new Group();
                group.Name = Name.Text;
                foreach (ListItem roleListItem in RoleList.Items)
                {
                    if (roleListItem.Selected)
                    {
                        Role role = RoleDataSource.Load(AlwaysConvert.ToInt(roleListItem.Value));
                        group.Roles.Add(role);
                        roleListItem.Selected = false;
                    }
                }
                Store store = AbleContext.Current.Store;
                // BERT START FIX
                group.Store = store;
                // BERT END FIX
                store.Groups.Add(group);
                store.Save();  <-- Exception here without fix
NHibernate.PropertyValueException was unhandled by user code
Message=not-null property references a null or transient value CommerceBuilder.Users.Group.Store
Source=CommerceBuilder
EntityName=CommerceBuilder.Users.Group
PropertyName=Store
StackTrace:
at CommerceBuilder.DomainModel.EntityWithTypedId`1.Save()
at AbleCommerce.Admin.People.Groups.AddGroupDialog.CreateGroup() in C:\xx\AbleCommerceGold-b4194-WAP\Website\Admin\People\Groups\AddGroupDialog.ascx.cs:line 42
at AbleCommerce.Admin.People.Groups.AddGroupDialog.SaveButton_Click(Object sender, EventArgs e) in C:\xx\AbleCommerceGold-b4194-WAP\Website\Admin\People\Groups\AddGroupDialog.ascx.cs:line 55
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:

Re: Unable to Create User Group (and possible fix)

Posted: Mon Sep 17, 2012 2:49 pm
by Logan Rhodehamel
Thanks for the report. We discovered this ourselves and processed an issue report about it. The fix you have noted is an acceptable workaround. I hope we are issuing an update for Gold soon that has a fix that addresses the root of the issue. We should be able to add items to a collection (i.e. Store.Groups) and the item should know what store it belongs to.

Re: Unable to Create User Group (and possible fix)

Posted: Mon Nov 12, 2012 6:54 pm
by Calbeth
Sorry to revive an old thread. After all afternoon trouble-shooting, this is the closest I could find a similar issue I'm encounter trying to save the wishlist. Strangely, the result is that the BasketItem DOES add to the wishlist, then the exception, resulting in the Http redirect failing. If I click Wishlist from the nav, however, I can see the item has been successfully added.

See code and stacktrace below. Is there a similar fix you might recommend? Taken a couple stabs to no avail. Any help very much appreciated.

Code: Select all

protected void AddToWishlistButton_Click(object sender, System.EventArgs e)
        {
			
            if (Page.IsValid && ValidateVariablePrice() && ValidateQuantity()
                && AllProductOptionsSelected() && RequiredKitOptionsSelected())
            {
                BasketItem wishlistItem = GetBasketItem();
                if (wishlistItem != null)
                {
                    // DETERMINE IF THE LICENSE AGREEMENT MUST BE REQUESTED
                    IList<LicenseAgreement> basketItemLicenseAgreements = new List<LicenseAgreement>();
                    basketItemLicenseAgreements.BuildCollection(wishlistItem, LicenseAgreementMode.OnAddToBasket);
                    if ((basketItemLicenseAgreements.Count > 0))
                    {
                        // THESE AGREEMENTS MUST BE ACCEPTED TO ADD TO CART
                        List<BasketItem> basketItems = new List<BasketItem>();
                        basketItems.Add(wishlistItem);
                        string guidKey = Guid.NewGuid().ToString("N");
                        Cache.Add(guidKey, basketItems, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0), System.Web.Caching.CacheItemPriority.NotRemovable, null);
                        string acceptUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("~/Members/MyWishlist.aspx"));
                        string declineUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Page.ResolveUrl(_Product.NavigateUrl)));
                        Response.Redirect("~/BuyWithAgreement.aspx?Items=" + guidKey + "&AcceptUrl=" + acceptUrl + "&DeclineUrl=" + declineUrl + "&ToWishlist=True");
                    }

                    Wishlist wishlist = AbleContext.Current.User.PrimaryWishlist;
                    // Does a similar BERT FIX belong here?
                    wishlist.WishlistItems.Add(wishlistItem);
					
                    //SET THE REQUIRED PARENT REFERENCE FOR ITEMS. WE ARE USING EXTENSIONS FOR ABOVE ADD METHOD WHICH CAN'T SET PARENT REFERENCE BY ITSELF
                    foreach (WishlistItem item in wishlist.WishlistItems)
                    {
                        item.Wishlist = wishlist;
                    }
					
                    wishlist.Save();  <-- Exception here without fix
                    Response.Redirect("~/Members/MyWishlist.aspx");
                }
            }
        }
An error has occured at xx
Exception: Exception of type 'System.Web.HttpUnhandledException' was thrown. Stack Trace: at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.product_aspx.ProcessRequest(HttpContext context) in c:\windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\store\cd9081c2\2927a939\App_Web_rb0xyegm.3.cs:line 0 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) Inner Exception: not-null property references a null or transient value CommerceBuilder.Users.WishlistItemInput.WishlistItem Inner Exception Stack Trace: at CommerceBuilder.DomainModel.EntityWithTypedId`1.Save() at AbleCommerce.ConLib.WABuyProductDialog.AddToWishlistButton_Click(Object sender, EventArgs e) in \\phx3.gdhosting.gdg\p3nwhg522\hosting\84\9876384\html\store\ConLib\Custom\WABuyProductDialog.ascx.cs:line 493 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Re: Unable to Create User Group (and possible fix)

Posted: Mon Nov 12, 2012 7:20 pm
by Calbeth
I should add that I tried Rusty's BuyProductDialogOptionsList.ascx patch ("Basket basket = AbleContext.Current.User.Basket;" "basketItem.Basket = basket;") as specified here: viewtopic.php?f=65&t=16853#p71941. That hasn't solved the add to wishlist problem for me.

Re: Unable to Create User Group (and possible fix)

Posted: Tue Nov 13, 2012 8:34 am
by jmestep
We also have a site getting the same error. I was able to eliminate some of them by wrapping it in a try/catch and putting code on the wishlist button to deactivate it after someone clicked it one time, but you can still click it if you do it fast enough before it is deactivated.
If I remember correctly, I had debugged it in Visual Studio and saw that it was trying to add the item twice because of the fast double click, but maybe that isn't it after all.

Re: Unable to Create User Group (and possible fix)

Posted: Tue Nov 13, 2012 11:33 pm
by Calbeth
Hi, Judy. Would you mind posting your fix if you have a moment? It's worth a shot.

Re: Unable to Create User Group (and possible fix)

Posted: Wed Nov 14, 2012 8:06 am
by jmestep
It didn't get rid of the error completely, but before I did it people would click add to wishlist and the page would freeze. This is in the BuyProductDialog.ascx.cs AddToWishlistButton_Click
I wrapped the section in a try/catch- I'm posting a fragment here
if (wishlistItem != null)
{
//w2m jme added try catch for temp error handling
try
{
// DETERMINE IF THE LICENSE AGREEMENT MUST BE REQUESTED
................................... existing code

wishlist.Save();
}
catch (Exception)
{
//Logger.Warn("user id on add to wishlist is " + AbleContext.Current.UserId.ToString());
//Logger.Warn("wishlist item id is " + wishlistItem.ProductId);
}
finally
{

}
Response.Redirect("~/Members/MyWishlist.aspx");

Re: Unable to Create User Group (and possible fix)

Posted: Thu Nov 15, 2012 10:29 am
by Calbeth
Judy: Bingo! That resolved the problem. No more errors generated in the error log; the product adds to the wishlist and the redirect now happens. Strange--but heck, a fix is a fix.

Thanks so much!
Calbeth