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.

  • Steen Tøttrup 191 posts 291 karma points c-trib
    Jul 19, 2012 @ 09:42
    Steen Tøttrup
    0

    API created products fail in back-office

    I'm importing a lot of products using the API, and everything seems to show up fine in the tree, but when I click on a product I get this error in the back-office:

    [NullReferenceException: Object reference not set to an instance of an object.]
       UCommerce.Presentation.Presenters.Catalog.EditProductPresenter.BindView() +1261
       UCommerce.Presentation.Presenters.Catalog.EditProductPresenter.View_Load(Object sender, EventArgs e) +15
       System.EventHandler.Invoke(Object sender, EventArgs e) +0
       umbraco.BasePages.BasePage.OnLoad(EventArgs e) +18
       System.Web.UI.Control.LoadRecursive() +70
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3063

    I'm creating products, setting a definition, relating them to a category, giving them a description, adding a custom property and creating a price for them. What am I missing? I'm not getting any errors when creating the products, so...

    The code that imports the products are here:

    foreach (var variant in product.Variants) {
        newProduct.Name = product.DisplayName;
        newProduct.CreatedBy = newProduct.ModifiedBy = "System";
        newProduct.CreatedOn = newProduct.ModifiedOn = DateTime.UtcNow;
        newProduct.Sku = product.ProductId;
        newProduct.VariantSku = variant.VariantId;
        newProduct.ProductDefinition = statelessSession.CreateCriteria<ProductDefinition>().Add(Restrictions.Eq("Name", "Jewelry")).List<ProductDefinition>().First();
        statelessSession.Insert(newProduct);

        CategoryProductRelation cpr = new CategoryProductRelation();
        cpr.Category = category;
        cpr.Product = newProduct;
        statelessSession.Insert(cpr);

        ProductDescription desc = new ProductDescription();
        desc.CultureCode = culture;
        desc.DisplayName = product.DisplayName;
        desc.ShortDescription = variant.Description;
        desc.Product = newProduct;
        statelessSession.Insert(desc);

        ProductDescriptionProperty color = new ProductDescriptionProperty();
        color.ProductDefinitionField = statelessSession.CreateCriteria<ProductDefinitionField>().Add(Restrictions.Eq("Name", "Color")).List<ProductDefinitionField>().First();
        color.ProductDescription = desc;
        color.Value = variant.Color;
        statelessSession.Insert(color);

        foreach (KeyValuePair<String, ProductPrice> pair in variant.Prices) {
            Currency curr = statelessSession.CreateCriteria<Currency>().Add(Restrictions.Eq("ISOCode", pair.Key)).List<Currency>().First();
            if (curr != null) {
                PriceGroup pg = statelessSession.CreateCriteria<PriceGroup>().Add(Restrictions.Eq("CurrencyId", curr.Id)).List<PriceGroup>().First();
                if (pg != null) {
                    PriceGroupPrice pgp = new PriceGroupPrice();
                    pgp.PriceGroup = pg;
                    pgp.Product = newProduct;
                    pgp.Price = pair.Value.Price;
                    statelessSession.Insert(pgp);
                }
            }
        }
    }

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jul 20, 2012 @ 12:36
    Søren Spelling Lund
    0

    Turns out this was some bad data written to product families (variant SKU was set, which doesn't make sense on a product family).

    I've added a fix which prevents the errors for happening again in V3.

Please Sign in or register to post replies

Write your reply to:

Draft