Found an interesting problem with my AbleCommerce 7.0.3 installation after doing a test upgrade to 7.0.5 last night.

My add to cart button wouldn’t work after the upgrade.  It kept saying Object reference blah blah blah.  Put everything into the debugger and figured out I have some bad data in the storefront.

I had several (384 to be exact) ChildProductId’s assigned to real products in the ac_UpsellProducts table.  Upsells are products that are advertised after the original product is added to the cart.  Obviously you wouldn’t want to upsell a product that no longer exists – thus there’s a foreign key constraint on the ProductId.  That way, any products that get deleted automatically delete their link in any upsell products and visa versa.

Somehow in my data, that wasn’t happening.  I have products assigned as an upsell to a main product, and those products no longer exist.  This was causing addtocartlink.ascx to throw a null reference exception when it hit the GetUpSellProducts method.

Easy fix is to just clean out any bad upsells using this query:

delete ac_upsellproducts

from ac_upsellproducts

left outer join ac_products on ac_upsellproducts.childproductid = ac_products.productid

where ac_products.productid is null