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.

  • Igor 25 posts 45 karma points
    Jun 24, 2011 @ 12:29
    Igor
    0

    Problem creating product from API

    Hello again :-) 

    When i had migrated to uCommerce 2.0.1 i started expiriencing problems with creating Product.

    We are using some WCF service where we are getting information about products, then i need to import all products to uCommerce. Now you set Id in Product class as read-only property, i thought you are resolving Id in auto mode, but seems that no....

    Look to my code:

      Product product = new Product
                            {
                                Sku = i.no,
                                Name = i.description,
                                AllowOrdering = true,
                                DisplayOnSite = i.blocked.ToLower() != "no",
                                ProductDefinition = definition,  // Set to an existing defintion
                                ThumbnailImageMediaId = null // ID from Umbraco (nullable int)
                            };
      product.Save();

    And i am getting this error:

    could not resolve property: Id of: UCommerce.EntitiesV2.ProductDefinition [.SingleOrDefault[UCommerce.EntitiesV2.ProductDefinition](NHibernate.Linq.NhQueryable`1[UCommerce.EntitiesV2.ProductDefinition], Quote((d, ) => (Equal(d.Id, p1))), )]

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jun 27, 2011 @ 09:03
    Søren Spelling Lund
    0

    Hi Igor,

    Your code looks right. In fact I've got a unit test with your exact code.

    The problem must be somewhere else. One thing to try is grabbing the product definition id using this code:

    product.ProductDefinition.ProductDefinitionId
  • Igor 25 posts 45 karma points
    Jun 28, 2011 @ 11:36
    Igor
    0

    Yes, seems, that problem was not in that part. Our team had figured out, that SingleOrDefault(<lambda expression>) method works not in all cases, sometime, it just returns null. And we prefer to use Find(<lambda expression>) which works all the time for us. Anyway thanks for help :-)

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jun 28, 2011 @ 13:50
    Søren Spelling Lund
    0

     

    Glad to hear that you figured it out. It would be extremely helpful if you could post the code for a repro so we can take a look at it and fix any issue there might be with the API. Thanks in advance.

  • Indraprasad 10 posts 30 karma points
    Nov 09, 2012 @ 10:24
    Indraprasad
    0

    Hi Soren,

    Im trying to create a product programmatically but it is not allowing me  to set  'ProductDefinitionId' . Im using using Ucommerce 2.6. Its showing the following error

    "Set accessor of property ProductDefinition is not accessible "

    my code is

    Dim Prod As New Product

    With Prod
               .Sku = "abc"
                .Name = "abc"
                .AllowOrdering = True
                .DisplayOnSite = True
                 Prod.ProductDefinition.ProductDefinitionId = 23 // this line throws the error
    End With

    Could u please let me know where the error and share any articles to create product programmatically

     

     

     

     

     

     

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    Nov 09, 2012 @ 13:26
    Søren Spelling Lund
    0

    You want to set the product definition itself instead of the ID like so:

    Dim definition As ProductDefinition = ProductDefinition.Get(23)
    Dim Prod As New Product

    With Prod
               .Sku = "abc"
                .Name = "abc"
                .AllowOrdering = True
                .DisplayOnSite = True
                 Prod.ProductDefinition = definition
    End With

    Hope this helps.

  • Indraprasad 10 posts 30 karma points
    Nov 20, 2012 @ 06:42
    Indraprasad
    0

    thanks Soren..it helped me..

Please Sign in or register to post replies

Write your reply to:

Draft