Null Reference exceptions in private method CartHelper.CreateLineItem()

Vote:
 

I've followed the examples that exist in the demo site, i've ported it across to the site i'm currently working on and sucessfully installed Commerce, yet I get the following error whenever I try to add an item to the cart.

Any ideas what this could be?  I'm completely stuck.

 

Line 67:             if(entry != null)
Line 68: {
Line 69: cartHelper.AddEntry(entry, 1, false, new CartHelper[] { wishlist });
Line 70: }
Line 71:


Source File: C:\projects\RICS\trunk\Rics.Web\Templates\Commerce\Pages\BasketConfirmation.aspx.cs    Line: 69

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
Mediachase.Commerce.Website.Helpers.CartHelper.CreateLineItem(Entry entry, Decimal quantity) +503
Mediachase.Commerce.Website.Helpers.CartHelper.AddEntry(Entry entry, Decimal quantity, Boolean fixedQuantity, CartHelper[] helpersToRemove) +749
Rics.Web.Templates.Commerce.Pages.BasketConfirmation.BtnItemClick(Object sender, EventArgs e) in C:\projects\RICS\trunk\Rics.Web\Templates\Commerce\Pages\BasketConfirmation.aspx.cs:69
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

 

#52379
Jul 20, 2011 15:19
Vote:
 

hi got the smae error. Use the code on the wishlist page to add items to basket

  Entry e1 = CatalogContext.Current.GetCatalogEntry(txtprodid.Text);
            Entry entrytouse = CatalogContext.Current.GetCatalogEntry(e1.CatalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
      
            if (entrytouse != null)
            {
                bool alreadyExists = false;
                CartHelper helper = new CartHelper(Cart.DefaultName);
                // Check if item exists
                foreach (LineItem item in helper.LineItems)
                {
                    if (item.CatalogEntryId.Equals(entrytouse.ID))
                    {
                        item.Quantity += Convert.ToInt16(txtQuantity.Text);
                        alreadyExists = true;
                    }
                }
                lock (_lock)
                {
                    if (!alreadyExists)
                        helper.AddEntry(entrytouse, Convert.ToInt16(txtQuantity.Text), true);
                    else
                        helper.Cart.AcceptChanges();
                }
            }        

#52779
Aug 14, 2011 21:33
Vote:
 

Thanks - the issue in my case was a configuration line was missing from Web.Config that set up database connections to the catalog system....  Any commerce related issues, the first thing I suggest is thoroughly checking all of the configuration, httpModules etc

#52858
Aug 17, 2011 14:55
Vote:
 

We had this exact same problem.

For other people that are having this issue, make sure you requested the Entry with price information. If entry.ItemAttributes.ListPrice is null then AddEntry will fail.

This code will not return price information:
CatalogContext.Current.GetCatalogEntry(code);

This code will return price information:
CatalogContext.Current.GetCatalogEntry(code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

#60431
Aug 08, 2012 15:16
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.