TeaCommerce.Base.GetStock - Nullable object must have a value
I'm getting an error when calling the TeaCommerce.Base.GetStock for a product node that has not had its stock level set.
Of course the stock level should be set mandatory when creating a product but there exists a whole bunch of products where it is not been because until now the stock functionality was not in place.
It would be nice if it could perhaps return 0 for these products rather than an error.
I'm using an older version of Tea Commerce so maybe it has already been addressed?
Which Tea Commerce version do you run at the moment? Could you try and update and see if the problem is still there? If the problem is still around could you try and send me a screen of your document type you use as a product and then a screen of one of the products data that is causing problems. Is it because the umbraco node doesnt have the stock property because it was created before you added the stock peoperty to your document type?
V1.4.1.2 is now in place and the error still occurs.
Yes basically the stock property has been in place since the beginning but it wasn't being used in any way so it was set 'optional' and never populated by any editors.
Below is the data for Node 1640.
I'm now adding new functionality that takes into account product stock levels, but of course there are lots of existing products where no value has ever been entered.
As you can see below, there is no record for NodeId 1640 in the Stock table and I beleive this is the problem.
I think the GetStock method just needs to handle this.
My initial thought was that it could return a stock level of 0. Some developers however might like it to error if you pass the node ID of a non-product item which of course wouldn't have stock.
I don't understand how it fails. The standard starter kit for Tea Commerce uses GetStock, and no errors are thrown. Almost none of the products in the starter kit have a stock entered, so they should all throw the error.
A quick glance in the code reveals that GetStock will return an empty string if no stock is found, for the requested node. It might throw an error if GetStock recieves an empty node, or something like that. Please check what param you are sending to GetStock and maybe do an ?umbDebugShowTrace=true, to reveal the error.
I know the starter kit uses all XSLT where I'm using all .Net controls. Maybe the error is being ignored in the XSLT? Just a thought.
If I call TeaCommerce.Base.GetStock(123) and node 123 has not had its stock property set I get the following error.
System.InvalidOperationException was unhandled Message=Nullable object must have a value. Source=mscorlib StackTrace: at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Nullable`1.get_Value() at TeaCommerce.Base.GetStock(Int32 nodeId) InnerException:
If I set the stock property to say 100 and publish it works fine.
If I then clear/blank the stock property and publish it errors again.
TeaCommerce.Base.GetStock - Nullable object must have a value
I'm getting an error when calling the TeaCommerce.Base.GetStock for a product node that has not had its stock level set.
Of course the stock level should be set mandatory when creating a product but there exists a whole bunch of products where it is not been because until now the stock functionality was not in place.
It would be nice if it could perhaps return 0 for these products rather than an error.
I'm using an older version of Tea Commerce so maybe it has already been addressed?
Hi Matt
Which Tea Commerce version do you run at the moment? Could you try and update and see if the problem is still there? If the problem is still around could you try and send me a screen of your document type you use as a product and then a screen of one of the products data that is causing problems. Is it because the umbraco node doesnt have the stock property because it was created before you added the stock peoperty to your document type?
Kind regards
Anders
Hey Anders,
It's V1.4.1.0 BETA.
I'll do an upgrade and play around and get back to you.
Cheers,
Matt
Great - looking forward to hear from you again
Kind regads
Anders
Hi Anders,
Hi Matt
We will try and have a look at doing a solution for this method - because it shouldnt just give you an error :)
Kind regards
Anders
Thanks, one of those odd cases that shouldn't happen but can.
I can easily work around it for now.
At least I finally upgraded to the latest version. :-)
Hi Matt,
I don't understand how it fails. The standard starter kit for Tea Commerce uses GetStock, and no errors are thrown. Almost none of the products in the starter kit have a stock entered, so they should all throw the error.
A quick glance in the code reveals that GetStock will return an empty string if no stock is found, for the requested node. It might throw an error if GetStock recieves an empty node, or something like that. Please check what param you are sending to GetStock and maybe do an ?umbDebugShowTrace=true, to reveal the error.
/Rune
OK Rune, I'll look into what's happening a bit more.
Yeah, I will be ready to help when you have some more info.
/Rune
Hi Rune,
I know the starter kit uses all XSLT where I'm using all .Net controls. Maybe the error is being ignored in the XSLT? Just a thought.
If I call TeaCommerce.Base.GetStock(123) and node 123 has not had its stock property set I get the following error.
System.InvalidOperationException was unhandled
Message=Nullable object must have a value.
Source=mscorlib
StackTrace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Nullable`1.get_Value()
at TeaCommerce.Base.GetStock(Int32 nodeId)
InnerException:
If I set the stock property to say 100 and publish it works fine.
If I then clear/blank the stock property and publish it errors again.
We found the error now. We where looking in the wrong place :)
We will be back with a fix, as soon as posible. Tomorrow at the latest.
/Rune
No worries.
Cheers Rune.
Hi Matt,
I have uploaded a new beta package. Check it out, and see if it works as supposed to.
/Rune
Hi Matt
Tried the new Beta and did it solve your problem?
Kind regards
Anders
Hi Anders/Rune,
I've not had a chance to try it yet. I will do when I get a moment. I've no doubt it will work. :)
This has been fixed in the beta, thanks.
is working on a reply...