an ASP.NET Open Source CMS & eCommerce platform
Search:
Skip Navigation LinksHome > DotShoppingCart Forums > Development > General Programming > Object reference not set during an add to cart ...
Last Post 3/8/2010 10:32:04 AM By lukezy. 4 replies.
1/4/2010 1:26:24 PM
Gary Rasicot
Posts: 2
Joined: 10/5/2009
Object reference not set during an add to cart call.
Hi,
 
I am attempting to change how the add to cart works.
I am in the early stages and I think I may have found a bug.
 
Here is the code I modified:
productdetailtemplate.cs
I just commented out the returned quantity and supplied a 0 so that it would always be out of stock.
 
public bool AddToCart(int count, List int selectedAttributeValueIds,string customField) {
// int quantity = Product.GetStockQuantity(count, selectedAttributeValueIds); 

 

int quantity = 0;  if (0 == quantity){ return false; }
 

Object reference not set to an instance of an object.

</span>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

<table width="100%" bgcolor="#ffffcc"> <tbody> <tr> <td>
Line 4:  <script type="text/javascript" language="javascript">
Line 5:      var imageDict = new Array();
Line 6:      var currentImageId = <%=Product.DefaultImageId ?? 0 %>;
Line 7:      function OpenPopupWindowFromMain() {
Line 8:          OpenResizablePopupWindow('<%=string.Format("{0}?n={1}&width={2}&height={3}&imageId=", SiteNavigation.ProductImagesPage, Product.SKU, ProductEnlargedImageWidth, ProductEnlargedImageHeight) %>' + currentImageId, 800, 700);
</td> </tr> </tbody> </table>
Source File: d:\Visual Studio 2008\Projects\DotShoppingCartSuiteV4.0\Web\Store\ProductDetail\ProductImages.ascx    Line: 6

Stack Trace:

 
Thanks,
Tom Usselman
1/4/2010 2:51:06 PM
lukezy
Posts: 2109
Joined: 6/12/2007
Location:WA, US
Re: Object reference not set during an add to cart call.
The exception stack says "Product" is null. Try setting a breakpoint in the code behind and check why it didn't get set.
DotShoppingCart Staff
1/6/2010 2:09:43 PM
Gary Rasicot
Posts: 2
Joined: 10/5/2009
Re: Object reference not set during an add to cart call.
Hi Luke,
 
I think it may be a "bug" kind of?
 
It appears that there is code to take into account that an item may disappear from stock while a user is shopping.
So they load the product page when the item is in stock and then when they go to add the item to the cart it throws the object error.
 
1. To test this I went into when into a product page and selected the required attributes.
2. I then went into the SQL server and set the quanities to 0 for the product and its attributes.
3. Back to the product page and clicked add to cart and received the object error.
 
When I debug, the first time every thing loads and the product object is loaded and everything works fine, it's only in the redirect that I am getting the error.
 
I have been chasing this for a bit, but since you wrote the original code it may pop right out at you?
 
Thanks,
Tom Usselman
3/8/2010 9:20:02 AM
bansal_db
Posts: 181
Joined: 4/13/2009
Re: Object reference not set during an add to cart call.
Hey Luke,
 
 
I'm getting the same error while adding item to the Cart. I did not make any changes on Version 4.0 for Adding a product.
This error shows up when I set the quantity for item to zero and add the item to the cart.  
 
 
-Bansal
3/8/2010 10:32:04 AM
lukezy
Posts: 2109
Joined: 6/12/2007
Location:WA, US
Re: Object reference not set during an add to cart call.
We will repro that and try to fix this.
DotShoppingCart Staff