Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Terry Clancy 204 posts 944 karma points
    Dec 28, 2014 @ 08:44
    Terry Clancy
    0

    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

  • Martin 181 posts 740 karma points
    Dec 28, 2014 @ 14:42
    Martin
    0

    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

  • Terry Clancy 204 posts 944 karma points
    Dec 29, 2014 @ 07:11
    Terry Clancy
    0

    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:

                   ProductProperty productProperty_PDSKU = new ProductProperty();
                productProperty_PDSKU.Product = product;
                productProperty_PDSKU.ProductDefinitionField = productDefinition.ProductDefinitionFields.SingleOrDefault((x => x.Name == "PDSKU"));
                string mySku = msproduct.Open_Volume_Products.ToString();
                object mySkuObject = new object();
                mySkuObject = (object) mySku;
                productProperty_PDSKU.SetValue(mySkuObject);
                //productProperty_PDSKU.SetValue("077-06673");
                product.AddProductProperty(productProperty_PDSKU);
    

    Specifically the following line from above:

    productProperty_PDSKU.SetValue(mySkuObject);
    

    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

  • Martin 181 posts 740 karma points
    Dec 29, 2014 @ 18:17
    Martin
    100

    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

  • Terry Clancy 204 posts 944 karma points
    Dec 29, 2014 @ 23:45
    Terry Clancy
    0

    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

  • Terry Clancy 204 posts 944 karma points
    Dec 30, 2014 @ 09:39
    Terry Clancy
    0

    Martin ,

    I might have found the cause, not sure, will check tomorrow.

    Terry

  • Terry Clancy 204 posts 944 karma points
    Dec 31, 2014 @ 08:53
    Terry Clancy
    1

    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

Please Sign in or register to post replies

Write your reply to:

Draft