How to write to uCommerce ProductDefinitionField and ProductDefinitionFieldDescription
Hi all,
I have successfully written code to define a uCommerce
"Product" linked to a
"ProductDefinition" linked to several
"ProductDefinitionField" linked to one or more
"ProductDefinitionFieldDescription"
Now with the data structure defined I am trying to programmatically populate it with data from several hundred products.
I have no problem creating and populating instances of the Product and
ProductDefinition classes but I can not figure out how I am meant to populate data into ProductDefinitionField and ProductDefinitionFieldDescription it is not clear where to write the data.
If you can point me in the right direction with this it would be appreciated.
I don't have access to Visual Studio right now so this will be coming right as I remember it. A product instance have a collection "ProductProperties". This collection will contain all your non-multilinqual properties (referenced to a product definition field). I recall there is a method called AddProperty on the product which should help you adding data to the right collections (determined by if it's multilinqual or not).
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=ClancyCom8
StackTrace:
at ClancyCom8.TCUCAdmin.deleteProductClick1(Object sender, EventArgs e) in c:\Clancy\AClancyCom\Dev\ClancyCom8\ClancyCom8\TCUCAdmin.aspx.cs:line 659
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:
I have used the debugger to check and the object "mySkuObject" which I am passing is not null.
Try to look at your ProductDefinitionField does it have a reference to "DataType" or is it just a null? I can see in the code that uCommerce uses the datatype to find out how it should parse your value.
Yes all the products I am adding share the same "ProductDefinition" and related "ProductDefinitionFields". Each of those fields has been set to a data type of "short text" except the price which I have set to "number".
So I do not think that a null DataType is the problem - any other ideas ?
OK I solved it yes you were on the right track my productProperty.ProductDefinitionField was NULL because I was using SingleOrDefault to set it from a matching set of more than one.
The trick was not to look at just what I was passing the method but what else in the class the method might need which might be incorrectly null.
How to write to uCommerce ProductDefinitionField and ProductDefinitionFieldDescription
Hi all,
I have successfully written code to define a uCommerce
"Product" linked to a "ProductDefinition" linked to several "ProductDefinitionField" linked to one or more "ProductDefinitionFieldDescription"
Now with the data structure defined I am trying to programmatically populate it with data from several hundred products.
I have no problem creating and populating instances of the Product and ProductDefinition classes but I can not figure out how I am meant to populate data into ProductDefinitionField and ProductDefinitionFieldDescription it is not clear where to write the data.
If you can point me in the right direction with this it would be appreciated.
Thanks
Terry Clancy ClanceZ
Hi Terry,
I don't have access to Visual Studio right now so this will be coming right as I remember it. A product instance have a collection "ProductProperties". This collection will contain all your non-multilinqual properties (referenced to a product definition field). I recall there is a method called AddProperty on the product which should help you adding data to the right collections (determined by if it's multilinqual or not).
Best regards Martin
Thanks very much Martin, that helps a lot.
However I am still having problems with using ProductProperty.SetValue . The error occurs in the following code:
Specifically the following line from above:
Throws the following error:
System.NullReferenceException was unhandled by user code HResult=-2147467261 Message=Object reference not set to an instance of an object. Source=ClancyCom8 StackTrace: at ClancyCom8.TCUCAdmin.deleteProductClick1(Object sender, EventArgs e) in c:\Clancy\AClancyCom\Dev\ClancyCom8\ClancyCom8\TCUCAdmin.aspx.cs:line 659 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:
I have used the debugger to check and the object "mySkuObject" which I am passing is not null.
Do you have any idea what the problem is here ?
Thanks again,
Terry
Hi Terry,
Try to look at your ProductDefinitionField does it have a reference to "DataType" or is it just a null? I can see in the code that uCommerce uses the datatype to find out how it should parse your value.
best regards Martin
Hi Martin,
Yes all the products I am adding share the same "ProductDefinition" and related "ProductDefinitionFields". Each of those fields has been set to a data type of "short text" except the price which I have set to "number".
So I do not think that a null DataType is the problem - any other ideas ?
Terry
Martin ,
I might have found the cause, not sure, will check tomorrow.
Terry
Martin,
OK I solved it yes you were on the right track my productProperty.ProductDefinitionField was NULL because I was using SingleOrDefault to set it from a matching set of more than one.
The trick was not to look at just what I was passing the method but what else in the class the method might need which might be incorrectly null.
Tanks
Terry
is working on a reply...